-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunittests.py
72 lines (48 loc) · 1.39 KB
/
unittests.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import sys
import unittest
from pystatictypes import typed
@typed
def test1(a:int, b:int) -> int:
return a + b
class Test1(unittest.TestCase):
def test_expected(self):
self.assertEqual(test1(1, 2), 3)
def test_wrong_type_arg1(self):
self.assertRaises(TypeError, test1, 'a', 2)
def test_too_few_args(self):
self.assertRaises(TypeError, test1, 'a')
def test_too_few_args(self):
self.assertRaises(TypeError, test1, 2)
def test_expected_kwargs(self):
self.assertEqual(test1(1, b=2), 3)
def test_unexpected_kwarg_val(self):
self.assertRaises(TypeError, test1, 1, b='a')
def test_unexpected_kwarg(self):
self.assertRaises(TypeError, test1, b=1, c=3)
def test_duplicate_vals(self):
self.assertRaises(TypeError, test1, 1, a=2)
def test2(a, b) ->int:
return a + b
class Test2(unittest.TestCase):
def test_no_param_annotation(self):
self.assertRaises(SyntaxError, typed, test2)
@typed
def test3(a:int, b:int) -> None:
pass
class Test3(unittest.TestCase):
def test_expected(self):
self.assertEqual(test3(1, 2), None)
class FooType:
def __init__(self, data):
self.data = data
def __eq__(self, other):
if type(other) == FooType:
return self.data == other.data
return self.data == other
@typed
def test4(a:int, b:int) -> FooType:
return FooType(max(a, b))
class Test4(unittest.TestCase):
def test_expected(self):
self.assertEqual(test4(4, 5), 5)
unittest.main()