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
Maxim Avanov
committed
May 8, 2020
1 parent
a73b73b
commit 968a88a
Showing
2 changed files
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from typing import NamedTuple | ||
|
||
import pytest | ||
|
||
from typeit import TypeConstructor, flags, Error | ||
|
||
|
||
def test_bytes(): | ||
class X(NamedTuple): | ||
x: bytes | ||
|
||
non_strict_mk_x, non_strict_dict_x = TypeConstructor & flags.NonStrictPrimitives ^ X | ||
strict_mk_x, strict_dict_x = TypeConstructor ^ X | ||
|
||
data = {'x': 'abc'} | ||
x = non_strict_mk_x(data) | ||
assert x.x == b'abc' | ||
|
||
with pytest.raises(Error): | ||
strict_mk_x(data) | ||
|
||
data_strict = {'x': b'abc'} | ||
x_non_strict = non_strict_mk_x(data_strict) | ||
x_strict = strict_mk_x(data_strict) | ||
assert x_non_strict == x_strict | ||
|
||
assert non_strict_dict_x(x_strict) == strict_dict_x(x_non_strict) == {'x': b'abc'} |
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