-
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.
- Loading branch information
1 parent
36a522a
commit e0a1958
Showing
3 changed files
with
72 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
Test attrs_helpers module | ||
""" | ||
import re | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
|
||
from pydoit_nb.attrs_helpers import AttributeInitialisationError, make_attrs_validator_compatible_single_input | ||
|
||
|
||
def test_make_attrs_validator_compatible_single_input(): | ||
def func(inp: str) -> None: | ||
if inp != "hi": | ||
raise ValueError(f"inp must be hi, received: {inp}") | ||
|
||
wrapped = make_attrs_validator_compatible_single_input(func) | ||
|
||
instance = Mock() | ||
attribute = Mock() | ||
attribute.name = "attribute_name" | ||
# No error | ||
wrapped(instance, attribute, "hi") | ||
|
||
# Error | ||
error_msg = re.escape( | ||
"Error raised while initialising attribute " | ||
f"``attribute_name`` of ``{type(instance)}``. " | ||
"Value provided: bye" | ||
) | ||
with pytest.raises(AttributeInitialisationError, match=error_msg) as exc: | ||
wrapped(instance, attribute, "bye") | ||
|
||
assert isinstance(exc.value.__cause__, ValueError) | ||
assert str(exc.value.__cause__) == "inp must be hi, received: bye" |