This repository was archived by the owner on Feb 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_jeni_python3.py
More file actions
49 lines (35 loc) · 1.38 KB
/
test_jeni_python3.py
File metadata and controls
49 lines (35 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import unittest
import jeni
from test_jeni import BasicInjector
class Python3AnnotationTestCase(unittest.TestCase):
def test_annotate_without_annotations(self):
def fn(hello):
"unused"
jeni.annotate(fn)
self.assertTrue(jeni.annotate.has_annotations(fn))
def test_annotate_without_dunder_annotations(self):
# Unclear when this would come up; testing it given Python 2 support.
class NoDunderAnnotations(object):
def __getattr__(self, name):
if name == '__annotations__':
raise AttributeError()
return super().__getattr__(name)
def __call__(self):
"unused"
fn = NoDunderAnnotations()
self.assertTrue(hasattr(fn, '__call__'))
self.assertFalse(hasattr(fn, '__annotations__'))
self.assertFalse(hasattr(fn, 'fake')) # coverage
with self.assertRaises(AttributeError):
jeni.annotate(fn)
@jeni.annotate
def annotated_function(hello: 'hello:thing', eggs: 'eggs'):
return hello, eggs
class FunctionAnnotationTestCase(unittest.TestCase):
def setUp(self):
self.injector = BasicInjector()
def test_function_annotation(self):
self.assertEqual(
('Hello, thing!', 'eggs!'),
self.injector.apply(annotated_function))
if __name__ == '__main__': unittest.main()