mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
headless driver and tests
This commit is contained in:
17
src/textual/drivers/headless_driver.py
Normal file
17
src/textual/drivers/headless_driver.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
|
from ..driver import Driver
|
||||||
|
|
||||||
|
|
||||||
|
class HeadlessDriver(Driver):
|
||||||
|
"""A do-nothing driver for testing."""
|
||||||
|
|
||||||
|
def start_application_mode(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def disable_input(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def stop_application_mode(self) -> None:
|
||||||
|
pass
|
||||||
30
tests/test_auto_refresh.py
Normal file
30
tests/test_auto_refresh.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
from time import time
|
||||||
|
|
||||||
|
from textual.app import App
|
||||||
|
|
||||||
|
|
||||||
|
class RefreshApp(App[float]):
|
||||||
|
def __init__(self):
|
||||||
|
self.count = 0
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
def on_mount(self):
|
||||||
|
self.start = time()
|
||||||
|
self.auto_refresh = 0.1
|
||||||
|
|
||||||
|
def _automatic_refresh(self):
|
||||||
|
self.count += 1
|
||||||
|
super()._automatic_refresh()
|
||||||
|
|
||||||
|
def refresh(self, *, repaint: bool = True, layout: bool = False) -> None:
|
||||||
|
super().refresh(repaint=repaint, layout=layout)
|
||||||
|
if self.count == 3:
|
||||||
|
self.exit(time() - self.start)
|
||||||
|
|
||||||
|
|
||||||
|
def test_auto_refresh():
|
||||||
|
app = RefreshApp()
|
||||||
|
|
||||||
|
elapsed = app.run(quit_after=0.5, headless=True)
|
||||||
|
assert elapsed is not None
|
||||||
|
assert elapsed >= 0.3 and elapsed < 0.31
|
||||||
Reference in New Issue
Block a user