1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
from textual.app import App
from textual.screen import Screen
from textual.widgets import Header
async def test_screen_title_none_is_ignored():
class MyScreen(Screen):
def compose(self):
yield Header()
class MyApp(App):
TITLE = "app title"
def on_mount(self):
self.push_screen(MyScreen())
app = MyApp()
async with app.run_test():
assert app.query_one("HeaderTitle").text == "app title"
async def test_screen_title_overrides_app_title():
class MyScreen(Screen):
TITLE = "screen title"
def compose(self):
yield Header()
class MyApp(App):
TITLE = "app title"
def on_mount(self):
self.push_screen(MyScreen())
app = MyApp()
async with app.run_test():
assert app.query_one("HeaderTitle").text == "screen title"
async def test_screen_title_reactive_updates_title():
class MyScreen(Screen):
TITLE = "screen title"
def compose(self):
yield Header()
class MyApp(App):
TITLE = "app title"
def on_mount(self):
self.push_screen(MyScreen())
app = MyApp()
async with app.run_test() as pilot:
app.screen.title = "new screen title"
await pilot.pause()
assert app.query_one("HeaderTitle").text == "new screen title"
async def test_app_title_reactive_does_not_update_title_when_screen_title_is_set():
class MyScreen(Screen):
TITLE = "screen title"
def compose(self):
yield Header()
class MyApp(App):
TITLE = "app title"
def on_mount(self):
self.push_screen(MyScreen())
app = MyApp()
async with app.run_test() as pilot:
app.title = "new app title"
await pilot.pause()
assert app.query_one("HeaderTitle").text == "screen title"
async def test_screen_sub_title_none_is_ignored():
class MyScreen(Screen):
def compose(self):
yield Header()
class MyApp(App):
SUB_TITLE = "app sub-title"
def on_mount(self):
self.push_screen(MyScreen())
app = MyApp()
async with app.run_test():
assert app.query_one("HeaderTitle").sub_text == "app sub-title"
async def test_screen_sub_title_overrides_app_sub_title():
class MyScreen(Screen):
SUB_TITLE = "screen sub-title"
def compose(self):
yield Header()
class MyApp(App):
SUB_TITLE = "app sub-title"
def on_mount(self):
self.push_screen(MyScreen())
app = MyApp()
async with app.run_test():
assert app.query_one("HeaderTitle").sub_text == "screen sub-title"
async def test_screen_sub_title_reactive_updates_sub_title():
class MyScreen(Screen):
SUB_TITLE = "screen sub-title"
def compose(self):
yield Header()
class MyApp(App):
SUB_TITLE = "app sub-title"
def on_mount(self):
self.push_screen(MyScreen())
app = MyApp()
async with app.run_test() as pilot:
app.screen.sub_title = "new screen sub-title"
await pilot.pause()
assert app.query_one("HeaderTitle").sub_text == "new screen sub-title"
async def test_app_sub_title_reactive_does_not_update_sub_title_when_screen_sub_title_is_set():
class MyScreen(Screen):
SUB_TITLE = "screen sub-title"
def compose(self):
yield Header()
class MyApp(App):
SUB_TITLE = "app sub-title"
def on_mount(self):
self.push_screen(MyScreen())
app = MyApp()
async with app.run_test() as pilot:
app.sub_title = "new app sub-title"
await pilot.pause()
assert app.query_one("HeaderTitle").sub_text == "screen sub-title"
|