-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Base coverage for constraints engine.
- Loading branch information
1 parent
b53835b
commit 96100d8
Showing
9 changed files
with
584 additions
and
21 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,50 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
from typical import constraints | ||
|
||
|
||
def test_constrained_new(): | ||
# Given | ||
@constraints.constrained(max_length=10) | ||
class ShortStr(str): | ||
... | ||
|
||
# When/Then | ||
with pytest.raises(constraints.error.ConstraintValueError): | ||
ShortStr("1234567891011") | ||
|
||
|
||
def test_constrained_init(): | ||
# Given | ||
@constraints.constrained(max_items=1) | ||
class SmallMap(dict): | ||
... | ||
|
||
# When/Then | ||
with pytest.raises(constraints.error.ConstraintValueError): | ||
SmallMap({"foo": 1, "bar": 2}) | ||
|
||
|
||
def test_constrained_builtin(): | ||
# Given | ||
ShortStr = constraints.constrained(str, max_length=10) | ||
# When/Then | ||
with pytest.raises(constraints.error.ConstraintValueError): | ||
ShortStr("1234567891011") | ||
|
||
|
||
def test_nested_constraints(): | ||
# Given | ||
@constraints.constrained(max_length=10) | ||
class ShortStr(str): | ||
... | ||
|
||
@constraints.constrained(max_items=1, values=ShortStr, keys=ShortStr) | ||
class SmallMap(dict): | ||
... | ||
|
||
# When/Then | ||
with pytest.raises(constraints.error.ConstraintValueError): | ||
SmallMap({"foo": 1}) |
Oops, something went wrong.