mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Test redirecting to logfile
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import json
|
||||
import pprint
|
||||
from contextlib import redirect_stdout
|
||||
from datetime import datetime
|
||||
|
||||
@@ -11,10 +10,10 @@ TIMESTAMP = 1649166819
|
||||
|
||||
|
||||
@time_machine.travel(datetime.fromtimestamp(TIMESTAMP))
|
||||
async def test_print_is_redirected_to_devtools(devtools, in_memory_logfile):
|
||||
async def test_print_redirect_to_devtools_only(devtools):
|
||||
await devtools._stop_log_queue_processing()
|
||||
|
||||
with redirect_stdout(StdoutRedirector(devtools, in_memory_logfile)): # type: ignore
|
||||
with redirect_stdout(StdoutRedirector(devtools, None)): # type: ignore
|
||||
print("Hello, world!")
|
||||
|
||||
assert devtools.log_queue.qsize() == 1
|
||||
@@ -31,6 +30,23 @@ async def test_print_is_redirected_to_devtools(devtools, in_memory_logfile):
|
||||
)
|
||||
|
||||
|
||||
async def test_print_redirect_to_logfile_only(devtools, in_memory_logfile):
|
||||
await devtools.disconnect()
|
||||
with redirect_stdout(StdoutRedirector(devtools, in_memory_logfile)): # type: ignore
|
||||
print("Hello, world!")
|
||||
assert in_memory_logfile.getvalue() == "Hello, world!\n"
|
||||
|
||||
|
||||
async def test_print_redirect_to_devtools_and_logfile(devtools, in_memory_logfile):
|
||||
await devtools._stop_log_queue_processing()
|
||||
|
||||
with redirect_stdout(StdoutRedirector(devtools, in_memory_logfile)): # type: ignore
|
||||
print("Hello, world!")
|
||||
|
||||
assert devtools.log_queue.qsize() == 1
|
||||
assert in_memory_logfile.getvalue() == "Hello, world!\n"
|
||||
|
||||
|
||||
@time_machine.travel(datetime.fromtimestamp(TIMESTAMP))
|
||||
async def test_print_without_flush_not_sent_to_devtools(devtools, in_memory_logfile):
|
||||
await devtools._stop_log_queue_processing()
|
||||
|
||||
Reference in New Issue
Block a user