Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/python-wasm
Path: blob/main/python/pylang/test/elementmaker_.py
1396 views
1
# vim:fileencoding=utf-8
2
# License: BSD Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
3
# globals: assrt
4
5
from elementmaker import E
6
7
eq = assrt.equal
8
9
10
def dummy_elem_eq(a, b):
11
eq(jstype(a), jstype(b))
12
if (jstype(a) == 'string'):
13
eq(a, b)
14
return
15
eq(a.attributes.length, b.attributes.length)
16
eq(a.children.length, b.children.length)
17
eq(a.name, b.name)
18
for attr in a.attributes:
19
eq(a[attr], b[attr])
20
for i, child in enumerate(a.children):
21
dummy_elem_eq(child, b.children[i])
22
23
24
q = E.div('text', id='1', class_='c', data_x='x')
25
dummy_elem_eq(
26
q, {
27
'name': 'div',
28
'children': ['text'],
29
'attributes': {
30
'id': '1',
31
'class': 'c',
32
'data-x': 'x'
33
}
34
})
35
36
q = E.div(
37
E.span('a'),
38
E.span('b'),
39
E.a(),
40
id='1',
41
boolean_attr=True,
42
)
43
dummy_elem_eq(
44
q, {
45
'name':
46
'div',
47
'children': [
48
{
49
'name': 'span',
50
'children': ['a'],
51
'attributes': {}
52
},
53
{
54
'name': 'span',
55
'children': ['b'],
56
'attributes': {}
57
},
58
{
59
'name': 'a',
60
'children': [],
61
'attributes': {}
62
},
63
],
64
'attributes': {
65
'id': '1',
66
'boolean-attr': 'boolean-attr'
67
}
68
})
69
70