code
stringlengths
26
870k
docstring
stringlengths
1
65.6k
func_name
stringlengths
1
194
language
stringclasses
1 value
repo
stringlengths
8
68
path
stringlengths
5
194
url
stringlengths
46
254
license
stringclasses
4 values
async def test_app_no_notifications() -> None: """An app with no notifications should have an empty notification list.""" async with NotificationApp().run_test() as pilot: assert len(pilot.app._notifications) == 0
An app with no notifications should have an empty notification list.
test_app_no_notifications
python
Textualize/textual
tests/notifications/test_app_notifications.py
https://github.com/Textualize/textual/blob/master/tests/notifications/test_app_notifications.py
MIT
async def test_app_with_notifications() -> None: """An app with notifications should have notifications in the list.""" async with NotificationApp().run_test() as pilot: pilot.app.notify("test") await pilot.pause() assert len(pilot.app._notifications) == 1
An app with notifications should have notifications in the list.
test_app_with_notifications
python
Textualize/textual
tests/notifications/test_app_notifications.py
https://github.com/Textualize/textual/blob/master/tests/notifications/test_app_notifications.py
MIT
async def test_app_with_removing_notifications() -> None: """An app with notifications should have notifications in the list, which can be removed.""" async with NotificationApp().run_test() as pilot: pilot.app.notify("test") await pilot.pause() assert len(pilot.app._notifications) == 1 pilot.app._unnotify(list(pilot.app._notifications)[0]) assert len(pilot.app._notifications) == 0
An app with notifications should have notifications in the list, which can be removed.
test_app_with_removing_notifications
python
Textualize/textual
tests/notifications/test_app_notifications.py
https://github.com/Textualize/textual/blob/master/tests/notifications/test_app_notifications.py
MIT
async def test_app_with_notifications_that_expire() -> None: """Notifications should expire from an app.""" async with NotificationApp().run_test() as pilot: for n in range(10): pilot.app.notify("test", timeout=(0.01 if bool(n % 2) else 60)) # Wait until the 0.01 timeout expires on all notifications (plus some leeway) await asyncio.sleep(0.25) assert len(pilot.app._notifications) == 5
Notifications should expire from an app.
test_app_with_notifications_that_expire
python
Textualize/textual
tests/notifications/test_app_notifications.py
https://github.com/Textualize/textual/blob/master/tests/notifications/test_app_notifications.py
MIT
async def test_app_clearing_notifications() -> None: """The application should be able to clear all notifications.""" async with NotificationApp().run_test() as pilot: for _ in range(100): pilot.app.notify("test", timeout=120) await pilot.pause() assert len(pilot.app._notifications) == 100 pilot.app.clear_notifications() assert len(pilot.app._notifications) == 0
The application should be able to clear all notifications.
test_app_clearing_notifications
python
Textualize/textual
tests/notifications/test_app_notifications.py
https://github.com/Textualize/textual/blob/master/tests/notifications/test_app_notifications.py
MIT
def test_message() -> None: """A notification should not change the message.""" assert Notification("test").message == "test"
A notification should not change the message.
test_message
python
Textualize/textual
tests/notifications/test_notification.py
https://github.com/Textualize/textual/blob/master/tests/notifications/test_notification.py
MIT
def test_default_title() -> None: """A notification with no title should have a empty title.""" assert Notification("test").title == ""
A notification with no title should have a empty title.
test_default_title
python
Textualize/textual
tests/notifications/test_notification.py
https://github.com/Textualize/textual/blob/master/tests/notifications/test_notification.py
MIT
def test_default_severity_level() -> None: """The default severity level should be as expected.""" assert Notification("test").severity == "information"
The default severity level should be as expected.
test_default_severity_level
python
Textualize/textual
tests/notifications/test_notification.py
https://github.com/Textualize/textual/blob/master/tests/notifications/test_notification.py
MIT
def test_default_timeout() -> None: """The default timeout should be as expected.""" assert Notification("test").timeout == Notification.timeout
The default timeout should be as expected.
test_default_timeout
python
Textualize/textual
tests/notifications/test_notification.py
https://github.com/Textualize/textual/blob/master/tests/notifications/test_notification.py
MIT
def test_identity_is_unique() -> None: """A collection of notifications should, by default, have unique IDs.""" notifications: set[str] = set() for _ in range(1000): notifications.add(Notification("test").identity) assert len(notifications) == 1000
A collection of notifications should, by default, have unique IDs.
test_identity_is_unique
python
Textualize/textual
tests/notifications/test_notification.py
https://github.com/Textualize/textual/blob/master/tests/notifications/test_notification.py
MIT
async def test_all_levels_of_notification() -> None: """All levels within the DOM should be able to notify.""" async with NotifyApp().run_test() as pilot: assert len(pilot.app._notifications) == 3
All levels within the DOM should be able to notify.
test_all_levels_of_notification
python
Textualize/textual
tests/notifications/test_all_levels_notifications.py
https://github.com/Textualize/textual/blob/master/tests/notifications/test_all_levels_notifications.py
MIT
def test_empty_to_start_with() -> None: """We should have no notifications if we've not raised any.""" assert len(Notifications()) == 0
We should have no notifications if we've not raised any.
test_empty_to_start_with
python
Textualize/textual
tests/notifications/test_notifications.py
https://github.com/Textualize/textual/blob/master/tests/notifications/test_notifications.py
MIT
def test_many_notifications() -> None: """Adding lots of long-timeout notifications should result in them being in the list.""" tester = Notifications() for _ in range(100): tester.add(Notification("test", timeout=60)) assert len(tester) == 100
Adding lots of long-timeout notifications should result in them being in the list.
test_many_notifications
python
Textualize/textual
tests/notifications/test_notifications.py
https://github.com/Textualize/textual/blob/master/tests/notifications/test_notifications.py
MIT
def test_timeout() -> None: """Notifications should timeout from the list.""" tester = Notifications() for n in range(100): tester.add(Notification("test", timeout=(0.5 if bool(n % 2) else 60))) assert len(tester) == 100 sleep(0.6) assert len(tester) == 50
Notifications should timeout from the list.
test_timeout
python
Textualize/textual
tests/notifications/test_notifications.py
https://github.com/Textualize/textual/blob/master/tests/notifications/test_notifications.py
MIT
def test_in() -> None: """It should be possible to test if a notification is in a collection.""" tester = Notifications() within = Notification("within", timeout=120) outwith = Notification("outwith", timeout=120) tester.add(within) assert within in tester assert outwith not in tester
It should be possible to test if a notification is in a collection.
test_in
python
Textualize/textual
tests/notifications/test_notifications.py
https://github.com/Textualize/textual/blob/master/tests/notifications/test_notifications.py
MIT
def test_remove_notification() -> None: """It should be possible to remove a notification.""" tester = Notifications() first = Notification("first", timeout=120) second = Notification("second", timeout=120) third = Notification("third", timeout=120) tester.add(first) tester.add(second) tester.add(third) assert list(tester) == [first, second, third] del tester[second] assert list(tester) == [first, third] del tester[first] assert list(tester) == [third] del tester[third] assert list(tester) == []
It should be possible to remove a notification.
test_remove_notification
python
Textualize/textual
tests/notifications/test_notifications.py
https://github.com/Textualize/textual/blob/master/tests/notifications/test_notifications.py
MIT
def test_remove_notification_multiple_times() -> None: """It should be possible to remove the same notification more than once without an error.""" tester = Notifications() alert = Notification("delete me") tester.add(alert) assert list(tester) == [alert] del tester[alert] assert list(tester) == [] del tester[alert] assert list(tester) == []
It should be possible to remove the same notification more than once without an error.
test_remove_notification_multiple_times
python
Textualize/textual
tests/notifications/test_notifications.py
https://github.com/Textualize/textual/blob/master/tests/notifications/test_notifications.py
MIT
def test_clear() -> None: """It should be possible to clear all notifications.""" tester = Notifications() for _ in range(100): tester.add(Notification("test", timeout=120)) assert len(tester) == 100 tester.clear() assert len(tester) == 0
It should be possible to clear all notifications.
test_clear
python
Textualize/textual
tests/notifications/test_notifications.py
https://github.com/Textualize/textual/blob/master/tests/notifications/test_notifications.py
MIT
async def test_programmatic_style_change_updates_children(style: str, value: object): """Regression test for #1607 https://github.com/Textualize/textual/issues/1607 Some programmatic style changes to a widget were not updating the layout of the children widgets, which seemed to be happening when the style change did not affect the size of the widget but did affect the layout of the children. This test, in particular, checks the attributes that _should_ affect the size of the children widgets. """ class MyApp(App[None]): CSS = """ Grid { grid-size: 2 2; } Label { width: 100%; height: 100%; } """ def compose(self): yield Grid( Label("one"), Label("two"), Label("three"), Label("four"), ) app = MyApp() async with app.run_test() as pilot: sizes = [(lbl.size.width, lbl.size.height) for lbl in app.screen.query(Label)] setattr(app.query_one(Grid).styles, style, value) await pilot.pause() assert sizes != [ (lbl.size.width, lbl.size.height) for lbl in app.screen.query(Label) ]
Regression test for #1607 https://github.com/Textualize/textual/issues/1607 Some programmatic style changes to a widget were not updating the layout of the children widgets, which seemed to be happening when the style change did not affect the size of the widget but did affect the layout of the children. This test, in particular, checks the attributes that _should_ affect the size of the children widgets.
test_programmatic_style_change_updates_children
python
Textualize/textual
tests/css/test_programmatic_style_changes.py
https://github.com/Textualize/textual/blob/master/tests/css/test_programmatic_style_changes.py
MIT
async def test_programmatic_align_change_updates_children_position( style: str, value: str ): """Regression test for #1607 for the align(_xxx) styles. See https://github.com/Textualize/textual/issues/1607. """ class MyApp(App[None]): CSS = "Grid { grid-size: 2 2; }" def compose(self): yield Grid( Label("one"), Label("two"), Label("three"), Label("four"), ) app = MyApp() async with app.run_test() as pilot: offsets = [(lbl.region.x, lbl.region.y) for lbl in app.screen.query(Label)] setattr(app.query_one(Grid).styles, style, value) await pilot.pause() assert offsets != [ (lbl.region.x, lbl.region.y) for lbl in app.screen.query(Label) ]
Regression test for #1607 for the align(_xxx) styles. See https://github.com/Textualize/textual/issues/1607.
test_programmatic_align_change_updates_children_position
python
Textualize/textual
tests/css/test_programmatic_style_changes.py
https://github.com/Textualize/textual/blob/master/tests/css/test_programmatic_style_changes.py
MIT
async def test_css_reloading_applies_to_non_top_screen(monkeypatch) -> None: # type: ignore """Regression test for https://github.com/Textualize/textual/issues/3931""" monkeypatch.setenv( "TEXTUAL", "debug" ) # This will make sure we create a file monitor. # Write some initial CSS. Path(CSS_PATH).write_text( """\ Label { height: 5; border: panel white; } """ ) app = MyApp() async with app.run_test() as pilot: await pilot.pause() first_label = pilot.app.screen_stack[-2].query(Label).first() # Sanity check. assert first_label.styles.height is not None assert first_label.styles.height.value == 5 # Clear the CSS from the file. Path(CSS_PATH).write_text("/* This file has no rules intentionally. */\n") await pilot.pause() await pilot.app._on_css_change() # Height should fall back to 1. assert first_label.styles.height is not None assert first_label.styles.height.value == 1
Regression test for https://github.com/Textualize/textual/issues/3931
test_css_reloading_applies_to_non_top_screen
python
Textualize/textual
tests/css/test_css_reloading.py
https://github.com/Textualize/textual/blob/master/tests/css/test_css_reloading.py
MIT
async def test_css_reloading_file_not_found(monkeypatch, tmp_path): """Regression test for https://github.com/Textualize/textual/issues/3996 Files can become temporarily unavailable during saving on certain environments. """ monkeypatch.setenv("TEXTUAL", "debug") css_path = tmp_path / "test_css_reloading_file_not_found.tcss" with open(css_path, "w") as css_file: css_file.write("#a {color: red;}") class TextualApp(App): CSS_PATH = css_path app = TextualApp() async with app.run_test() as pilot: await pilot.app._on_css_change() os.remove(css_path) assert not css_path.exists() await pilot.app._on_css_change()
Regression test for https://github.com/Textualize/textual/issues/3996 Files can become temporarily unavailable during saving on certain environments.
test_css_reloading_file_not_found
python
Textualize/textual
tests/css/test_css_reloading.py
https://github.com/Textualize/textual/blob/master/tests/css/test_css_reloading.py
MIT
def test_help_text_examples_are_contextualized(): """Ensure that if the user is using CSS, they see CSS-specific examples and if they're using inline styles they see inline-specific examples.""" rendered_inline = render(spacing_invalid_value_help_text("padding", "inline")) assert "widget.styles.padding" in rendered_inline rendered_css = render(spacing_invalid_value_help_text("padding", "css")) assert "padding:" in rendered_css
Ensure that if the user is using CSS, they see CSS-specific examples and if they're using inline styles they see inline-specific examples.
test_help_text_examples_are_contextualized
python
Textualize/textual
tests/css/test_help_text.py
https://github.com/Textualize/textual/blob/master/tests/css/test_help_text.py
MIT
def test_stylesheet_apply_highest_specificity_wins(): """#ids have higher specificity than .classes""" css = "#id {color: red;} .class {color: blue;}" stylesheet = _make_user_stylesheet(css) node = DOMNode(classes="class", id="id") stylesheet.apply(node) assert node.styles.color == Color(255, 0, 0)
#ids have higher specificity than .classes
test_stylesheet_apply_highest_specificity_wins
python
Textualize/textual
tests/css/test_stylesheet.py
https://github.com/Textualize/textual/blob/master/tests/css/test_stylesheet.py
MIT
def test_stylesheet_apply_highest_specificity_wins_multiple_classes(): """When we use two selectors containing only classes, then the selector `.b.c` has greater specificity than the selector `.a`""" css = ".b.c {background: blue;} .a {background: red; color: lime;}" stylesheet = _make_user_stylesheet(css) node = DOMNode(classes="a b c") stylesheet.apply(node) assert node.styles.background == Color(0, 0, 255) assert node.styles.color == Color(0, 255, 0)
When we use two selectors containing only classes, then the selector `.b.c` has greater specificity than the selector `.a`
test_stylesheet_apply_highest_specificity_wins_multiple_classes
python
Textualize/textual
tests/css/test_stylesheet.py
https://github.com/Textualize/textual/blob/master/tests/css/test_stylesheet.py
MIT
def test_stylesheet_many_classes_dont_overrule_id(): """#id is further to the left in the specificity tuple than class, and a selector containing multiple classes cannot take priority over even a single class.""" css = "#id {color: red;} .a.b.c.d {color: blue;}" stylesheet = _make_user_stylesheet(css) node = DOMNode(classes="a b c d", id="id") stylesheet.apply(node) assert node.styles.color == Color(255, 0, 0)
#id is further to the left in the specificity tuple than class, and a selector containing multiple classes cannot take priority over even a single class.
test_stylesheet_many_classes_dont_overrule_id
python
Textualize/textual
tests/css/test_stylesheet.py
https://github.com/Textualize/textual/blob/master/tests/css/test_stylesheet.py
MIT
def test_stylesheet_apply_takes_final_rule_in_specificity_clash(): """.a and .b both contain background and have same specificity, so .b wins since it was declared last - the background should be blue.""" css = ".a {background: red; color: lime;} .b {background: blue;}" stylesheet = _make_user_stylesheet(css) node = DOMNode(classes="a b", id="c") stylesheet.apply(node) assert node.styles.color == Color(0, 255, 0) # color: lime assert node.styles.background == Color(0, 0, 255) # background: blue
.a and .b both contain background and have same specificity, so .b wins since it was declared last - the background should be blue.
test_stylesheet_apply_takes_final_rule_in_specificity_clash
python
Textualize/textual
tests/css/test_stylesheet.py
https://github.com/Textualize/textual/blob/master/tests/css/test_stylesheet.py
MIT
def test_stylesheet_apply_empty_rulesets(): """Ensure that we don't crash when working with empty rulesets""" css = ".a {} .b {}" stylesheet = _make_user_stylesheet(css) node = DOMNode(classes="a b") stylesheet.apply(node)
Ensure that we don't crash when working with empty rulesets
test_stylesheet_apply_empty_rulesets
python
Textualize/textual
tests/css/test_stylesheet.py
https://github.com/Textualize/textual/blob/master/tests/css/test_stylesheet.py
MIT
def test_did_you_mean_for_property_names_in_nested_css( css_property_name: str, expected_property_name_suggestion: "str | None" ) -> None: """Test that we get nice errors with mistyped declaractions in nested CSS. When implementing pseudo-class support in nested TCSS (https://github.com/Textualize/textual/issues/4039), the first iterations didn't preserve this so we add these tests to make sure we don't take this feature away unintentionally. """ stylesheet = Stylesheet() css = """ Screen { * { border: blue; ${PROPERTY}: red; } } """.replace( "${PROPERTY}", css_property_name ) stylesheet.add_source(css) with pytest.raises(StylesheetParseError) as err: stylesheet.parse() _, help_text = err.value.errors.rules[1].errors[0] displayed_css_property_name = css_property_name.replace("_", "-") expected_summary = f"Invalid CSS property {displayed_css_property_name!r}" if expected_property_name_suggestion: expected_summary += f". Did you mean '{expected_property_name_suggestion}'?" assert help_text.summary == expected_summary
Test that we get nice errors with mistyped declaractions in nested CSS. When implementing pseudo-class support in nested TCSS (https://github.com/Textualize/textual/issues/4039), the first iterations didn't preserve this so we add these tests to make sure we don't take this feature away unintentionally.
test_did_you_mean_for_property_names_in_nested_css
python
Textualize/textual
tests/css/test_stylesheet.py
https://github.com/Textualize/textual/blob/master/tests/css/test_stylesheet.py
MIT
def test_grid_rows_columns_relative_units_are_correct(): """Ensure correct relative dimensions for programmatic assignments.""" styles = Styles() styles.grid_columns = "1fr 5%" fr, percent = styles.grid_columns assert fr.percent_unit == Unit.WIDTH assert percent.percent_unit == Unit.WIDTH styles.grid_rows = "1fr 5%" fr, percent = styles.grid_rows assert fr.percent_unit == Unit.HEIGHT assert percent.percent_unit == Unit.HEIGHT
Ensure correct relative dimensions for programmatic assignments.
test_grid_rows_columns_relative_units_are_correct
python
Textualize/textual
tests/css/test_grid_rows_columns_relative_units.py
https://github.com/Textualize/textual/blob/master/tests/css/test_grid_rows_columns_relative_units.py
MIT
def test_styles_builder_uses_correct_relative_units_grid_rows_columns(): """Ensure correct relative dimensions for CSS parsed from files.""" CSS = "grid-rows: 1fr 5%; grid-columns: 1fr 5%;" styles = parse_declarations(CSS, "test") fr, percent = styles.grid_columns assert fr.percent_unit == Unit.WIDTH assert percent.percent_unit == Unit.WIDTH fr, percent = styles.grid_rows assert fr.percent_unit == Unit.HEIGHT assert percent.percent_unit == Unit.HEIGHT
Ensure correct relative dimensions for CSS parsed from files.
test_styles_builder_uses_correct_relative_units_grid_rows_columns
python
Textualize/textual
tests/css/test_grid_rows_columns_relative_units.py
https://github.com/Textualize/textual/blob/master/tests/css/test_grid_rows_columns_relative_units.py
MIT
def test_opacity_set_allows_integer_value(): """Regression test for https://github.com/Textualize/textual/issues/3414""" styles = RenderStyles(DOMNode(), Styles(), Styles()) styles.text_opacity = 0 assert styles.text_opacity == 0.0
Regression test for https://github.com/Textualize/textual/issues/3414
test_opacity_set_allows_integer_value
python
Textualize/textual
tests/css/test_styles.py
https://github.com/Textualize/textual/blob/master/tests/css/test_styles.py
MIT
def test_mega_stylesheet() -> None: """It should be possible to load a known-good stylesheet.""" mega_stylesheet = Stylesheet() mega_stylesheet.read(Path(__file__).parent / "test_mega_stylesheet.tcss") mega_stylesheet.parse() assert ".---we-made-it-to-the-end---" in mega_stylesheet.css
It should be possible to load a known-good stylesheet.
test_mega_stylesheet
python
Textualize/textual
tests/css/test_mega_stylesheet.py
https://github.com/Textualize/textual/blob/master/tests/css/test_mega_stylesheet.py
MIT
def test_did_you_mean_pseudo_classes(pseudo_class: str, expected: str) -> None: """Make sure we get the correct suggestion for pseudo-classes with typos.""" css = f""" Button:{pseudo_class} {{ background: red; }} """ with pytest.raises(TokenError) as err: list(tokenize(css, ("", ""))) assert f"unknown pseudo-class {pseudo_class!r}" in str(err.value) assert f"did you mean {expected!r}" in str(err.value)
Make sure we get the correct suggestion for pseudo-classes with typos.
test_did_you_mean_pseudo_classes
python
Textualize/textual
tests/css/test_tokenize.py
https://github.com/Textualize/textual/blob/master/tests/css/test_tokenize.py
MIT
def test_did_you_mean_pseudo_classes_in_nested_css( pseudo_class: str, expected: str ) -> None: """Test that we get nice errors for pseudo-classes with typos in nested TCSS. When implementing pseudo-class support in nested TCSS (https://github.com/Textualize/textual/issues/4039), the first iterations didn't preserve this so we add these tests to make sure we don't take this feature away unintentionally. """ css = f""" Screen {{ Button:{pseudo_class} {{ background: red; }} }} """ with pytest.raises(TokenError) as err: list(tokenize(css, ("", ""))) assert f"unknown pseudo-class {pseudo_class!r}" in str(err.value) assert f"did you mean {expected!r}" in str(err.value)
Test that we get nice errors for pseudo-classes with typos in nested TCSS. When implementing pseudo-class support in nested TCSS (https://github.com/Textualize/textual/issues/4039), the first iterations didn't preserve this so we add these tests to make sure we don't take this feature away unintentionally.
test_did_you_mean_pseudo_classes_in_nested_css
python
Textualize/textual
tests/css/test_tokenize.py
https://github.com/Textualize/textual/blob/master/tests/css/test_tokenize.py
MIT
async def test_nest_app(): """Test nested CSS works as expected.""" app = NestedApp() async with app.run_test(): assert app.query_one("#foo").styles.background == Color.parse("red") assert app.query_one("#foo").styles.color == Color.parse("magenta") assert app.query_one("#egg").styles.background == Color.parse("green") assert app.query_one("#foo .paul").styles.background == Color.parse("blue")
Test nested CSS works as expected.
test_nest_app
python
Textualize/textual
tests/css/test_nested_css.py
https://github.com/Textualize/textual/blob/master/tests/css/test_nested_css.py
MIT
async def test_lists_of_selectors_in_nested_css() -> None: """Regression test for https://github.com/Textualize/textual/issues/3969.""" app = ListOfNestedSelectorsApp() red = Color.parse("red") async with app.run_test(): assert app.query_one(".foo").styles.background == red assert app.query_one(".bar").styles.background == red assert app.query_one(".heh").styles.background != red
Regression test for https://github.com/Textualize/textual/issues/3969.
test_lists_of_selectors_in_nested_css
python
Textualize/textual
tests/css/test_nested_css.py
https://github.com/Textualize/textual/blob/master/tests/css/test_nested_css.py
MIT
async def test_rule_declaration_after_nested() -> None: """Regression test for https://github.com/Textualize/textual/issues/3999.""" app = DeclarationAfterNestedApp() async with app.run_test(): assert app.screen.styles.background == Color.parse("green") assert app.query_one(Label).styles.background == Color.parse("red")
Regression test for https://github.com/Textualize/textual/issues/3999.
test_rule_declaration_after_nested
python
Textualize/textual
tests/css/test_nested_css.py
https://github.com/Textualize/textual/blob/master/tests/css/test_nested_css.py
MIT
def test_parse_errors(css: str, exception: type[Exception]) -> None: """Check some CSS which should fail.""" with pytest.raises(exception): list(parse("", css, ("foo", "")))
Check some CSS which should fail.
test_parse_errors
python
Textualize/textual
tests/css/test_nested_css.py
https://github.com/Textualize/textual/blob/master/tests/css/test_nested_css.py
MIT
async def test_pseudo_classes_work_in_nested_css() -> None: """Makes sure pseudo-classes are correctly understood in nested TCSS. Regression test for https://github.com/Textualize/textual/issues/4039. """ app = PseudoClassesInNestedApp() green = Color.parse("green") red = Color.parse("red") async with app.run_test() as pilot: assert app.query_one("#one").styles.background == green assert app.query_one("#two").styles.background == green assert app.query_one("#five").styles.background == red assert app.query_one("#six").styles.background == red assert app.query_one("#three").styles.background == red assert app.query_one("#four").styles.background == red assert app.query_one("#seven").styles.background == red assert app.query_one("#eight").styles.background == red await pilot.hover("#eight") assert app.query_one("#three").styles.background == red assert app.query_one("#four").styles.background == red assert app.query_one("#seven").styles.background == red assert app.query_one("#eight").styles.background == green
Makes sure pseudo-classes are correctly understood in nested TCSS. Regression test for https://github.com/Textualize/textual/issues/4039.
test_pseudo_classes_work_in_nested_css
python
Textualize/textual
tests/css/test_nested_css.py
https://github.com/Textualize/textual/blob/master/tests/css/test_nested_css.py
MIT
async def test_screen_pushing_and_popping_does_not_reparse_css(): """Check that pushing and popping the same screen doesn't trigger CSS reparses.""" class MyApp(BaseApp): def key_p(self): self.push_screen(ScreenWithCSS()) def key_o(self): self.pop_screen() counter = 0 def reparse_wrapper(reparse): def _reparse(*args, **kwargs): nonlocal counter counter += 1 return reparse(*args, **kwargs) return _reparse app = MyApp() app.stylesheet.reparse = reparse_wrapper(app.stylesheet.reparse) async with app.run_test() as pilot: await pilot.press("p") await pilot.press("o") await pilot.press("p") await pilot.press("o") await pilot.press("p") await pilot.press("o") await pilot.press("p") await pilot.press("o") assert counter == 1
Check that pushing and popping the same screen doesn't trigger CSS reparses.
test_screen_pushing_and_popping_does_not_reparse_css
python
Textualize/textual
tests/css/test_screen_css.py
https://github.com/Textualize/textual/blob/master/tests/css/test_screen_css.py
MIT
async def test_screen_css_push_screen_instance(): """Check that screen CSS is loaded and applied when pushing a screen instance.""" class MyApp(BaseApp): def key_p(self): self.push_screen(ScreenWithCSS()) def key_o(self): self.pop_screen() app = MyApp() async with app.run_test() as pilot: check_colors_before_screen_css(app) await pilot.press("p") check_colors_after_screen_css(app) await pilot.press("o") check_colors_after_screen_css(app)
Check that screen CSS is loaded and applied when pushing a screen instance.
test_screen_css_push_screen_instance
python
Textualize/textual
tests/css/test_screen_css.py
https://github.com/Textualize/textual/blob/master/tests/css/test_screen_css.py
MIT
async def test_screen_css_push_screen_instance_by_name(): """Check that screen CSS is loaded and applied when pushing a screen name that points to a screen instance.""" class MyApp(BaseApp): SCREENS = {"screenwithcss": ScreenWithCSS} def key_p(self): self.push_screen("screenwithcss") def key_o(self): self.pop_screen() app = MyApp() async with app.run_test() as pilot: check_colors_before_screen_css(app) await pilot.press("p") check_colors_after_screen_css(app) await pilot.press("o") check_colors_after_screen_css(app)
Check that screen CSS is loaded and applied when pushing a screen name that points to a screen instance.
test_screen_css_push_screen_instance_by_name
python
Textualize/textual
tests/css/test_screen_css.py
https://github.com/Textualize/textual/blob/master/tests/css/test_screen_css.py
MIT
async def test_screen_css_push_screen_type_by_name(): """Check that screen CSS is loaded and applied when pushing a screen name that points to a screen class.""" class MyApp(BaseApp): SCREENS = {"screenwithcss": ScreenWithCSS} def key_p(self): self.push_screen("screenwithcss") def key_o(self): self.pop_screen() app = MyApp() async with app.run_test() as pilot: check_colors_before_screen_css(app) await pilot.press("p") check_colors_after_screen_css(app) await pilot.press("o") check_colors_after_screen_css(app)
Check that screen CSS is loaded and applied when pushing a screen name that points to a screen class.
test_screen_css_push_screen_type_by_name
python
Textualize/textual
tests/css/test_screen_css.py
https://github.com/Textualize/textual/blob/master/tests/css/test_screen_css.py
MIT
async def test_screen_css_switch_screen_instance(): """Check that screen CSS is loaded and applied when switching to a screen instance.""" class MyApp(SwitchBaseApp): def key_p(self): self.switch_screen(ScreenWithCSS()) def key_o(self): self.pop_screen() app = MyApp() async with app.run_test() as pilot: check_colors_before_screen_css(app) await pilot.press("p") check_colors_after_screen_css(app) await pilot.press("o") check_colors_after_screen_css(app)
Check that screen CSS is loaded and applied when switching to a screen instance.
test_screen_css_switch_screen_instance
python
Textualize/textual
tests/css/test_screen_css.py
https://github.com/Textualize/textual/blob/master/tests/css/test_screen_css.py
MIT
async def test_screen_css_switch_screen_instance_by_name(): """Check that screen CSS is loaded and applied when switching a screen name that points to a screen instance.""" class MyApp(SwitchBaseApp): SCREENS = {"screenwithcss": ScreenWithCSS} def key_p(self): self.switch_screen("screenwithcss") def key_o(self): self.pop_screen() app = MyApp() async with app.run_test() as pilot: check_colors_before_screen_css(app) await pilot.press("p") check_colors_after_screen_css(app) await pilot.press("o") check_colors_after_screen_css(app)
Check that screen CSS is loaded and applied when switching a screen name that points to a screen instance.
test_screen_css_switch_screen_instance_by_name
python
Textualize/textual
tests/css/test_screen_css.py
https://github.com/Textualize/textual/blob/master/tests/css/test_screen_css.py
MIT
async def test_screen_css_switch_screen_type_by_name(): """Check that screen CSS is loaded and applied when switching a screen name that points to a screen class.""" class MyApp(SwitchBaseApp): SCREENS = {"screenwithcss": ScreenWithCSS} async def key_p(self): self.switch_screen("screenwithcss") def key_o(self): self.pop_screen() app = MyApp() async with app.run_test() as pilot: check_colors_before_screen_css(app) await pilot.press("p") check_colors_after_screen_css(app) await pilot.press("o") check_colors_after_screen_css(app)
Check that screen CSS is loaded and applied when switching a screen name that points to a screen class.
test_screen_css_switch_screen_type_by_name
python
Textualize/textual
tests/css/test_screen_css.py
https://github.com/Textualize/textual/blob/master/tests/css/test_screen_css.py
MIT
async def test_screen_css_switch_mode_screen_instance(): """Check that screen CSS is loaded and applied when switching to a mode with a screen instance.""" class MyApp(BaseApp): MODES = { "base": BaseScreen, "mode": ScreenWithCSS, } def key_p(self): self.switch_mode("mode") def key_o(self): self.switch_mode("base") app = MyApp() async with app.run_test() as pilot: await pilot.press("o") check_colors_before_screen_css(app) await pilot.press("p") check_colors_after_screen_css(app) await pilot.press("o") check_colors_after_screen_css(app)
Check that screen CSS is loaded and applied when switching to a mode with a screen instance.
test_screen_css_switch_mode_screen_instance
python
Textualize/textual
tests/css/test_screen_css.py
https://github.com/Textualize/textual/blob/master/tests/css/test_screen_css.py
MIT
async def test_screen_css_switch_mode_screen_instance_by_name(): """Check that screen CSS is loaded and applied when switching to a mode with a screen instance name.""" class MyApp(BaseApp): SCREENS = { "screenwithcss": ScreenWithCSS, } MODES = { "base": BaseScreen, "mode": "screenwithcss", } def key_p(self): self.switch_mode("mode") def key_o(self): self.switch_mode("base") app = MyApp() async with app.run_test() as pilot: await pilot.press("o") check_colors_before_screen_css(app) await pilot.press("p") check_colors_after_screen_css(app) await pilot.press("o") check_colors_after_screen_css(app)
Check that screen CSS is loaded and applied when switching to a mode with a screen instance name.
test_screen_css_switch_mode_screen_instance_by_name
python
Textualize/textual
tests/css/test_screen_css.py
https://github.com/Textualize/textual/blob/master/tests/css/test_screen_css.py
MIT
async def test_screen_css_switch_mode_screen_type_by_name(): """Check that screen CSS is loaded and applied when switching to a mode with a screen type name.""" class MyApp(BaseApp): SCREENS = { "screenwithcss": ScreenWithCSS, } MODES = { "base": BaseScreen, "mode": "screenwithcss", } def key_p(self): self.switch_mode("mode") def key_o(self): self.switch_mode("base") app = MyApp() async with app.run_test() as pilot: await pilot.press("o") check_colors_before_screen_css(app) await pilot.press("p") check_colors_after_screen_css(app) await pilot.press("o") check_colors_after_screen_css(app)
Check that screen CSS is loaded and applied when switching to a mode with a screen type name.
test_screen_css_switch_mode_screen_type_by_name
python
Textualize/textual
tests/css/test_screen_css.py
https://github.com/Textualize/textual/blob/master/tests/css/test_screen_css.py
MIT
def test_parse_bad_pseudo_selector(): """Check unknown selector raises a token error.""" bad_selector = """\ Widget:foo{ border: red; } """ stylesheet = Stylesheet() stylesheet.add_source(bad_selector, None) with pytest.raises(TokenError) as error: stylesheet.parse() assert error.value.start == (1, 7)
Check unknown selector raises a token error.
test_parse_bad_pseudo_selector
python
Textualize/textual
tests/css/test_parse.py
https://github.com/Textualize/textual/blob/master/tests/css/test_parse.py
MIT
def test_parse_bad_pseudo_selector_with_suggestion(): """Check unknown pseudo selector raises token error with correct position.""" bad_selector = """ Widget:blu { border: red; } """ stylesheet = Stylesheet() stylesheet.add_source(bad_selector, None) with pytest.raises(TokenError) as error: stylesheet.parse() assert error.value.start == (2, 7)
Check unknown pseudo selector raises token error with correct position.
test_parse_bad_pseudo_selector_with_suggestion
python
Textualize/textual
tests/css/test_parse.py
https://github.com/Textualize/textual/blob/master/tests/css/test_parse.py
MIT
def test_switches(snap_compare): """Tests switches but also acts a regression test for using width: auto in a Horizontal layout context.""" press = [ "shift+tab", "enter", # toggle off "shift+tab", "wait:20", "enter", # toggle on "wait:20", ] assert snap_compare(WIDGET_EXAMPLES_DIR / "switch.py", press=press)
Tests switches but also acts a regression test for using width: auto in a Horizontal layout context.
test_switches
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_input_validation(snap_compare): """Checking that invalid styling is applied. The snapshot app itself also adds styling for -valid which gives a green border.""" press = [ *"-2", # -2 is invalid, so -invalid should be applied "tab", "3", # This is valid, so -valid should be applied "tab", *"-2", # -2 is invalid, so -invalid should be applied (and :focus, since we stop here) ] assert snap_compare(SNAPSHOT_APPS_DIR / "input_validation.py", press=press)
Checking that invalid styling is applied. The snapshot app itself also adds styling for -valid which gives a green border.
test_input_validation
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_input_setting_value(snap_compare): """Test that Inputs with different values are rendered correctly. The values of inputs should be (from top to bottom): "default", "set attribute in compose" , "" (empty), a placeholder of 'Placeholder, no value', and "set in on_mount". """ class InputApp(App[None]): def compose(self) -> ComposeResult: yield Input(value="default") input2 = Input() input2.value = "set attribute in compose" yield input2 yield Input() yield Input(placeholder="Placeholder, no value") yield Input(id="input3") def on_mount(self) -> None: input3 = self.query_one("#input3", Input) input3.value = "set in on_mount" assert snap_compare(InputApp())
Test that Inputs with different values are rendered correctly. The values of inputs should be (from top to bottom): "default", "set attribute in compose" , "" (empty), a placeholder of 'Placeholder, no value', and "set in on_mount".
test_input_setting_value
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_input_cursor(snap_compare): """The first input should say こんにちは. The second input should say こんにちは, with a cursor on the final character (double width). Note that this might render incorrectly in the SVG output - the letters may overlap. """ class InputApp(App[None]): def compose(self) -> ComposeResult: yield Input(value="こんにちは") input = Input(value="こんにちは", select_on_focus=False) input.focus() input.action_cursor_left() yield input assert snap_compare(InputApp())
The first input should say こんにちは. The second input should say こんにちは, with a cursor on the final character (double width). Note that this might render incorrectly in the SVG output - the letters may overlap.
test_input_cursor
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_input_scrolls_to_cursor(snap_compare): """The input widget should scroll the cursor into view when it moves, and this should account for different cell widths. Only the final two characters should be visible in the first input (ちは). They might be overlapping in the SVG output. In the second input, we should only see numbers 5-9 inclusive, plus the cursor. The number of cells to the right of the cursor should equal the number of cells to the left of the number '5'. """ class InputScrollingApp(App[None]): CSS = "Input { width: 12; }" def compose(self) -> ComposeResult: yield Input(id="input1") yield Input(id="input2") assert snap_compare( InputScrollingApp(), press=[*"こんにちは", "tab", *"0123456789"] )
The input widget should scroll the cursor into view when it moves, and this should account for different cell widths. Only the final two characters should be visible in the first input (ちは). They might be overlapping in the SVG output. In the second input, we should only see numbers 5-9 inclusive, plus the cursor. The number of cells to the right of the cursor should equal the number of cells to the left of the number '5'.
test_input_scrolls_to_cursor
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_input_initial_scroll(snap_compare): """When the input is smaller than its content, the start of the content should be visible, not the end.""" class InputInitialScrollApp(App[None]): AUTO_FOCUS = None def compose(self) -> ComposeResult: yield Input(value="the quick brown fox jumps over the lazy dog") assert snap_compare(InputInitialScrollApp(), terminal_size=(20, 5))
When the input is smaller than its content, the start of the content should be visible, not the end.
test_input_initial_scroll
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_input_selection(snap_compare): """BCDEF should be visible, and DEF should be selected. The cursor should be sitting above 'D'.""" class InputSelectionApp(App[None]): CSS = "Input { width: 12; }" def compose(self) -> ComposeResult: yield Input(id="input1") assert snap_compare(InputSelectionApp(), press=[*"ABCDEF", *("shift+left",) * 3])
BCDEF should be visible, and DEF should be selected. The cursor should be sitting above 'D'.
test_input_selection
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_datatable_auto_height_future_updates(snap_compare): """https://github.com/Textualize/textual/issues/4928 meant that when height=None, in add_row, future updates to the table would be incorrect. In this test, every 2nd row is auto height and every other row is height 2. The table is cleared then fully repopulated with the same 4 rows. All 4 rows should be visible and rendered at heights 2, 1, 2, 1. """ ROWS = [ ("foo", "bar"), (1, "abc"), (2, "def"), (3, "ghi"), (4, "jkl"), ] class ExampleApp(App[None]): CSS = "DataTable { border: solid red; }" def compose(self) -> ComposeResult: yield DataTable() def on_mount(self) -> None: table = self.query_one(DataTable) table.add_columns(*ROWS[0]) self.populate_table() def key_r(self) -> None: self.populate_table() def populate_table(self) -> None: table = self.query_one(DataTable) table.clear() for i, row in enumerate(ROWS[1:]): table.add_row( *row, height=None if i % 2 == 1 else 2, ) assert snap_compare(ExampleApp(), press=["r"])
https://github.com/Textualize/textual/issues/4928 meant that when height=None, in add_row, future updates to the table would be incorrect. In this test, every 2nd row is auto height and every other row is height 2. The table is cleared then fully repopulated with the same 4 rows. All 4 rows should be visible and rendered at heights 2, 1, 2, 1.
test_datatable_auto_height_future_updates
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_radio_set_is_scrollable(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/5100""" class RadioSetApp(App): CSS = """ RadioSet { height: 5; } """ def compose(self) -> ComposeResult: yield RadioSet(*[(f"This is option #{n}") for n in range(10)]) app = RadioSetApp() assert snap_compare(app, press=["up"])
Regression test for https://github.com/Textualize/textual/issues/5100
test_radio_set_is_scrollable
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_select_no_blank_has_default_value(snap_compare): """Make sure that the first value is selected by default if allow_blank=False.""" assert snap_compare(WIDGET_EXAMPLES_DIR / "select_widget_no_blank.py")
Make sure that the first value is selected by default if allow_blank=False.
test_select_no_blank_has_default_value
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_select_type_to_search(snap_compare): """The select was expanded and the user typed "pi", which should match "Pigeon". The "Pigeon" option should be highlighted and scrolled into view. """ class SelectTypeToSearch(App[None]): CSS = "SelectOverlay { height: 5; }" def compose(self) -> ComposeResult: values = [ "Ostrich", "Penguin", "Duck", "Chicken", "Goose", "Pigeon", "Turkey", ] yield Select[str].from_values(values, type_to_search=True) async def run_before(pilot): await pilot.press("enter") # Expand the select await pilot.press(*"pi") # Search for "pi", which should match "Pigeon" assert snap_compare(SelectTypeToSearch(), run_before=run_before)
The select was expanded and the user typed "pi", which should match "Pigeon". The "Pigeon" option should be highlighted and scrolled into view.
test_select_type_to_search
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_offsets(snap_compare): """Test offsets of containers""" assert snap_compare("snapshot_apps/offsets.py")
Test offsets of containers
test_offsets
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_nested_auto_heights(snap_compare): """Test refreshing widget within a auto sized container""" assert snap_compare("snapshot_apps/nested_auto_heights.py", press=["1", "2"])
Test refreshing widget within a auto sized container
test_nested_auto_heights
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_programmatic_scrollbar_gutter_change(snap_compare): """Regression test for #1607 https://github.com/Textualize/textual/issues/1607 See also tests/css/test_programmatic_style_changes.py for other related regression tests. """ assert snap_compare( "snapshot_apps/programmatic_scrollbar_gutter_change.py", press=["s"] )
Regression test for #1607 https://github.com/Textualize/textual/issues/1607 See also tests/css/test_programmatic_style_changes.py for other related regression tests.
test_programmatic_scrollbar_gutter_change
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_label_widths(snap_compare): """Test renderable widths are calculate correctly.""" assert snap_compare(SNAPSHOT_APPS_DIR / "label_widths.py")
Test renderable widths are calculate correctly.
test_label_widths
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_border_alpha(snap_compare): """Test setting a border alpha.""" assert snap_compare(SNAPSHOT_APPS_DIR / "border_alpha.py")
Test setting a border alpha.
test_border_alpha
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_richlog_scroll(snap_compare): """Ensure `RichLog.auto_scroll` causes the log to scroll to the end when new content is written.""" assert snap_compare(SNAPSHOT_APPS_DIR / "richlog_scroll.py")
Ensure `RichLog.auto_scroll` causes the log to scroll to the end when new content is written.
test_richlog_scroll
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_richlog_width(snap_compare): """Check that the width of RichLog is respected, even when it's not visible.""" assert snap_compare(SNAPSHOT_APPS_DIR / "richlog_width.py", press=["p"])
Check that the width of RichLog is respected, even when it's not visible.
test_richlog_width
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_richlog_min_width(snap_compare): """The available space of this RichLog is less than the minimum width, so written content should be rendered at `min_width`. This snapshot should show the renderable clipping at the right edge, as there's not enough space to satisfy the minimum width. """ class RichLogMinWidth20(App[None]): def compose(self) -> ComposeResult: rich_log = RichLog(min_width=20) text = Text("0123456789", style="on red", justify="right") rich_log.write(text) yield rich_log assert snap_compare(RichLogMinWidth20(), terminal_size=(20, 6))
The available space of this RichLog is less than the minimum width, so written content should be rendered at `min_width`. This snapshot should show the renderable clipping at the right edge, as there's not enough space to satisfy the minimum width.
test_richlog_min_width
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_richlog_deferred_render_no_expand(snap_compare): """Check we can write to a RichLog before its size is known i.e. in `compose`.""" class RichLogNoExpand(App[None]): def compose(self) -> ComposeResult: rich_log = RichLog(min_width=10) text = Text("0123456789", style="on red", justify="right") # Perform the write in compose - it'll be deferred until the size is known rich_log.write(text) yield rich_log assert snap_compare(RichLogNoExpand(), terminal_size=(20, 6))
Check we can write to a RichLog before its size is known i.e. in `compose`.
test_richlog_deferred_render_no_expand
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_richlog_deferred_render_expand(snap_compare): """Check we can write to a RichLog before its size is known i.e. in `compose`. The renderable should expand to fill full the width of the RichLog. """ class RichLogExpand(App[None]): def compose(self) -> ComposeResult: rich_log = RichLog(min_width=10) text = Text("0123456789", style="on red", justify="right") # Perform the write in compose - it'll be deferred until the size is known rich_log.write(text, expand=True) yield rich_log assert snap_compare(RichLogExpand(), terminal_size=(20, 6))
Check we can write to a RichLog before its size is known i.e. in `compose`. The renderable should expand to fill full the width of the RichLog.
test_richlog_deferred_render_expand
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_richlog_markup(snap_compare): """Check that Rich markup is rendered in RichLog when markup=True.""" class RichLogWidth(App[None]): def compose(self) -> ComposeResult: rich_log = RichLog(min_width=10, markup=True) rich_log.write("[black on red u]black text on red, underlined") rich_log.write("normal text, no markup") yield rich_log assert snap_compare(RichLogWidth(), terminal_size=(42, 6))
Check that Rich markup is rendered in RichLog when markup=True.
test_richlog_markup
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_richlog_shrink(snap_compare): """Ensure that when shrink=True, the renderable shrinks to fit the width of the RichLog.""" class RichLogShrink(App[None]): CSS = "RichLog { width: 20; background: red;}" def compose(self) -> ComposeResult: rich_log = RichLog(min_width=4) panel = Panel("lorem ipsum dolor sit amet lorem ipsum dolor sit amet") rich_log.write(panel) yield rich_log assert snap_compare(RichLogShrink(), terminal_size=(24, 6))
Ensure that when shrink=True, the renderable shrinks to fit the width of the RichLog.
test_richlog_shrink
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_richlog_write_at_specific_width(snap_compare): """Ensure we can write renderables at a specific width. `min_width` should be respected, but `width` should override. The green label at the bottom should be equal in width to the bottom renderable (equal to min_width). """ class RichLogWriteAtSpecificWidth(App[None]): CSS = """ RichLog { width: 1fr; height: auto; } #width-marker { background: green; width: 50; } """ def compose(self) -> ComposeResult: rich_log = RichLog(min_width=50) rich_log.write(Panel("width=20", style="black on red"), width=20) rich_log.write(Panel("width=40", style="black on red"), width=40) rich_log.write(Panel("width=60", style="black on red"), width=60) rich_log.write(Panel("width=120", style="black on red"), width=120) rich_log.write( Panel("width=None (fallback to min_width)", style="black on red") ) yield rich_log width_marker = Label( f"this label is width 50 (same as min_width)", id="width-marker" ) yield width_marker assert snap_compare(RichLogWriteAtSpecificWidth())
Ensure we can write renderables at a specific width. `min_width` should be respected, but `width` should override. The green label at the bottom should be equal in width to the bottom renderable (equal to min_width).
test_richlog_write_at_specific_width
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_richlog_highlight(snap_compare): """Check that RichLog.highlight correctly highlights with the ReprHighlighter. Also ensures that interaction between CSS and highlighting is as expected - non-highlighted text should have the CSS styles applied, but highlighted text should ignore the CSS (and use the highlights returned from the highlighter). """ class RichLogHighlight(App[None]): # Add some CSS to check interaction with highlighting. CSS = """ RichLog { color: red; background: dodgerblue 40%; } """ def compose(self) -> ComposeResult: rich_log = RichLog(highlight=True) rich_log.write("Foo('bar', x=1, y=[1, 2, 3])") yield rich_log assert snap_compare(RichLogHighlight(), terminal_size=(30, 3))
Check that RichLog.highlight correctly highlights with the ReprHighlighter. Also ensures that interaction between CSS and highlighting is as expected - non-highlighted text should have the CSS styles applied, but highlighted text should ignore the CSS (and use the highlights returned from the highlighter).
test_richlog_highlight
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_css_hot_reloading(snap_compare, monkeypatch): """Regression test for https://github.com/Textualize/textual/issues/2063.""" monkeypatch.setenv( "TEXTUAL", "debug" ) # This will make sure we create a file monitor. async def run_before(pilot): css_file = pilot.app.CSS_PATH with open(css_file, "w") as f: f.write("/* This file is purposefully empty. */\n") # Clear all the CSS. await pilot.app._on_css_change() assert snap_compare( SNAPSHOT_APPS_DIR / "hot_reloading_app.py", run_before=run_before )
Regression test for https://github.com/Textualize/textual/issues/2063.
test_css_hot_reloading
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_css_hot_reloading_on_screen(snap_compare, monkeypatch): """Regression test for https://github.com/Textualize/textual/issues/3454.""" monkeypatch.setenv( "TEXTUAL", "debug" ) # This will make sure we create a file monitor. async def run_before(pilot): css_file = pilot.app.screen.CSS_PATH with open(css_file, "w") as f: f.write("/* This file is purposefully empty. */\n") # Clear all the CSS. await pilot.app._on_css_change() assert snap_compare( SNAPSHOT_APPS_DIR / "hot_reloading_app_with_screen_css.py", run_before=run_before, )
Regression test for https://github.com/Textualize/textual/issues/3454.
test_css_hot_reloading_on_screen
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_datatable_hot_reloading(snap_compare, monkeypatch): """Regression test for https://github.com/Textualize/textual/issues/3312.""" monkeypatch.setenv( "TEXTUAL", "debug" ) # This will make sure we create a file monitor. async def run_before(pilot): css_file = pilot.app.CSS_PATH with open(css_file, "w") as f: f.write("/* This file is purposefully empty. */\n") # Clear all the CSS. await pilot.app._on_css_change() assert snap_compare( SNAPSHOT_APPS_DIR / "datatable_hot_reloading.py", run_before=run_before )
Regression test for https://github.com/Textualize/textual/issues/3312.
test_datatable_hot_reloading
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_markdown_component_classes_reloading(snap_compare, monkeypatch): """Tests all markdown component classes reload correctly. See https://github.com/Textualize/textual/issues/3464.""" monkeypatch.setenv( "TEXTUAL", "debug" ) # This will make sure we create a file monitor. async def run_before(pilot): css_file = pilot.app.CSS_PATH with open(css_file, "w") as f: f.write("/* This file is purposefully empty. */\n") # Clear all the CSS. await pilot.app._on_css_change() assert snap_compare( SNAPSHOT_APPS_DIR / "markdown_component_classes_reloading.py", run_before=run_before, )
Tests all markdown component classes reload correctly. See https://github.com/Textualize/textual/issues/3464.
test_markdown_component_classes_reloading
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_dock_none(snap_compare): """Checking that `dock:none` works in CSS and Python. The label should appear at the top here, since we've undocked both the header and footer. """ class DockNone(App[None]): CSS = "Header { dock: none; }" def compose(self) -> ComposeResult: yield Label("Hello") yield Header() footer = Footer() footer.styles.dock = "none" yield footer assert snap_compare(DockNone(), terminal_size=(30, 5))
Checking that `dock:none` works in CSS and Python. The label should appear at the top here, since we've undocked both the header and footer.
test_dock_none
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_text_area_themes(snap_compare, theme_name): """Each theme should have its own snapshot with at least some Python to check that the rendering is sensible. This also ensures that theme switching results in the display changing correctly.""" text = """\ def hello(name): x = 123 while not False: print("hello " + name) continue """ def setup_theme(pilot): text_area = pilot.app.query_one(TextArea) text_area.load_text(text) text_area.language = "python" text_area.selection = Selection((0, 1), (1, 9)) text_area.theme = theme_name assert snap_compare( SNAPSHOT_APPS_DIR / "text_area.py", run_before=setup_theme, terminal_size=(48, text.count("\n") + 4), )
Each theme should have its own snapshot with at least some Python to check that the rendering is sensible. This also ensures that theme switching results in the display changing correctly.
test_text_area_themes
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_button_outline(snap_compare): """Outline style rendered incorrectly when applied to a `Button` widget. Regression test for https://github.com/Textualize/textual/issues/3628 """ assert snap_compare(SNAPSHOT_APPS_DIR / "button_outline.py")
Outline style rendered incorrectly when applied to a `Button` widget. Regression test for https://github.com/Textualize/textual/issues/3628
test_button_outline
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_notifications_loading_overlap_order(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/3677. This tests that notifications stay on top of loading indicators and it also tests that loading a widget will remove its scrollbars. """ assert snap_compare( SNAPSHOT_APPS_DIR / "notifications_above_loading.py", terminal_size=(80, 20) )
Regression test for https://github.com/Textualize/textual/issues/3677. This tests that notifications stay on top of loading indicators and it also tests that loading a widget will remove its scrollbars.
test_notifications_loading_overlap_order
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_missing_vertical_scroll(snap_compare): """Regression test for https://github.com/Textualize/textual/issues/3687""" assert snap_compare(SNAPSHOT_APPS_DIR / "missing_vertical_scroll.py")
Regression test for https://github.com/Textualize/textual/issues/3687
test_missing_vertical_scroll
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_vertical_min_height(snap_compare): """Test vertical min height takes border into account.""" assert snap_compare(SNAPSHOT_APPS_DIR / "vertical_min_height.py")
Test vertical min height takes border into account.
test_vertical_min_height
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_vertical_max_height(snap_compare): """Test vertical max height takes border into account.""" assert snap_compare(SNAPSHOT_APPS_DIR / "vertical_max_height.py")
Test vertical max height takes border into account.
test_vertical_max_height
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_max_height_100(snap_compare): """Test a datatable with max height 100%.""" assert snap_compare(SNAPSHOT_APPS_DIR / "max_height_100.py")
Test a datatable with max height 100%.
test_max_height_100
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_loading_indicator(snap_compare): """Test loading indicator.""" # https://github.com/Textualize/textual/pull/3816 assert snap_compare(SNAPSHOT_APPS_DIR / "loading.py", press=["space"])
Test loading indicator.
test_loading_indicator
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_loading_indicator_disables_widget(snap_compare): """Test loading indicator disabled widget.""" # https://github.com/Textualize/textual/pull/3816 assert snap_compare( SNAPSHOT_APPS_DIR / "loading.py", press=["space", "down", "down", "space"] )
Test loading indicator disabled widget.
test_loading_indicator_disables_widget
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_mount_style_fix(snap_compare): """Regression test for broken style update on mount.""" # https://github.com/Textualize/textual/issues/3858 assert snap_compare(SNAPSHOT_APPS_DIR / "mount_style_fix.py")
Regression test for broken style update on mount.
test_mount_style_fix
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_zero_scrollbar_size(snap_compare): """Regression test for missing content with 0 sized scrollbars""" # https://github.com/Textualize/textual/issues/3886 assert snap_compare(SNAPSHOT_APPS_DIR / "zero_scrollbar_size.py")
Regression test for missing content with 0 sized scrollbars
test_zero_scrollbar_size
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_tree_clearing_and_expansion(snap_compare): """Test the Tree.root.is_expanded state after a Tree.clear""" # https://github.com/Textualize/textual/issues/3557 assert snap_compare(SNAPSHOT_APPS_DIR / "tree_clearing.py")
Test the Tree.root.is_expanded state after a Tree.clear
test_tree_clearing_and_expansion
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_nested_specificity(snap_compare): """Test specificity of nested rules is working.""" # https://github.com/Textualize/textual/issues/3961 assert snap_compare(SNAPSHOT_APPS_DIR / "nested_specificity.py")
Test specificity of nested rules is working.
test_nested_specificity
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_tab_rename(snap_compare): """Test setting a new label for a tab amongst a TabbedContent.""" assert snap_compare(SNAPSHOT_APPS_DIR / "tab_rename.py")
Test setting a new label for a tab amongst a TabbedContent.
test_tab_rename
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_input_percentage_width(snap_compare): """Check percentage widths work correctly.""" # https://github.com/Textualize/textual/issues/3721 assert snap_compare(SNAPSHOT_APPS_DIR / "input_percentage_width.py")
Check percentage widths work correctly.
test_input_percentage_width
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_recompose(snap_compare): """Check recompose works.""" # https://github.com/Textualize/textual/pull/4206 assert snap_compare(SNAPSHOT_APPS_DIR / "recompose.py")
Check recompose works.
test_recompose
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_ansi_color_mapping(snap_compare, theme): """Test how ANSI colors in Rich renderables are mapped to hex colors.""" def setup(pilot): pilot.app.theme = theme assert snap_compare(SNAPSHOT_APPS_DIR / "ansi_mapping.py", run_before=setup)
Test how ANSI colors in Rich renderables are mapped to hex colors.
test_ansi_color_mapping
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT
def test_pretty_grid_gutter_interaction(snap_compare): """Regression test for https://github.com/Textualize/textual/pull/4219.""" assert snap_compare( SNAPSHOT_APPS_DIR / "pretty_grid_gutter_interaction.py", terminal_size=(81, 7) )
Regression test for https://github.com/Textualize/textual/pull/4219.
test_pretty_grid_gutter_interaction
python
Textualize/textual
tests/snapshot_tests/test_snapshots.py
https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py
MIT