-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding tests #34
Adding tests #34
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4668,6 +4668,71 @@ class Foo(typing.Generic[T]): | |
def test_frozenset(self): | ||
self.assertTrue(pytypes.is_of_type(frozenset({1, 2, 'a', None, 'b'}), typing.AbstractSet[typing.Union[str, int, None]])) | ||
|
||
# See: https://github.com/Stewori/pytypes/issues/32 | ||
# See: https://github.com/Stewori/pytypes/issues/33 | ||
def test_empty_values(self): | ||
self.assertTrue(pytypes.is_of_type([], typing.Sequence)) | ||
self.assertTrue(pytypes.is_of_type([], typing.Sequence[int])) | ||
|
||
for interface in (typing.Iterable, typing.Sized, typing.Container): | ||
self.assertTrue(isinstance(set(), interface), interface) | ||
self.assertTrue(pytypes.is_of_type(set(), interface), interface) | ||
self.assertTrue(isinstance([], interface), interface) | ||
self.assertTrue(pytypes.is_of_type([], interface), interface) | ||
|
||
# See: https://github.com/Stewori/pytypes/issues/21 | ||
def test_tuple_ellipsis(self): | ||
class Foo: | ||
pass | ||
|
||
self.assertTrue(pytypes.is_subtype(typing.Tuple[Foo], typing.Tuple[object, ...])) | ||
self.assertTrue(pytypes.is_subtype(typing.Tuple[Foo], typing.Tuple[typing.Any, ...])) | ||
|
||
# See: https://github.com/Stewori/pytypes/issues/24 | ||
def test_bound_typevars_readonly(self): | ||
T = typing.TypeVar('T', covariant=True) | ||
|
||
class L(typing.List[T]): | ||
pass | ||
|
||
C = typing.TypeVar('T', bound=L) | ||
|
||
self.assertTrue(pytypes.is_subtype(L[float], C)) | ||
self.assertTrue(pytypes.is_subtype(L[float], C, bound_typevars={})) | ||
self.assertFalse(pytypes.is_subtype(L[float], C, bound_typevars_readonly=True, bound_typevars={})) | ||
self.assertTrue(pytypes.is_subtype(L[float], C, bound_typevars_readonly=False, bound_typevars={})) | ||
|
||
# See: https://github.com/Stewori/pytypes/issues/22 | ||
def test_forward_declaration(self): | ||
Wrapper = typing.Union[ | ||
typing.Sequence['Data'], | ||
] | ||
|
||
Data = typing.Union[ | ||
Wrapper, | ||
str, bytes, bool, float, int, dict, | ||
] | ||
|
||
with self.assertRaises(pytypes.ForwardRefError): | ||
pytypes.is_subtype(typing.Sequence[float], Wrapper) | ||
|
||
pytypes.resolve_fw_decl(Wrapper) | ||
|
||
self.assertTrue(pytypes.is_subtype(typing.Sequence[float], Wrapper)) | ||
self.assertTrue(pytypes.is_subtype(int, Data)) | ||
self.assertTrue(pytypes.is_subtype(float, Data)) | ||
self.assertFalse(pytypes.is_subtype(Data, Wrapper)) | ||
self.assertFalse(pytypes.is_subtype(Wrapper, Data)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. :-) I think I have no clue about typing anymore. ;-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry to hear that. Hope it doesn't stop you from helping to improve pytypes ;) |
||
|
||
# See: https://github.com/Stewori/pytypes/issues/22 | ||
def test_forward_declaration_infinite_recursion(self): | ||
Data = typing.Union['Wrapper', float] | ||
Wrapper = typing.Union[Data, int] | ||
|
||
pytypes.resolve_fw_decl(Data) | ||
|
||
self.assertFalse(pytypes.is_subtype(list, Wrapper)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.assertTrue(pytypes.is_subtype(typing.List[float], Wrapper)) should work as well, i.e. changing List to Sequence was not necessary here, only in declaration of Wrapper.