annotate emeraldtree/tests/test_html.py @ 73:641657361783

Tests for HTML support - Fix invocation, add tests for ouput
author Bastian Blank <bblank@thinkmo.de>
date Fri, 04 Jun 2010 13:02:19 +0200
parents d7e235461c97
children 223789ea05b2
rev   line source
51
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
1 import py.test
68
d7e235461c97 HTML Support - Change imports to internal names
Bastian Blank <bblank@thinkmo.de>
parents: 52
diff changeset
2
d7e235461c97 HTML Support - Change imports to internal names
Bastian Blank <bblank@thinkmo.de>
parents: 52
diff changeset
3 from .. import html, tree
51
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
4
73
641657361783 Tests for HTML support - Fix invocation, add tests for ouput
Bastian Blank <bblank@thinkmo.de>
parents: 68
diff changeset
5 def serialize(elem):
641657361783 Tests for HTML support - Fix invocation, add tests for ouput
Bastian Blank <bblank@thinkmo.de>
parents: 68
diff changeset
6 from StringIO import StringIO
51
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
7 file = StringIO()
73
641657361783 Tests for HTML support - Fix invocation, add tests for ouput
Bastian Blank <bblank@thinkmo.de>
parents: 68
diff changeset
8 elem.write(file.write, method='html')
51
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
9 return file.getvalue()
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
10
73
641657361783 Tests for HTML support - Fix invocation, add tests for ouput
Bastian Blank <bblank@thinkmo.de>
parents: 68
diff changeset
11 def test_read_simple1():
68
d7e235461c97 HTML Support - Change imports to internal names
Bastian Blank <bblank@thinkmo.de>
parents: 52
diff changeset
12 elem = html.HTML('<a></a>')
51
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
13 assert elem.tag.name == 'a'
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
14 assert len(elem) == 0
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
15
73
641657361783 Tests for HTML support - Fix invocation, add tests for ouput
Bastian Blank <bblank@thinkmo.de>
parents: 68
diff changeset
16 def test_read_simple2():
68
d7e235461c97 HTML Support - Change imports to internal names
Bastian Blank <bblank@thinkmo.de>
parents: 52
diff changeset
17 elem = html.HTML('<a><b /></a>')
51
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
18 assert elem.tag.name == 'a'
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
19 assert len(elem) == 1
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
20 assert elem[0].tag.name == 'b'
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
21 assert len(elem[0]) == 0
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
22
73
641657361783 Tests for HTML support - Fix invocation, add tests for ouput
Bastian Blank <bblank@thinkmo.de>
parents: 68
diff changeset
23 def test_read_text1():
68
d7e235461c97 HTML Support - Change imports to internal names
Bastian Blank <bblank@thinkmo.de>
parents: 52
diff changeset
24 elem = html.HTML('<a>b</a>')
51
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
25 assert elem.tag.name == 'a'
68
d7e235461c97 HTML Support - Change imports to internal names
Bastian Blank <bblank@thinkmo.de>
parents: 52
diff changeset
26 assert isinstance(elem, tree.Element)
51
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
27 assert len(elem) == 1
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
28 assert elem[0] == 'b'
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
29 assert isinstance(elem[0], unicode)
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
30
73
641657361783 Tests for HTML support - Fix invocation, add tests for ouput
Bastian Blank <bblank@thinkmo.de>
parents: 68
diff changeset
31 def test_read_text2():
68
d7e235461c97 HTML Support - Change imports to internal names
Bastian Blank <bblank@thinkmo.de>
parents: 52
diff changeset
32 elem = html.HTML('<a>b<c>d</c>d</a>')
51
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
33 assert elem.tag.name == 'a'
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
34 assert len(elem) == 3
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
35 assert elem[0] == 'b'
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
36 assert elem[1].tag.name == 'c'
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
37 assert elem[2] == 'd'
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
38
73
641657361783 Tests for HTML support - Fix invocation, add tests for ouput
Bastian Blank <bblank@thinkmo.de>
parents: 68
diff changeset
39 def test_read_ignoreend():
68
d7e235461c97 HTML Support - Change imports to internal names
Bastian Blank <bblank@thinkmo.de>
parents: 52
diff changeset
40 elem = html.HTML('<br>')
51
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
41 assert elem.tag.name == 'br'
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
42 assert len(elem) == 0
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
43
68
d7e235461c97 HTML Support - Change imports to internal names
Bastian Blank <bblank@thinkmo.de>
parents: 52
diff changeset
44 elem = html.HTML('<br></br>')
51
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
45 assert elem.tag.name == 'br'
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
46 assert len(elem) == 0
847897e5fab8 HTMLTreeBuilder - Make namespace aware, add testcases
Bastian Blank <bblank@thinkmo.de>
parents:
diff changeset
47
73
641657361783 Tests for HTML support - Fix invocation, add tests for ouput
Bastian Blank <bblank@thinkmo.de>
parents: 68
diff changeset
48 def test_write():
641657361783 Tests for HTML support - Fix invocation, add tests for ouput
Bastian Blank <bblank@thinkmo.de>
parents: 68
diff changeset
49 elem = html.HTML(u'<br>')
641657361783 Tests for HTML support - Fix invocation, add tests for ouput
Bastian Blank <bblank@thinkmo.de>
parents: 68
diff changeset
50 assert serialize(elem) == u'<br>'