forked from beeware/voc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_class.py
79 lines (58 loc) · 1.98 KB
/
test_class.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
73
74
75
76
77
78
79
from ..utils import TranspileTestCase
class ClassTests(TranspileTestCase):
def test_minimal(self):
self.assertCodeExecution("""
class MyClass:
pass
obj = MyClass()
print('Done.')
""", run_in_function=False)
def test_simple(self):
self.assertCodeExecution("""
class MyClass:
def __init__(self, val):
print("VAL: ", val)
self.value = val
def stuff(self, delta):
print("DELTA: ", delta)
return self.value + delta
obj = MyClass(4)
obj.stuff(5)
print('Done.')
""", run_in_function=False)
def test_method_override(self):
self.assertCodeExecution("""
class MyObject:
def __init__(self, x):
self.x = x
def __str__(self):
return "Myobject instance %s" % self.x
obj = MyObject(37)
print(obj)
print('Done.')
""", run_in_function=False)
def test_subclass(self):
self.assertCodeExecution("""
class MyBase:
def __init__(self, x):
self.x = x
def __str__(self):
return "Mybase instance %s" % self.x
def first(self):
return self.x * 2
class MyObject(MyBase):
def __init__(self, x, y):
super().__init__(x)
self.y = y
def __str__(self):
return "Myobject instance %s, %s" % (self.x, self.y)
def second(self):
return self.x * self.y
obj = MyObject(37, 42)
print(obj)
print(obj.x)
print(obj.first())
print(obj.y)
print(obj.second())
print('Done.')
""")