From 29a891724be7975cdb06e0ff7fb7e55817edf13a Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Thu, 17 Nov 2022 10:37:30 +0000 Subject: [PATCH 01/11] Tidy up dead code from linux_driver.py --- src/textual/drivers/linux_driver.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/textual/drivers/linux_driver.py b/src/textual/drivers/linux_driver.py index f0e75e71e..8f61c4fb2 100644 --- a/src/textual/drivers/linux_driver.py +++ b/src/textual/drivers/linux_driver.py @@ -236,17 +236,3 @@ class LinuxDriver(Driver): finally: with timer("selector.close"): selector.close() - - -if __name__ == "__main__": - from rich.console import Console - - console = Console() - - from ..app import App - - class MyApp(App): - async def on_mount(self, event: events.Mount) -> None: - self.set_timer(5, callback=self._close_messages) - - MyApp.run() From 5f4a44c6c64fa8521ca6224dec559561fdb997d3 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Thu, 17 Nov 2022 10:39:43 +0000 Subject: [PATCH 02/11] Fix the devtools example of how to run an app --- docs/guide/devtools.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/guide/devtools.md b/docs/guide/devtools.md index fa0d1e7e9..8643073ff 100644 --- a/docs/guide/devtools.md +++ b/docs/guide/devtools.md @@ -25,7 +25,7 @@ textual run my_app.py The `run` sub-command will first look for a `App` instance called `app` in the global scope of your Python file. If there is no `app`, it will create an instance of the first `App` class it finds and run that. -Alternatively, you can add the name of an `App` instance or class after a colon to run a specific app in the Python file. Here's an example: +Alternatively, you can add the name of an `App` instance or class after a colon to run a specific app in the Python file. Here's an example: ```bash textual run my_app.py:alternative_app @@ -119,6 +119,6 @@ class LogApp(App): self.log(self.tree) if __name__ == "__main__": - LogApp.run() + LogApp().run() ``` From 965cc7d19f8fd95d44b3c90f5607a8d0d6248773 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Thu, 17 Nov 2022 10:44:08 +0000 Subject: [PATCH 03/11] Remove old test code from css/parse.py This is covered in unit tests these days. --- src/textual/css/parse.py | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/textual/css/parse.py b/src/textual/css/parse.py index fdfca677a..1560a009f 100644 --- a/src/textual/css/parse.py +++ b/src/textual/css/parse.py @@ -366,26 +366,3 @@ def parse( is_default_rules=is_default_rules, tie_breaker=tie_breaker, ) - - -if __name__ == "__main__": - print(parse_selectors("Foo > Bar.baz { foo: bar")) - - css = """#something { - text: on red; - transition: offset 5.51s in_out_cubic; - offset-x: 100%; -} -""" - - from textual.css.stylesheet import Stylesheet, StylesheetParseError - from rich.console import Console - - console = Console() - stylesheet = Stylesheet() - try: - stylesheet.add_source(css) - except StylesheetParseError as e: - console.print(e.errors) - print(stylesheet) - print(stylesheet.css) From 93f952b74b165bb28bb4f6df188d75c374d04443 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Thu, 17 Nov 2022 10:45:07 +0000 Subject: [PATCH 04/11] Remove old test code from css/scalar.py This is covered in unit tests these days. --- src/textual/css/scalar.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/textual/css/scalar.py b/src/textual/css/scalar.py index 8c5fa39b9..0fb4f874b 100644 --- a/src/textual/css/scalar.py +++ b/src/textual/css/scalar.py @@ -383,10 +383,3 @@ def percentage_string_to_float(string: str) -> float: else: float_percentage = float(string) return float_percentage - - -if __name__ == "__main__": - print(Scalar.parse("3.14fr")) - s = Scalar.parse("23") - print(repr(s)) - print(repr(s.cells)) From c8ae2455cf580de7456bccf69c671dec51bb5daf Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Thu, 17 Nov 2022 10:47:22 +0000 Subject: [PATCH 05/11] Remove old test code from css/styles.py This isn't fullt covered in unit tests yet, but the dead code can be removed and adding unit tests should likely be encouraged. --- src/textual/css/styles.py | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/src/textual/css/styles.py b/src/textual/css/styles.py index 17e5963a8..6b4dc1d7e 100644 --- a/src/textual/css/styles.py +++ b/src/textual/css/styles.py @@ -1037,25 +1037,3 @@ class RenderStyles(StylesBase): styles.merge(self._inline_styles) combined_css = styles.css return combined_css - - -if __name__ == "__main__": - styles = Styles() - - styles.display = "none" - styles.visibility = "hidden" - styles.border = ("solid", "rgb(10,20,30)") - styles.outline_right = ("solid", "red") - styles.text_style = "italic" - styles.dock = "bar" - styles.layers = "foo bar" - - from rich import print - - print(styles.text_style) - print(styles.text) - - print(styles) - print(styles.css) - - print(styles.extract_rules((0, 1, 0))) From f40c0bf3d0eaf1d8d920d4a65b86ad658c0ea8e5 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Thu, 17 Nov 2022 10:53:46 +0000 Subject: [PATCH 06/11] Remove old test code from css/tokenize.py This is covered in unit tests these days. --- src/textual/css/tokenize.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/textual/css/tokenize.py b/src/textual/css/tokenize.py index dbec369df..e13820fd6 100644 --- a/src/textual/css/tokenize.py +++ b/src/textual/css/tokenize.py @@ -197,18 +197,3 @@ def tokenize_values(values: dict[str, str]) -> dict[str, list[Token]]: name: list(tokenize_value(value, "__name__")) for name, value in values.items() } return value_tokens - - -if __name__ == "__main__": - from rich import print - - css = """#something { - - color: rgb(10,12,23) - } - """ - # transition: offset 500 in_out_cubic; - tokens = tokenize(css, __name__) - print(list(tokens)) - - print(tokenize_values({"primary": "rgb(10,20,30)", "secondary": "#ff00ff"})) From 33eefd56cfdaec9beea254d45f4e0afe268a3a15 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Thu, 17 Nov 2022 10:56:27 +0000 Subject: [PATCH 07/11] Remove old test code from renderables/blank.py This is covered in unit tests these days. --- src/textual/renderables/blank.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/textual/renderables/blank.py b/src/textual/renderables/blank.py index b83dbbc34..05552ac2f 100644 --- a/src/textual/renderables/blank.py +++ b/src/textual/renderables/blank.py @@ -25,9 +25,3 @@ class Blank: for _ in range(height): yield segment yield line - - -if __name__ == "__main__": - from rich import print - - print(Blank("red")) From 53b760eea2bb66f6525944aa041a954a86492e4c Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Thu, 17 Nov 2022 10:58:01 +0000 Subject: [PATCH 08/11] Remove old test code from renderables/gradient.py This isn't currently covered in unit tests but should be at some point? Either way, having a test in dead code in the library doesn't help much any more. --- src/textual/renderables/gradient.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/textual/renderables/gradient.py b/src/textual/renderables/gradient.py index 7d5fb3243..a0c5379fb 100644 --- a/src/textual/renderables/gradient.py +++ b/src/textual/renderables/gradient.py @@ -36,9 +36,3 @@ class VerticalGradient: ), ) yield Segment(f"{width * ' '}\n", line_color) - - -if __name__ == "__main__": - from rich import print - - print(VerticalGradient("red", "blue")) From 265f77097645d0b11aff102f256e625eca015b16 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Thu, 17 Nov 2022 11:01:31 +0000 Subject: [PATCH 09/11] Remove old test code from case.py This is covered in unit tests these days. --- src/textual/case.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/textual/case.py b/src/textual/case.py index ba34e58a8..4ae4883f3 100644 --- a/src/textual/case.py +++ b/src/textual/case.py @@ -22,7 +22,3 @@ def camel_to_snake( return f"{lower}_{upper.lower()}" return _re_snake.sub(repl, name).lower() - - -if __name__ == "__main__": - print(camel_to_snake("HelloWorldEvent")) From 3b8b0ebeb2fa22b2899c01ff9e814be3abf1ec1d Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Thu, 17 Nov 2022 11:02:29 +0000 Subject: [PATCH 10/11] Remove old test code from design.py This is covered in unit tests these days. --- src/textual/design.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/textual/design.py b/src/textual/design.py index 2294de748..490aa9da2 100644 --- a/src/textual/design.py +++ b/src/textual/design.py @@ -222,11 +222,3 @@ def show_design(light: ColorSystem, dark: ColorSystem) -> Table: table.add_column("Dark", justify="center") table.add_row(make_shades(light), make_shades(dark)) return table - - -if __name__ == "__main__": - from .app import DEFAULT_COLORS - - from rich import print - - print(show_design(DEFAULT_COLORS["light"], DEFAULT_COLORS["dark"])) From be0a268395ba533c4d571068f4bb17387a85f2f3 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Thu, 17 Nov 2022 11:04:01 +0000 Subject: [PATCH 11/11] Remove old test code from scrollbar.py This is covered in unit tests these days. --- src/textual/scrollbar.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/textual/scrollbar.py b/src/textual/scrollbar.py index 707cd67d2..f6d115f8a 100644 --- a/src/textual/scrollbar.py +++ b/src/textual/scrollbar.py @@ -320,18 +320,3 @@ class ScrollBarCorner(Widget): styles = self.parent.styles color = styles.scrollbar_corner_color return Blank(color) - - -if __name__ == "__main__": - from rich.console import Console - - console = Console() - - thickness = 2 - console.print(f"Bars thickness: {thickness}") - - console.print("Vertical bar:") - console.print(ScrollBarRender.render_bar(thickness=thickness)) - - console.print("Horizontal bar:") - console.print(ScrollBarRender.render_bar(vertical=False, thickness=thickness))