diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 70880883..b59ea633 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -47,7 +47,7 @@ jobs: - name: Install Extras Package run: python3 -m pip install -e ./extras[test] - name: MyPy - run: mypy --install-types --non-interactive . + run: mypy --install-types --non-interactive --no-warn-unused-ignores . - name: Pytest run: pytest -vvs --cov fileformats --cov-config .coveragerc --cov-report xml . - name: Upload coverage to Codecov diff --git a/extras/fileformats/extras/application/tests/test_application_serialization.py b/extras/fileformats/extras/application/tests/test_application_serialization.py index 1a2cda43..1ac09a07 100644 --- a/extras/fileformats/extras/application/tests/test_application_serialization.py +++ b/extras/fileformats/extras/application/tests/test_application_serialization.py @@ -1,5 +1,5 @@ -import sys -import pytest +# import sys +# import pytest from fileformats.application import Json, Yaml @@ -28,10 +28,10 @@ """ -@pytest.mark.xfail( - sys.version_info.minor <= 9, - reason="upstream Pydra issue with type-checking 'type' objects", -) +# @pytest.mark.xfail( +# sys.version_info.minor <= 9, +# reason="upstream Pydra issue with type-checking 'type' objects", +# ) def test_json_to_yaml(work_dir): in_file = work_dir / "test.json" with open(in_file, "w") as f: @@ -41,10 +41,10 @@ def test_json_to_yaml(work_dir): assert yml.contents == SAMPLE_YAML -@pytest.mark.xfail( - sys.version_info.minor <= 9, - reason="upstream Pydra issue with type-checking 'type' objects", -) +# @pytest.mark.xfail( +# sys.version_info.minor <= 9, +# reason="upstream Pydra issue with type-checking 'type' objects", +# ) def test_yaml_to_json(work_dir): in_file = work_dir / "test.yaml" with open(in_file, "w") as f: diff --git a/extras/fileformats/extras/image/tests/test_image_converters.py b/extras/fileformats/extras/image/tests/test_image_converters.py index c6be18e4..2e85e345 100644 --- a/extras/fileformats/extras/image/tests/test_image_converters.py +++ b/extras/fileformats/extras/image/tests/test_image_converters.py @@ -1,4 +1,4 @@ -import sys +# import sys import pytest from imageio.core.fetching import get_remote_file from fileformats.image import Bitmap, Gif, Jpeg, Png, Tiff @@ -15,25 +15,25 @@ def png() -> Png: return Png(get_remote_file("images/chelsea.png")) -@pytest.mark.xfail( - sys.version_info.minor <= 9, - reason="upstream Pydra issue with type-checking 'type' objects", -) +# @pytest.mark.xfail( +# sys.version_info.minor <= 9, +# reason="upstream Pydra issue with type-checking 'type' objects", +# ) def test_jpg_to_gif(jpg): Gif.convert(jpg) -@pytest.mark.xfail( - sys.version_info.minor <= 9, - reason="upstream Pydra issue with type-checking 'type' objects", -) +# @pytest.mark.xfail( +# sys.version_info.minor <= 9, +# reason="upstream Pydra issue with type-checking 'type' objects", +# ) def test_png_to_tiff(png): Tiff.convert(png) -@pytest.mark.xfail( - sys.version_info.minor <= 9, - reason="upstream Pydra issue with type-checking 'type' objects", -) +# @pytest.mark.xfail( +# sys.version_info.minor <= 9, +# reason="upstream Pydra issue with type-checking 'type' objects", +# ) def test_png_to_bitmap(png): Bitmap.convert(png) diff --git a/fileformats/core/fileset.py b/fileformats/core/fileset.py index b18fe029..db8b78e8 100644 --- a/fileformats/core/fileset.py +++ b/fileformats/core/fileset.py @@ -1737,13 +1737,16 @@ def __init__( @classproperty def type_name(cls) -> str: - class_name: str = cls.__name__ # type: ignore - assert class_name.endswith("Mock") - return class_name[: -len("Mock")] + return cls.mocked.type_name def __bytes_repr__(self, cache: ty.Dict[str, ty.Any]) -> ty.Iterable[bytes]: yield from (str(fspath).encode() for fspath in self.fspaths) + @classproperty + def mocked(cls) -> FileSet: + """The "true" class that the mocked class is based on""" + return next(c for c in cls.__mro__ if not issubclass(c, MockMixin)) # type: ignore[no-any-return, attr-defined] + @classproperty def namespace(cls) -> str: """The "namespace" the format belongs to under the "fileformats" umbrella diff --git a/fileformats/core/tests/test_identification.py b/fileformats/core/tests/test_identification.py index dda8467c..56b4495c 100644 --- a/fileformats/core/tests/test_identification.py +++ b/fileformats/core/tests/test_identification.py @@ -1,6 +1,7 @@ from collections import Counter import itertools import typing as ty +from pathlib import Path import pytest from fileformats.core import ( find_matching, @@ -9,6 +10,7 @@ from_paths, FileSet, ) +from fileformats.generic import File, SetOf from fileformats.core.exceptions import FormatRecognitionError from fileformats.testing import Foo, Bar from fileformats.application import Json, Yaml, Zip @@ -64,6 +66,16 @@ def test_repr(): assert repr(frmt.mock("/a/path")).startswith(f"{frmt.__name__}(") +def test_set_repr_trunc(): + a = Path("/a/path").absolute() + b = Path("/b/path").absolute() + c = Path("/c/path").absolute() + d = Path("/d/path").absolute() + assert ( + repr(SetOf[File].mock(a, b, c, d)) == f"SetOf[File]('{a}', '{b}', '{c}', ...)" + ) + + def test_from_paths(tmp_path): filesets = [] filesets.append(Json.sample(tmp_path, seed=1)) diff --git a/fileformats/generic/set.py b/fileformats/generic/set.py index 74840869..c6c31941 100644 --- a/fileformats/generic/set.py +++ b/fileformats/generic/set.py @@ -13,6 +13,18 @@ class TypedSet(FileSet): content_types: ty.Tuple[ty.Type[FileSet], ...] = () + MAX_REPR_PATHS = 3 + + def __repr__(self) -> str: + paths_repr = ( + "'" + + "', '".join(str(p) for p in sorted(self.fspaths)[: self.MAX_REPR_PATHS]) + + "'" + ) + if len(self.fspaths) > self.MAX_REPR_PATHS: + paths_repr += ", ..." + return f"{self.type_name}({paths_repr})" + @cached_property def contents(self) -> ty.List[FileSet]: contnts = [] diff --git a/fileformats/generic/tests/test_file.py b/fileformats/generic/tests/test_file.py index da9ed8e4..73a182a4 100644 --- a/fileformats/generic/tests/test_file.py +++ b/fileformats/generic/tests/test_file.py @@ -1,6 +1,6 @@ import pytest from fileformats.generic import FsObject, File -from fileformats.testing import Magic, Foo, MyFormatX +from fileformats.testing import Magic, MagicVersion, Foo, MyFormatX def test_sample_fsobject(): @@ -27,4 +27,4 @@ def test_sample_magic(): reason="generate_sample_data for WithMagicVersion file types is not implemented yet" ) def test_sample_magic_version(): - assert isinstance(Magic.sample(), Magic) + assert isinstance(MagicVersion.sample(), MagicVersion)