forked from limodou/uliweb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_html.py
More file actions
105 lines (99 loc) · 2.94 KB
/
test_html.py
File metadata and controls
105 lines (99 loc) · 2.94 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
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
99
100
101
102
103
104
105
#coding=utf-8
from uliweb.core.js import simple_value, json_dumps
from uliweb.core.html import *
from uliweb.core.html import to_attrs
def test_simple_value():
"""
>>> simple_value(1)
1
>>> simple_value('abc')
'abc'
>>> import datetime
>>> d = datetime.datetime(2010, 10, 25)
>>> simple_value(d)
'2010-10-25 00:00:00'
>>> import decimal
>>> d = decimal.Decimal('10.2')
>>> simple_value(d)
'10.2'
>>> def call():
... return 'bbb'
>>> simple_value(call)
'bbb'
"""
def testto_attrs():
"""
>>> print to_attrs({'name':'title'})
name="title"
>>> print to_attrs({'_class':'color', 'id':'title'})
class="color" id="title"
>>> print to_attrs({'_class':'color', 'id':None})
class="color"
>>> print to_attrs({'_class':'color', 'checked':None})
class="color" checked
>>> print to_attrs({'_class':'color', '_for':None})
class="color"
>>> print to_attrs({'action': '', '_class': 'yform', 'method': 'POST'})
class="yform" action="" method="POST"
>>> print to_attrs({'action': '"hello"'})
action=""hello""
>>> print to_attrs({'action': ''})
action=""
"""
def test_json_dumps():
"""
>>> import datetime
>>> a = {'name':u'limodou', 'date':datetime.datetime(2010, 10, 25), 'data':{'name':'aaa', 'total': 100, 'has':True}}
>>> json_dumps(a)
'{"date":"2010-10-25 00:00:00","data":{"has":true,"total":100,"name":"aaa"},"name":"limodou"}'
"""
def test_tag():
"""
>>> print Tag('a', 'Link', href='#')
<a href="#">Link</a>
>>> print Tag('a', 'Link', href='http://localhost:8000?a=b&c=d')
<a href="http://localhost:8000?a=b&c=d">Link</a>
>>> print Tag('p', 'Hello', attrs={'data-link':'ok'}, newline=False)
<p data-link="ok">Hello</p>
>>> html = Buf()
>>> with html.html:
... with html.head:
... html.title('Test')
>>> print html
<html>
<head>
<title>Test</title>
</head>
</html>
<BLANKLINE>
>>> div_group = Tag('div', _class='div', newline=True)
>>> with div_group:
... div_group << Tag('label', 'Hello')
>>> print div_group
<div class="div">
<label>Hello</label>
</div>
<BLANKLINE>
>>> div = Tag('div', newline=True)
>>> with div:
... div.span('test', attrs={'data-target':"Hello"})
>>> print div
<div>
<span data-target="Hello">test</span>
</div>
<BLANKLINE>
"""
def test_other():
"""
>>> print Div('Test', _class='data-group')
<div class="data-group">
Test
</div>
<BLANKLINE>
"""
#if __name__ == '__main__':
# import datetime
# a = {'name':u'中文', 'date':datetime.datetime(2010, 10, 25), 'data':{'name':'aaa', 'total': 100, 'has':True}}
# print json_dumps(a)
# print json_dumps(a, indent=4)
#