From 6c9a1a6e5d39c95829bc5c3e271363dc876ada12 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 24 Oct 2022 09:39:17 +0100 Subject: [PATCH] Add tests for the initialisation of CSS_PATH This improves coverage of _make_path_object_relative in _path.py, and generally provides some simple tests of how CSS_PATH gets turned into a css_path property of an App. Note that if an actual CSS path gets added (something that has been mooted) this will need updating. --- tests/test_path.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/test_path.py diff --git a/tests/test_path.py b/tests/test_path.py new file mode 100644 index 000000000..42818236c --- /dev/null +++ b/tests/test_path.py @@ -0,0 +1,43 @@ +from typing import Type +from pathlib import Path + +from textual.app import App + +class RelativePathObjectApp(App[None]): + + CSS_PATH = Path("test.css") + +class RelativePathStrApp(App[None]): + + CSS_PATH = "test.css" + +class AbsolutePathObjectApp(App[None]): + + CSS_PATH = Path("/tmp/test.css") + +class AbsolutePathStrApp(App[None]): + + CSS_PATH = "/tmp/test.css" + +def path_tester(obj_type: Type[App[None]], str_type: Type[App[None]], intended_result: Path) -> None: + assert isinstance(obj_type().css_path,Path), ( + "CSS_PATH didn't stay as an object" + ) + assert isinstance(str_type().css_path,Path), ( + "CSS_PATH wasn't converted from str to Path" + ) + assert obj_type().css_path == intended_result, ( + "CSS_PATH doesn't match the intended result." + ) + assert str_type().css_path == intended_result, ( + "CSS_PATH doesn't match the intended result." + ) + assert str_type().css_path == obj_type().css_path, ( + "CSS_PATH str to Path conversion gave a different result" + ) + +def test_relative_path(): + path_tester(RelativePathObjectApp, RelativePathStrApp, ((Path(__file__).absolute().parent ) / "test.css")) + +def test_absolute_path(): + path_tester(AbsolutePathObjectApp, AbsolutePathStrApp, Path("/tmp/test.css"))