diff --git a/setup.cfg b/setup.cfg index 45ebfe3..1c8f5fb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -64,7 +64,7 @@ zip_safe = False # bin/second.py install_requires = - # snazzy + typing-extensions;python_version<'3.11' # [options.package_data] # * = *.txt, *.rst diff --git a/tests/test_fs.py b/tests/test_fs.py index 49a2c94..1f54c8b 100644 --- a/tests/test_fs.py +++ b/tests/test_fs.py @@ -14,32 +14,6 @@ class TestFS: - # @pytest.mark.skipif(os.name == "nt", reason="windows has different eol size") - # def test_fs_linux(self): - # path = Path(__file__).parent / "fixtures" - - # # We check for unix line endings/file sizes (as used on travis) - # tree = load_tree_from_fs(path) - # assert fixture.check_content( - # tree, - # """ - # FileSystemTree<*> - # ├── 'file_1.txt', 13 bytes, 2022-04-14 21:35:21 - # ╰── [folder_1] - # ╰── 'file_1_1.txt', 15 bytes, 2022-04-14 21:35:21 - # """, - # ) - - # tree = load_tree_from_fs(path, sort=False) - # assert "[folder_1]" in fixture.canonical_repr(tree) - - # @pytest.mark.skipif(os.name != "nt", reason="windows has different eol size") - # def test_fs_windows(self): - # path = Path(__file__).parent / "fixtures" - # # Cheap test only, - # tree = load_tree_from_fs(path) - # assert "[folder_1]" in fixture.canonical_repr(tree) - def test_fs_serialize(self): KEEP_FILES = False path = Path(__file__).parent / "fixtures" @@ -69,3 +43,36 @@ def test_fs_serialize_unsorted(self): tree = load_tree_from_fs(path, sort=False) assert "[folder_1]" in fixture.canonical_repr(tree) assert len(tree) == 3 + + # NOTE: these tests are not very useful, since they depend on the file system + # and the file system is not under our control (e.g. line endings, file sizes, etc.) + # Especially on GitHub Actions we have no control over the file system and + # timestamps, so we cannot compare the output of `load_tree_from_fs` with a + # fixture. + # We should only test the serialization/deserialization here. + + # @pytest.mark.skipif(os.name == "nt", reason="windows has different eol size") + # def test_fs_linux(self): + # path = Path(__file__).parent / "fixtures" + + # # We check for unix line endings/file sizes (as used on travis) + # tree = load_tree_from_fs(path) + # assert fixture.check_content( + # tree, + # """ + # FileSystemTree<*> + # ├── 'file_1.txt', 13 bytes, 2022-04-14 21:35:21 + # ╰── [folder_1] + # ╰── 'file_1_1.txt', 15 bytes, 2022-04-14 21:35:21 + # """, + # ) + + # tree = load_tree_from_fs(path, sort=False) + # assert "[folder_1]" in fixture.canonical_repr(tree) + + # @pytest.mark.skipif(os.name != "nt", reason="windows has different eol size") + # def test_fs_windows(self): + # path = Path(__file__).parent / "fixtures" + # # Cheap test only, + # tree = load_tree_from_fs(path) + # assert "[folder_1]" in fixture.canonical_repr(tree) diff --git a/tests/test_typing_concept.py b/tests/test_typing_concept.py index 96c8c6d..710d413 100644 --- a/tests/test_typing_concept.py +++ b/tests/test_typing_concept.py @@ -2,40 +2,40 @@ from __future__ import annotations -import pytest - -# pytest.skip(allow_module_level=True) +from typing import Any, Generic, List, Type, TypeVar, cast try: - from typing import Any, Generic, List, Self, TypeVar, cast + from typing import Self except ImportError as e: print(f"ImportError: {e}") + from typing_extensions import Self + # _ = pytest.importorskip("typing_extensions") # from typing_extensions import Self - typing_extensions = pytest.importorskip("typing_extensions") - Self = typing_extensions.Self # TData = TypeVar("TData") TNode = TypeVar("TNode", bound="Node") -class Node: - def __init__(self, data: Any, parent: Node): +class Node(Generic[TNode]): + def __init__(self, data: Any, parent: Self): self.data: Any = data - self.parent: Node = parent - self.children: List[Node] = [] + self.parent: Self = parent + self.children: List[Self] = [] - def add(self, data: Any) -> Node: - node = Node(data, self) + def add(self, data: Any) -> Self: + node = self.__class__(data, self) self.children.append(node) return node class Tree(Generic[TNode]): + node_class: Type[TNode] = Node + def __init__(self): - self.root: Node = Node("__root__", cast(TNode, None)) + self.root: TNode = self.node_class("__root__", cast(TNode, None)) - def add(self, data: Any) -> Node: + def add(self, data: Any) -> TNode: node = self.root.add(data) return node @@ -44,26 +44,27 @@ def first(self) -> TNode: # ---------------------------- -# ---------------------------- class TypedNode(Node): - def __init__(self, data: Any, kind: str, parent: TypedNode): + def __init__(self, data: Any, kind: str, parent: Self): super().__init__(data, parent) self.kind: str = kind # self.children: List[TypedNode] = [] - def add(self, data: Any, kind: str) -> TypedNode: - node = TypedNode(data, kind, self) + def add(self, data: Any, kind: str) -> Self: + node = self.__class__(data, kind, self) self.children.append(node) return node class TypedTree(Tree[TypedNode]): + node_class = TypedNode + def __init__(self): self.root: TypedNode = TypedNode("__root__", "__root__", cast(TypedNode, None)) - def add(self, data: Any, kind: str) -> TNode: + def add(self, data: Any, kind: str) -> TypedNode: node = self.root.add(data, kind) return node diff --git a/tox.ini b/tox.ini index d632e32..25f92ad 100644 --- a/tox.ini +++ b/tox.ini @@ -29,6 +29,8 @@ deps = pytest-cov pytest-html rdflib + # py39: typing-extensions>=4.0 + # py310: typing-extensions>=4.0 setenv = COVERAGE_FILE=.coverage.{envname} ; allowlist_externals =