-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_constructors.py
99 lines (65 loc) · 2.88 KB
/
test_constructors.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from htag import Tag
import pytest
#####################################################################################
# test base
#####################################################################################
def test_basic_creation(): # auto init (property/html_attributes) in all cases
# test base constructor
t=Tag.div("hello",param1=12,_param2=13)
assert t.param1 == 12
assert t["param2"] == 13
class MyDiv(Tag.div):
pass
def test_basic_inherited_creation(): # auto init (property/html_attributes) in all cases
# test Tag simple inherits (no constructor)
t=MyDiv("hello",param1=12,_param2=13)
assert t.param1 == 12
assert t["param2"] == 13
#####################################################################################
# test Tag constructor with real/python __init__() method
#####################################################################################
#############################################
## with real __init__() constructor
#############################################
class MyRDivOpen(Tag.div): # accept auto set property/html_attributes
def __init__(self,content,**a):
Tag.div.__init__(self,content,**a)
class MyRDivClosed(Tag.div): # DONT't accept auto set property/html_attributes
def __init__(self,content):
Tag.div.__init__(self,content)
def test_real_inherited_creation():
# test Tag inherited with __init__() constructor
t=MyRDivOpen("hi",param1=12,_param2=13)
assert t.param1 == 12
assert t["param2"] == 13
t=MyRDivOpen(content="hi",param1=12,_param2=13)
assert t.param1 == 12
assert t["param2"] == 13
with pytest.raises(TypeError):
MyRDivClosed("hi",param1=12)
with pytest.raises(TypeError):
MyRDivClosed("hi",_param2=13)
#####################################################################################
# test Tag constructor with simplified init() method
#####################################################################################
#############################################
## with simplified init() constructor
#############################################
class MyDivOpen(Tag.div): # accept auto set property/html_attributes
def init(self,content,**a): # <- **a
self <= content
class MyDivClosed(Tag.div): # DONT't accept auto set property/html_attributes
def init(self,content): # no **a !
self <= content
def test_simplified_inherited_creation():
# test Tag inherited with init() constructor
t=MyDivOpen("hi",param1=12,_param2=13)
assert t.param1 == 12
assert t["param2"] == 13
t=MyDivOpen(content="hi",param1=12,_param2=13)
assert t.param1 == 12
assert t["param2"] == 13
with pytest.raises(TypeError):
MyDivClosed("hi",param1=12)
with pytest.raises(TypeError):
MyDivClosed("hi",_param2=13)