mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Because testing on Windows is going to add a drive to any absolute path, and in the tests we don't want to make it specific to something like that, take the absolute path to test against and then absolute it again which is pretty much a NOP on a Unix-a-like, but will add the drive on Windows.
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
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").absolute())
|
|
|
|
def test_absolute_path():
|
|
path_tester(AbsolutePathObjectApp, AbsolutePathStrApp, Path("/tmp/test.css").absolute())
|