-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_etree.py
67 lines (60 loc) · 2.2 KB
/
test_etree.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
# vim: set et sw=4 sts=4:
# Copyright 2012 Dave Hughes.
#
# This file is part of dbsuite.
#
# dbsuite is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# dbsuite is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# dbsuite. If not, see <http://www.gnu.org/licenses/>.
from __future__ import (
unicode_literals,
print_function,
absolute_import,
division,
)
from dbsuite.etree import ElementFactory, iselement
def test_element():
tag = ElementFactory()
test_tag = tag.a()
assert iselement(test_tag)
assert test_tag.tag == 'a'
assert len(test_tag.attrib) == 0
def test_attributes():
tag = ElementFactory()
test_tag = tag.a(foo='a', bar=1, baz=True, quux=False, xyzzy=None, class_='test')
assert len(test_tag.attrib) == 4
assert test_tag.attrib['foo'] == 'a'
assert test_tag.attrib['bar'] == '1'
assert test_tag.attrib['baz'] != ''
assert test_tag.attrib['class'] == 'test'
assert 'quux' not in test_tag.attrib
assert 'xyzzy' not in test_tag.attrib
def test_content():
tag = ElementFactory()
test_doc = tag.a('quux', tag.b('foo'), 'bar', tag.c(tag.d(), 'baz'), 'xyzzy')
assert len(test_doc) == 2
assert test_doc.text == 'quux'
assert not test_doc.tail
assert test_doc[0].tag == 'b'
assert test_doc[0].text == 'foo'
assert test_doc[0].tail == 'bar'
assert test_doc[1].tag == 'c'
assert test_doc[1].text == 'baz' or test_doc[1][0].tail == 'baz'
assert test_doc[1].tail == 'xyzzy'
assert len(test_doc[1]) == 1
assert test_doc[1][0].tag == 'd'
assert not test_doc[1][0].text
assert len(test_doc[1][0]) == 0
def test_namespaces():
tag = ElementFactory(namespace='foo')
test_tag = tag.a(bar=True)
assert test_tag.tag == '{foo}a'
assert '{foo}bar' in test_tag.attrib