|
1 | 1 | import unittest |
2 | 2 | import type_annotations |
3 | | -from typing import Union, Dict, List |
| 3 | +from typing import Union, Dict, List, TypeVar |
4 | 4 |
|
5 | 5 |
|
6 | 6 | class TestTypeAnnotations(unittest.TestCase): |
7 | 7 |
|
8 | | - def test_get_func_annotations_exception(self): |
| 8 | + def test_get_func_annotations_exceptions(self): |
9 | 9 |
|
10 | 10 | def foo(a: int, b, c: str = "string"): |
11 | 11 | pass |
12 | 12 | with self.assertRaises(SyntaxError) as raises: |
13 | 13 | type_annotations.get_func_annotations(foo) |
14 | | - self.assertIn('Not found annotation for parameter b', str(raises.exception)) |
| 14 | + self.assertIn('No annotation for parameter b', str(raises.exception)) |
15 | 15 |
|
16 | 16 | def test_get_cls_annotations(self): |
17 | 17 | class TestClass(object): |
@@ -46,6 +46,17 @@ def func_three(a: Dict[int, str], b: str = "string", c: int = 1): |
46 | 46 | with self.subTest(func=f.__name__): |
47 | 47 | self.assertEqual(type_annotations.get_func_annotations(f), expected) |
48 | 48 |
|
| 49 | + def test_expend_annotations(self): |
| 50 | + |
| 51 | + S = TypeVar('S', float, str) |
| 52 | + info = ({'a': [int], 'b': [int, float], 'c': [S]}, {}) |
| 53 | + result = type_annotations.expend_annotations(info) |
| 54 | + expected = [[{'a': int, 'b': int, 'c': float}, {}], |
| 55 | + [{'a': int, 'b': int, 'c': str}, {}], |
| 56 | + [{'a': int, 'b': float, 'c': float}, {}], |
| 57 | + [{'a': int, 'b': float, 'c': str}, {}]] |
| 58 | + self.assertEqual(result, expected) |
| 59 | + |
49 | 60 |
|
50 | 61 | if __name__ == '__main__': |
51 | 62 | unittest.main() |
0 commit comments