-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Even better hook factories * Improve hook factory types * Test deque validation, for coverage * Enum coverage * Fix lint
- Loading branch information
Showing
8 changed files
with
179 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Tests for enums.""" | ||
from hypothesis import given | ||
from hypothesis.strategies import data, sampled_from | ||
from pytest import raises | ||
|
||
from cattrs import BaseConverter | ||
from cattrs._compat import Literal | ||
|
||
from .untyped import enums_of_primitives | ||
|
||
|
||
@given(data(), enums_of_primitives()) | ||
def test_structuring_enums(data, enum): | ||
"""Test structuring enums by their values.""" | ||
converter = BaseConverter() | ||
val = data.draw(sampled_from(list(enum))) | ||
|
||
assert converter.structure(val.value, enum) == val | ||
|
||
|
||
@given(enums_of_primitives()) | ||
def test_enum_failure(enum): | ||
"""Structuring literals with enums fails properly.""" | ||
converter = BaseConverter() | ||
type = Literal[next(iter(enum))] | ||
|
||
with raises(Exception) as exc_info: | ||
converter.structure("", type) | ||
|
||
assert exc_info.value.args[0] == f" not in literal {type!r}" |
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