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
|
import dominate
from dominate.tags import *
from dominate import util
def test_context():
id1 = dominate.dom_tag._get_thread_context()
id2 = dominate.dom_tag._get_thread_context()
assert id1 == id2
def test_include():
import os
try:
f = open('_test_include.deleteme', 'w')
f.write('Hello World')
f.close()
d = div()
d += util.include('_test_include.deleteme')
assert d.render() == '<div>Hello World</div>'
finally:
try:
os.remove('_test_include.deleteme')
except:
pass
def test_system():
d = div()
d += util.system('echo Hello World')
assert d.render().replace('\r\n', '\n') == '<div>Hello World\n</div>'
def test_unescape():
assert util.unescape('&<> ') == '&<> '
def test_url():
assert util.url_escape('hi there?') == 'hi%20there%3F'
assert util.url_unescape('hi%20there%3f') == 'hi there?'
def test_container():
d = div()
with d:
with util.container():
pass
assert d.render() == '<div></div>'
d = div()
with d:
with util.container():
h1('a')
assert d.render() == \
'''<div>
<h1>a</h1>
</div>'''
|