diff --git a/fileformats/core/__init__.py b/fileformats/core/__init__.py index 9e64352..c3cf12a 100644 --- a/fileformats/core/__init__.py +++ b/fileformats/core/__init__.py @@ -1,7 +1,7 @@ from ._version import __version__ from .classifier import Classifier, ClassifierCategory from .datatype import DataType -from .fileset import FileSet +from .fileset import FileSet, MockMixin from .field import Field from .utils import ( to_mime, diff --git a/fileformats/core/hook.py b/fileformats/core/hook.py index ed9752c..1bf529a 100644 --- a/fileformats/core/hook.py +++ b/fileformats/core/hook.py @@ -199,13 +199,13 @@ def type_match(a, b) -> bool: ftype = fparam.annotation if mname != fname: differences.append( - f"Name of parameter at position {i}: {mname} vs {fname}" + f"name of parameter at position {i}: {mname} vs {fname}" ) elif not type_match(mtype, ftype): differences.append(f"Type of '{mname}' arg: {mtype} vs {ftype}") if not type_match(msig.return_annotation, fsig.return_annotation): differences.append( - f"Return type: {msig.return_annotation} vs {fsig.return_annotation}" + f"return type: {msig.return_annotation} vs {fsig.return_annotation}" ) if differences: raise TypeError( diff --git a/fileformats/core/tests/test_extras.py b/fileformats/core/tests/test_extras.py deleted file mode 100644 index eeae59c..0000000 --- a/fileformats/core/tests/test_extras.py +++ /dev/null @@ -1,25 +0,0 @@ -from pathlib import Path -import platform -from fileformats.core.fileset import MockMixin -from fileformats.testing import Foo - - -def test_sample(): - test_inst = Foo.sample() - assert test_inst.fspath.exists() - assert test_inst.fspath.suffix == ".foo" - - -def test_mock(): - mock = Foo.mock() - if platform.system() == "Windows": - expected = Path(f"{Path().cwd().drive}\\mock\\foo.foo") - else: - expected = Path("/mock/foo.foo") - assert mock.fspath == expected - assert not mock.fspath.exists() - assert isinstance(mock, MockMixin) - - -def test_extra_errors(): - pass diff --git a/fileformats/core/tests/test_hooks.py b/fileformats/core/tests/test_hooks.py new file mode 100644 index 0000000..3b18559 --- /dev/null +++ b/fileformats/core/tests/test_hooks.py @@ -0,0 +1,73 @@ +from pathlib import Path +import platform +import typing as ty +import pytest +from fileformats.core import hook, MockMixin, FileSet +from fileformats.testing import Foo + + +def test_sample(): + test_inst = Foo.sample() + assert test_inst.fspath.exists() + assert test_inst.fspath.suffix == ".foo" + + +def test_mock(): + mock = Foo.mock() + if platform.system() == "Windows": + expected = Path(f"{Path().cwd().drive}\\mock\\foo.foo") + else: + expected = Path("/mock/foo.foo") + assert mock.fspath == expected + assert not mock.fspath.exists() + assert isinstance(mock, MockMixin) + + +class Woo(FileSet): + @hook.extra + def test_hook(self, a: int, b: float, c: ty.Optional[str] = None) -> float: + raise NotImplementedError + + +def test_hook_signature_no_default(): + @Woo.test_hook.register + def woo_test_hook(woo: Woo, a: int, b: float) -> float: + pass + + +def test_hook_signature1(): + + with pytest.raises(TypeError, match="missing required argument"): + + @Woo.test_hook.register + def woo_test_hook(woo: Woo, a: int) -> float: + pass + + +def test_hook_signature2(): + + with pytest.raises(TypeError, match="name of parameter"): + + @Woo.test_hook.register + def woo_test_hook(woo: Woo, a: int, d: str) -> float: + pass + + +def test_hook_signature3(): + + with pytest.raises(TypeError, match="found additional argument"): + + @Woo.test_hook.register + def woo_test_hook( + woo: Woo, a: int, b: float, c: ty.Optional[str], d: int + ) -> float: + pass + + +def test_hook_signature4(): + + with pytest.raises(TypeError, match="return type"): + + @Woo.test_hook.register + def woo_test_hook(woo: Woo, a: int, b: str) -> int: + pass