-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_misc.py
More file actions
61 lines (47 loc) · 1.2 KB
/
test_misc.py
File metadata and controls
61 lines (47 loc) · 1.2 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
50
51
52
53
54
55
56
57
58
59
60
61
import unittest
from writeYourProgram import *
from typing import *
setDieOnCheckFailures(True)
ty = ForwardRef('Name')
@record
class Name:
firstName: str
lastName: str
@record
class Point:
x: float
y: float
PointOrFloat = Union[Point, float]
WithNone = Union[str, None]
class C:
pass
def abcGenerator():
yield("a")
yield("b")
yield("c")
class TestMisc(unittest.TestCase):
def test_types(self):
# just check that the types are defined
Mapping
dict
dict[str, int]
myName = Name("Stefan", "Wehr")
list[Name] # just use it
list[ty] # just use it
list[ForwardRef('foo')] # just use
list[PointOrFloat]
def test_math(self):
# just check that the functions are defined
math.sqrt(2)
math.sin(2)
def assertTypeError(self, thunk, msg):
try:
thunk()
self.fail("no type error")
except TypeError as e:
self.assertEqual(str(e), msg)
def test_checkEq(self):
check(1.0000000000000001, 1)
def test_typechking(self):
self.assertTypeError(lambda : ForwardRef(1),
'Forward reference must be a string -- got 1')