-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #45 Signed-off-by: David Euresti <david@pilot.com>
- Loading branch information
1 parent
2a93324
commit 23b6e05
Showing
5 changed files
with
106 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import sys | ||
|
||
|
||
def pytest_ignore_collect(path): | ||
return sys.version_info[0] <= 2 and str(path).endswith("__py3.py") |
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,54 @@ | ||
from typing import Optional | ||
|
||
import attr | ||
import pytest | ||
|
||
from attrs_strict import type_validator | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"type_, good_value, bad_value", | ||
[(str, "str", 0xBAD), (int, 7, "bad"), (Optional[str], None, 0xBAD)], | ||
) | ||
def test_real_types(type_, good_value, bad_value): | ||
@attr.s(auto_attribs=True) | ||
class Something: | ||
value: type_ = attr.ib(validator=type_validator()) | ||
|
||
with pytest.raises(ValueError): | ||
Something(bad_value) | ||
|
||
x = Something(good_value) | ||
with pytest.raises(ValueError): | ||
x.value = bad_value | ||
attr.validate(x) | ||
|
||
|
||
@attr.s(auto_attribs=True) | ||
class Child: | ||
parent: "Parent" = attr.ib(validator=type_validator()) | ||
|
||
|
||
@attr.s(auto_attribs=True) | ||
class Parent: | ||
pass | ||
|
||
|
||
def test_forward_ref(): | ||
Child(Parent()) | ||
|
||
with pytest.raises(ValueError): | ||
Child(15) | ||
|
||
|
||
@attr.s(auto_attribs=True) | ||
class Self: | ||
parent: Optional["Self"] = attr.ib(None, validator=type_validator()) | ||
|
||
|
||
def test_recursive(): | ||
Self(Self()) | ||
Self(Self(None)) | ||
|
||
with pytest.raises(ValueError): | ||
Self(Self(17)) |
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