| Total Complexity | 9 | 
| Total Lines | 57 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
| 1 | import sys | ||
| 2 | from typing import Type | ||
| 3 | from unittest import TestCase | ||
| 4 | |||
| 5 | from typish import hintable, T | ||
| 6 | |||
| 7 | if sys.version_info.major * 10 + sys.version_info.minor > 35: | ||
| 8 | # All Python 3.5+ specific tests are moved to a separate module. | ||
| 9 | from test_resources.hintable import TestHintable as Base | ||
| 10 | else: | ||
| 11 | Base = TestCase | ||
| 12 | |||
| 13 | |||
| 14 | @hintable | ||
| 15 | def some_func(hint: Type[T]) -> Type[T]: | ||
| 16 | """Some docstring""" | ||
| 17 | return hint | ||
| 18 | |||
| 19 | |||
| 20 | class TestHintable(Base): | ||
| 21 | def test_hintable_without_any_hint(self): | ||
| 22 | # Test that when a hintable function is called without hint, it | ||
| 23 | # receives None. | ||
| 24 | |||
| 25 | x = some_func() | ||
| 26 | |||
| 27 | self.assertEqual(None, x) | ||
| 28 | |||
| 29 | def test_hintable_class(self): | ||
| 30 | # Test that decorating a class raises an error. | ||
| 31 | |||
| 32 | with self.assertRaises(TypeError): | ||
| 33 | @hintable | ||
| 34 | class DecoratedClass: | ||
| 35 | ... | ||
| 36 | |||
| 37 | def test_meta_data(self): | ||
| 38 | # Test that any meta data is copied properly. | ||
| 39 | |||
| 40 |         self.assertEqual('Some docstring', some_func.__doc__) | ||
| 41 | |||
| 42 | def test_hintable_with_flawed_function(self): | ||
| 43 | |||
| 44 | with self.assertRaises(TypeError): | ||
| 45 | @hintable | ||
| 46 | def some_flawed_func(): | ||
| 47 | ... | ||
| 48 | |||
| 49 | def test_hintable_with_flawed_custom_param_name(self): | ||
| 50 | # Test that when a custom param name is used, it is checked if a | ||
| 51 | # parameter with that name is accepted by the decorated function. | ||
| 52 | |||
| 53 | with self.assertRaises(TypeError): | ||
| 54 | @hintable(param='cls') | ||
| 55 | def some_func_with_flawed_custom_param_name(hint): | ||
| 56 | return hint | ||
| 57 |