-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from ArcanaFramework/develop
added protection against varying the signature of overriden extras hooks
- Loading branch information
Showing
9 changed files
with
169 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters