annotate genshi/filters/tests/transform.py @ 916:872726bac135 experimental-py3k

add support for python 3 to genshi.filters: * minor changes to track encoding=None API change in core genshi modules. * renamed genshi/filters/tests/html.py to test_html.py to avoid clashes with Python 3 top-level html module when running tests subset. * did not rename genshi/filters/html.py. * i18n filters: * ugettext and friends are gone in Python 3 (and only gettext and friends exist and they now handle unicode) * Some \ line continuations inside doctests confused 2to3 and so were removed them. * Testing picked up a problem (already present in trunk) where Translator.__call__ could end up defining gettext as an endlessly recursive function. Noted with a TODO.
author hodgestar
date Sun, 24 Oct 2010 22:21:28 +0000
parents 24733a5854d9
children
rev   line source
501
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
2 #
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
3 # Copyright (C) 2007 Edgewall Software
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
4 # All rights reserved.
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
5 #
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
8 # are also available at http://genshi.edgewall.org/wiki/License.
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
9 #
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
12 # history and logs, available at http://genshi.edgewall.org/log/.
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
13
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
14 import doctest
744
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
15 from pprint import pprint
501
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
16 import unittest
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
17
744
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
18 from genshi import HTML
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
19 from genshi.builder import Element
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
20 from genshi.core import START, END, TEXT, QName, Attrs
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
21 from genshi.filters.transform import Transformer, StreamBuffer, ENTER, EXIT, \
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
22 OUTSIDE, INSIDE, ATTR, BREAK
501
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
23 import genshi.filters.transform
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
24
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
25
744
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
26 FOO = '<root>ROOT<foo name="foo">FOO</foo></root>'
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
27 FOOBAR = '<root>ROOT<foo name="foo" size="100">FOO</foo><bar name="bar">BAR</bar></root>'
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
28
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
29
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
30 def _simplify(stream, with_attrs=False):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
31 """Simplify a marked stream."""
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
32 def _generate():
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
33 for mark, (kind, data, pos) in stream:
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
34 if kind is START:
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
35 if with_attrs:
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
36 data = (unicode(data[0]), dict((unicode(k), v)
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
37 for k, v in data[1]))
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
38 else:
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
39 data = unicode(data[0])
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
40 elif kind is END:
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
41 data = unicode(data)
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
42 elif kind is ATTR:
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
43 kind = ATTR
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
44 data = dict((unicode(k), v) for k, v in data[1])
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
45 yield mark, kind, data
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
46 return list(_generate())
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
47
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
48
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
49 def _transform(html, transformer, with_attrs=False):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
50 """Apply transformation returning simplified marked stream."""
916
872726bac135 add support for python 3 to genshi.filters:
hodgestar
parents: 857
diff changeset
51 if isinstance(html, basestring) and not isinstance(html, unicode):
872726bac135 add support for python 3 to genshi.filters:
hodgestar
parents: 857
diff changeset
52 html = HTML(html, encoding='utf-8')
872726bac135 add support for python 3 to genshi.filters:
hodgestar
parents: 857
diff changeset
53 elif isinstance(html, unicode):
872726bac135 add support for python 3 to genshi.filters:
hodgestar
parents: 857
diff changeset
54 html = HTML(html, encoding='utf-8')
744
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
55 stream = transformer(html, keep_marks=True)
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
56 return _simplify(stream, with_attrs)
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
57
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
58
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
59 class SelectTest(unittest.TestCase):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
60 """Test .select()"""
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
61 def _select(self, select):
916
872726bac135 add support for python 3 to genshi.filters:
hodgestar
parents: 857
diff changeset
62 html = HTML(FOOBAR, encoding='utf-8')
744
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
63 if isinstance(select, basestring):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
64 select = [select]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
65 transformer = Transformer(select[0])
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
66 for sel in select[1:]:
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
67 transformer = transformer.select(sel)
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
68 return _transform(html, transformer)
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
69
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
70 def test_select_single_element(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
71 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
72 self._select('foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
73 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
74 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
75 (ENTER, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
76 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
77 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
78 (None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
79 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
80 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
81 (None, END, u'root')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
82 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
83
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
84 def test_select_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
85 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
86 self._select('.'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
87 [(ENTER, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
88 (INSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
89 (INSIDE, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
90 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
91 (INSIDE, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
92 (INSIDE, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
93 (INSIDE, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
94 (INSIDE, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
95 (EXIT, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
96 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
97
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
98 def test_select_inside_select(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
99 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
100 self._select(['.', 'foo']),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
101 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
102 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
103 (ENTER, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
104 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
105 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
106 (None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
107 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
108 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
109 (None, END, u'root')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
110 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
111
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
112 def test_select_text(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
113 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
114 self._select('*/text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
115 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
116 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
117 (None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
118 (OUTSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
119 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
120 (None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
121 (OUTSIDE, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
122 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
123 (None, END, u'root')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
124 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
125
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
126 def test_select_attr(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
127 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
128 self._select('foo/@name'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
129 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
130 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
131 (ATTR, ATTR, {'name': u'foo'}),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
132 (None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
133 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
134 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
135 (None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
136 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
137 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
138 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
139 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
140
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
141 def test_select_text_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
142 self.assertEqual(
916
872726bac135 add support for python 3 to genshi.filters:
hodgestar
parents: 857
diff changeset
143 list(Transformer('.')(HTML(u'foo'), keep_marks=True)),
744
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
144 [('OUTSIDE', ('TEXT', u'foo', (None, 1, 0)))],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
145 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
146
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
147
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
148 class InvertTest(unittest.TestCase):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
149 def _invert(self, select):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
150 return _transform(FOO, Transformer(select).invert())
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
151
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
152 def test_invert_element(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
153 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
154 self._invert('foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
155 [(OUTSIDE, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
156 (OUTSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
157 (None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
158 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
159 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
160 (OUTSIDE, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
161 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
162
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
163 def test_invert_inverted_element(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
164 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
165 _transform(FOO, Transformer('foo').invert().invert()),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
166 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
167 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
168 (OUTSIDE, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
169 (OUTSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
170 (OUTSIDE, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
171 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
172 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
173
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
174 def test_invert_text(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
175 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
176 self._invert('foo/text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
177 [(OUTSIDE, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
178 (OUTSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
179 (OUTSIDE, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
180 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
181 (OUTSIDE, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
182 (OUTSIDE, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
183 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
184
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
185 def test_invert_attribute(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
186 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
187 self._invert('foo/@name'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
188 [(OUTSIDE, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
189 (OUTSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
190 (None, ATTR, {'name': u'foo'}),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
191 (OUTSIDE, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
192 (OUTSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
193 (OUTSIDE, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
194 (OUTSIDE, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
195 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
196
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
197 def test_invert_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
198 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
199 self._invert('.'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
200 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
201 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
202 (None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
203 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
204 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
205 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
206 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
207
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
208 def test_invert_text_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
209 self.assertEqual(
916
872726bac135 add support for python 3 to genshi.filters:
hodgestar
parents: 857
diff changeset
210 _simplify(Transformer('.').invert()(HTML(u'foo'), keep_marks=True)),
744
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
211 [(None, 'TEXT', u'foo')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
212 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
213
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
214
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
215
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
216 class EndTest(unittest.TestCase):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
217 def test_end(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
218 stream = _transform(FOO, Transformer('foo').end())
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
219 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
220 stream,
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
221 [(OUTSIDE, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
222 (OUTSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
223 (OUTSIDE, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
224 (OUTSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
225 (OUTSIDE, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
226 (OUTSIDE, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
227 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
228
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
229
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
230 class EmptyTest(unittest.TestCase):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
231 def _empty(self, select):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
232 return _transform(FOO, Transformer(select).empty())
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
233
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
234 def test_empty_element(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
235 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
236 self._empty('foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
237 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
238 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
239 (ENTER, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
240 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
241 (None, END, u'root')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
242 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
243
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
244 def test_empty_text(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
245 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
246 self._empty('foo/text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
247 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
248 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
249 (None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
250 (OUTSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
251 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
252 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
253 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
254
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
255 def test_empty_attr(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
256 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
257 self._empty('foo/@name'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
258 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
259 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
260 (ATTR, ATTR, {'name': u'foo'}),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
261 (None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
262 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
263 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
264 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
265 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
266
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
267 def test_empty_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
268 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
269 self._empty('.'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
270 [(ENTER, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
271 (EXIT, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
272 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
273
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
274 def test_empty_text_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
275 self.assertEqual(
916
872726bac135 add support for python 3 to genshi.filters:
hodgestar
parents: 857
diff changeset
276 _simplify(Transformer('.')(HTML(u'foo'), keep_marks=True)),
744
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
277 [(OUTSIDE, TEXT, u'foo')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
278 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
279
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
280
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
281 class RemoveTest(unittest.TestCase):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
282 def _remove(self, select):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
283 return _transform(FOO, Transformer(select).remove())
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
284
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
285 def test_remove_element(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
286 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
287 self._remove('foo|bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
288 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
289 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
290 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
291 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
292
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
293 def test_remove_text(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
294 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
295 self._remove('//text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
296 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
297 (None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
298 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
299 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
300 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
301
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
302 def test_remove_attr(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
303 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
304 self._remove('foo/@name'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
305 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
306 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
307 (None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
308 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
309 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
310 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
311 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
312
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
313 def test_remove_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
314 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
315 self._remove('.'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
316 [],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
317 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
318
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
319 def test_remove_text_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
320 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
321 _transform('foo', Transformer('.').remove()),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
322 [],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
323 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
324
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
325
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
326 class UnwrapText(unittest.TestCase):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
327 def _unwrap(self, select):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
328 return _transform(FOO, Transformer(select).unwrap())
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
329
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
330 def test_unwrap_element(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
331 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
332 self._unwrap('foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
333 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
334 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
335 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
336 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
337 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
338
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
339 def test_unwrap_text(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
340 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
341 self._unwrap('foo/text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
342 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
343 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
344 (None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
345 (OUTSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
346 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
347 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
348 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
349
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
350 def test_unwrap_attr(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
351 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
352 self._unwrap('foo/@name'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
353 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
354 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
355 (ATTR, ATTR, {'name': u'foo'}),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
356 (None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
357 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
358 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
359 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
360 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
361
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
362 def test_unwrap_adjacent(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
363 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
364 _transform(FOOBAR, Transformer('foo|bar').unwrap()),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
365 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
366 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
367 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
368 (INSIDE, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
369 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
370 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
371
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
372 def test_unwrap_root(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
373 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
374 self._unwrap('.'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
375 [(INSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
376 (INSIDE, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
377 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
378 (INSIDE, END, u'foo')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
379 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
380
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
381 def test_unwrap_text_root(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
382 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
383 _transform('foo', Transformer('.').unwrap()),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
384 [(OUTSIDE, TEXT, 'foo')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
385 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
386
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
387
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
388 class WrapTest(unittest.TestCase):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
389 def _wrap(self, select, wrap='wrap'):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
390 return _transform(FOO, Transformer(select).wrap(wrap))
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
391
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
392 def test_wrap_element(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
393 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
394 self._wrap('foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
395 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
396 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
397 (None, START, u'wrap'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
398 (ENTER, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
399 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
400 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
401 (None, END, u'wrap'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
402 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
403 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
404
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
405 def test_wrap_adjacent_elements(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
406 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
407 _transform(FOOBAR, Transformer('foo|bar').wrap('wrap')),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
408 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
409 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
410 (None, START, u'wrap'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
411 (ENTER, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
412 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
413 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
414 (None, END, u'wrap'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
415 (None, START, u'wrap'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
416 (ENTER, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
417 (INSIDE, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
418 (EXIT, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
419 (None, END, u'wrap'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
420 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
421 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
422
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
423 def test_wrap_text(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
424 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
425 self._wrap('foo/text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
426 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
427 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
428 (None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
429 (None, START, u'wrap'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
430 (OUTSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
431 (None, END, u'wrap'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
432 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
433 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
434 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
435
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
436 def test_wrap_root(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
437 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
438 self._wrap('.'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
439 [(None, START, u'wrap'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
440 (ENTER, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
441 (INSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
442 (INSIDE, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
443 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
444 (INSIDE, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
445 (EXIT, END, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
446 (None, END, u'wrap')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
447 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
448
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
449 def test_wrap_text_root(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
450 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
451 _transform('foo', Transformer('.').wrap('wrap')),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
452 [(None, START, u'wrap'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
453 (OUTSIDE, TEXT, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
454 (None, END, u'wrap')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
455 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
456
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
457 def test_wrap_with_element(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
458 element = Element('a', href='http://localhost')
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
459 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
460 _transform('foo', Transformer('.').wrap(element), with_attrs=True),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
461 [(None, START, (u'a', {u'href': u'http://localhost'})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
462 (OUTSIDE, TEXT, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
463 (None, END, u'a')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
464 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
465
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
466
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
467 class FilterTest(unittest.TestCase):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
468 def _filter(self, select, html=FOOBAR):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
469 """Returns a list of lists of filtered elements."""
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
470 output = []
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
471 def filtered(stream):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
472 interval = []
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
473 output.append(interval)
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
474 for event in stream:
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
475 interval.append(event)
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
476 yield event
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
477 _transform(html, Transformer(select).filter(filtered))
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
478 simplified = []
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
479 for sub in output:
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
480 simplified.append(_simplify([(None, event) for event in sub]))
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
481 return simplified
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
482
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
483 def test_filter_element(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
484 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
485 self._filter('foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
486 [[(None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
487 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
488 (None, END, u'foo')]]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
489 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
490
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
491 def test_filter_adjacent_elements(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
492 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
493 self._filter('foo|bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
494 [[(None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
495 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
496 (None, END, u'foo')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
497 [(None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
498 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
499 (None, END, u'bar')]]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
500 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
501
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
502 def test_filter_text(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
503 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
504 self._filter('*/text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
505 [[(None, TEXT, u'FOO')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
506 [(None, TEXT, u'BAR')]]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
507 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
508 def test_filter_root(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
509 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
510 self._filter('.'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
511 [[(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
512 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
513 (None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
514 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
515 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
516 (None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
517 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
518 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
519 (None, END, u'root')]]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
520 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
521
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
522 def test_filter_text_root(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
523 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
524 self._filter('.', 'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
525 [[(None, TEXT, u'foo')]])
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
526
800
1d7b582b09a4 Fix for filter transformation, closing #290. Thanks to Stephen Compall for reporting the problem and providing a patch.
cmlenz
parents: 744
diff changeset
527 def test_filter_after_outside(self):
1d7b582b09a4 Fix for filter transformation, closing #290. Thanks to Stephen Compall for reporting the problem and providing a patch.
cmlenz
parents: 744
diff changeset
528 stream = _transform(
1d7b582b09a4 Fix for filter transformation, closing #290. Thanks to Stephen Compall for reporting the problem and providing a patch.
cmlenz
parents: 744
diff changeset
529 '<root>x</root>', Transformer('//root/text()').filter(lambda x: x))
1d7b582b09a4 Fix for filter transformation, closing #290. Thanks to Stephen Compall for reporting the problem and providing a patch.
cmlenz
parents: 744
diff changeset
530 self.assertEqual(
1d7b582b09a4 Fix for filter transformation, closing #290. Thanks to Stephen Compall for reporting the problem and providing a patch.
cmlenz
parents: 744
diff changeset
531 list(stream),
1d7b582b09a4 Fix for filter transformation, closing #290. Thanks to Stephen Compall for reporting the problem and providing a patch.
cmlenz
parents: 744
diff changeset
532 [(None, START, u'root'),
1d7b582b09a4 Fix for filter transformation, closing #290. Thanks to Stephen Compall for reporting the problem and providing a patch.
cmlenz
parents: 744
diff changeset
533 (OUTSIDE, TEXT, u'x'),
1d7b582b09a4 Fix for filter transformation, closing #290. Thanks to Stephen Compall for reporting the problem and providing a patch.
cmlenz
parents: 744
diff changeset
534 (None, END, u'root')])
1d7b582b09a4 Fix for filter transformation, closing #290. Thanks to Stephen Compall for reporting the problem and providing a patch.
cmlenz
parents: 744
diff changeset
535
744
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
536
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
537 class MapTest(unittest.TestCase):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
538 def _map(self, select, kind=None):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
539 data = []
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
540 def record(d):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
541 data.append(d)
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
542 return d
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
543 _transform(FOOBAR, Transformer(select).map(record, kind))
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
544 return data
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
545
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
546 def test_map_element(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
547 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
548 self._map('foo'),
857
24733a5854d9 Avoid unicode literals in `repr`s of `QName` and `Namespace` when not necessary.
cmlenz
parents: 800
diff changeset
549 [(QName('foo'), Attrs([(QName('name'), u'foo'),
24733a5854d9 Avoid unicode literals in `repr`s of `QName` and `Namespace` when not necessary.
cmlenz
parents: 800
diff changeset
550 (QName('size'), u'100')])),
744
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
551 u'FOO',
857
24733a5854d9 Avoid unicode literals in `repr`s of `QName` and `Namespace` when not necessary.
cmlenz
parents: 800
diff changeset
552 QName('foo')]
24733a5854d9 Avoid unicode literals in `repr`s of `QName` and `Namespace` when not necessary.
cmlenz
parents: 800
diff changeset
553 )
744
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
554
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
555 def test_map_with_text_kind(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
556 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
557 self._map('.', TEXT),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
558 [u'ROOT', u'FOO', u'BAR']
857
24733a5854d9 Avoid unicode literals in `repr`s of `QName` and `Namespace` when not necessary.
cmlenz
parents: 800
diff changeset
559 )
744
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
560
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
561 def test_map_with_root_and_end_kind(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
562 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
563 self._map('.', END),
857
24733a5854d9 Avoid unicode literals in `repr`s of `QName` and `Namespace` when not necessary.
cmlenz
parents: 800
diff changeset
564 [QName('foo'), QName('bar'), QName('root')]
24733a5854d9 Avoid unicode literals in `repr`s of `QName` and `Namespace` when not necessary.
cmlenz
parents: 800
diff changeset
565 )
744
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
566
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
567 def test_map_with_attribute(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
568 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
569 self._map('foo/@name'),
857
24733a5854d9 Avoid unicode literals in `repr`s of `QName` and `Namespace` when not necessary.
cmlenz
parents: 800
diff changeset
570 [(QName('foo@*'), Attrs([('name', u'foo')]))]
24733a5854d9 Avoid unicode literals in `repr`s of `QName` and `Namespace` when not necessary.
cmlenz
parents: 800
diff changeset
571 )
744
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
572
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
573
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
574 class SubstituteTest(unittest.TestCase):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
575 def _substitute(self, select, pattern, replace):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
576 return _transform(FOOBAR, Transformer(select).substitute(pattern, replace))
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
577
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
578 def test_substitute_foo(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
579 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
580 self._substitute('foo', 'FOO|BAR', 'FOOOOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
581 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
582 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
583 (ENTER, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
584 (INSIDE, TEXT, u'FOOOOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
585 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
586 (None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
587 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
588 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
589 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
590 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
591
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
592 def test_substitute_foobar_with_group(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
593 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
594 self._substitute('foo|bar', '(FOO|BAR)', r'(\1)'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
595 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
596 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
597 (ENTER, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
598 (INSIDE, TEXT, u'(FOO)'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
599 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
600 (ENTER, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
601 (INSIDE, TEXT, u'(BAR)'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
602 (EXIT, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
603 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
604 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
605
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
606
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
607 class RenameTest(unittest.TestCase):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
608 def _rename(self, select):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
609 return _transform(FOOBAR, Transformer(select).rename('foobar'))
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
610
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
611 def test_rename_root(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
612 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
613 self._rename('.'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
614 [(ENTER, START, u'foobar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
615 (INSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
616 (INSIDE, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
617 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
618 (INSIDE, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
619 (INSIDE, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
620 (INSIDE, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
621 (INSIDE, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
622 (EXIT, END, u'foobar')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
623 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
624
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
625 def test_rename_element(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
626 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
627 self._rename('foo|bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
628 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
629 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
630 (ENTER, START, u'foobar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
631 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
632 (EXIT, END, u'foobar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
633 (ENTER, START, u'foobar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
634 (INSIDE, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
635 (EXIT, END, u'foobar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
636 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
637 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
638
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
639 def test_rename_text(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
640 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
641 self._rename('foo/text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
642 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
643 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
644 (None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
645 (OUTSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
646 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
647 (None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
648 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
649 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
650 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
651 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
652
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
653
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
654 class ContentTestMixin(object):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
655 def _apply(self, select, content=None, html=FOOBAR):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
656 class Injector(object):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
657 count = 0
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
658
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
659 def __iter__(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
660 self.count += 1
916
872726bac135 add support for python 3 to genshi.filters:
hodgestar
parents: 857
diff changeset
661 return iter(HTML(u'CONTENT %i' % self.count))
744
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
662
916
872726bac135 add support for python 3 to genshi.filters:
hodgestar
parents: 857
diff changeset
663 if isinstance(html, basestring) and not isinstance(html, unicode):
872726bac135 add support for python 3 to genshi.filters:
hodgestar
parents: 857
diff changeset
664 html = HTML(html, encoding='utf-8')
872726bac135 add support for python 3 to genshi.filters:
hodgestar
parents: 857
diff changeset
665 else:
744
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
666 html = HTML(html)
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
667 if content is None:
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
668 content = Injector()
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
669 elif isinstance(content, basestring):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
670 content = HTML(content)
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
671 return _transform(html, getattr(Transformer(select), self.operation)
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
672 (content))
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
673
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
674
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
675 class ReplaceTest(unittest.TestCase, ContentTestMixin):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
676 operation = 'replace'
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
677
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
678 def test_replace_element(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
679 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
680 self._apply('foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
681 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
682 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
683 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
684 (None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
685 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
686 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
687 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
688 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
689
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
690 def test_replace_text(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
691 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
692 self._apply('text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
693 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
694 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
695 (None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
696 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
697 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
698 (None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
699 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
700 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
701 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
702 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
703
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
704 def test_replace_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
705 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
706 self._apply('.'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
707 [(None, TEXT, u'CONTENT 1')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
708 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
709
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
710 def test_replace_text_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
711 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
712 self._apply('.', html='foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
713 [(None, TEXT, u'CONTENT 1')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
714 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
715
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
716 def test_replace_adjacent_elements(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
717 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
718 self._apply('*'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
719 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
720 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
721 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
722 (None, TEXT, u'CONTENT 2'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
723 (None, END, u'root')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
724 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
725
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
726 def test_replace_all(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
727 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
728 self._apply('*|text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
729 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
730 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
731 (None, TEXT, u'CONTENT 2'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
732 (None, TEXT, u'CONTENT 3'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
733 (None, END, u'root')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
734 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
735
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
736 def test_replace_with_callback(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
737 count = [0]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
738 def content():
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
739 count[0] += 1
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
740 yield '%2i.' % count[0]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
741 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
742 self._apply('*', content),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
743 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
744 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
745 (None, TEXT, u' 1.'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
746 (None, TEXT, u' 2.'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
747 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
748 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
749
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
750
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
751 class BeforeTest(unittest.TestCase, ContentTestMixin):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
752 operation = 'before'
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
753
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
754 def test_before_element(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
755 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
756 self._apply('foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
757 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
758 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
759 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
760 (ENTER, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
761 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
762 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
763 (None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
764 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
765 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
766 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
767 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
768
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
769 def test_before_text(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
770 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
771 self._apply('text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
772 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
773 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
774 (OUTSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
775 (None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
776 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
777 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
778 (None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
779 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
780 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
781 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
782 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
783
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
784 def test_before_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
785 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
786 self._apply('.'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
787 [(None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
788 (ENTER, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
789 (INSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
790 (INSIDE, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
791 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
792 (INSIDE, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
793 (INSIDE, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
794 (INSIDE, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
795 (INSIDE, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
796 (EXIT, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
797 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
798
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
799 def test_before_text_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
800 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
801 self._apply('.', html='foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
802 [(None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
803 (OUTSIDE, TEXT, u'foo')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
804 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
805
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
806 def test_before_adjacent_elements(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
807 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
808 self._apply('*'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
809 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
810 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
811 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
812 (ENTER, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
813 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
814 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
815 (None, TEXT, u'CONTENT 2'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
816 (ENTER, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
817 (INSIDE, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
818 (EXIT, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
819 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
820
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
821 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
822
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
823 def test_before_all(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
824 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
825 self._apply('*|text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
826 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
827 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
828 (OUTSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
829 (None, TEXT, u'CONTENT 2'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
830 (ENTER, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
831 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
832 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
833 (None, TEXT, u'CONTENT 3'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
834 (ENTER, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
835 (INSIDE, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
836 (EXIT, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
837 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
838 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
839
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
840 def test_before_with_callback(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
841 count = [0]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
842 def content():
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
843 count[0] += 1
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
844 yield '%2i.' % count[0]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
845 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
846 self._apply('foo/text()', content),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
847 [(None, 'START', u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
848 (None, 'TEXT', u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
849 (None, 'START', u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
850 (None, 'TEXT', u' 1.'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
851 ('OUTSIDE', 'TEXT', u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
852 (None, 'END', u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
853 (None, 'START', u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
854 (None, 'TEXT', u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
855 (None, 'END', u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
856 (None, 'END', u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
857 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
858
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
859
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
860 class AfterTest(unittest.TestCase, ContentTestMixin):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
861 operation = 'after'
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
862
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
863 def test_after_element(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
864 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
865 self._apply('foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
866 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
867 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
868 (ENTER, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
869 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
870 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
871 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
872 (None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
873 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
874 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
875 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
876 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
877
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
878 def test_after_text(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
879 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
880 self._apply('text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
881 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
882 (OUTSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
883 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
884 (None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
885 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
886 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
887 (None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
888 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
889 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
890 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
891 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
892
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
893 def test_after_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
894 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
895 self._apply('.'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
896 [(ENTER, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
897 (INSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
898 (INSIDE, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
899 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
900 (INSIDE, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
901 (INSIDE, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
902 (INSIDE, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
903 (INSIDE, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
904 (EXIT, END, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
905 (None, TEXT, u'CONTENT 1')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
906 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
907
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
908 def test_after_text_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
909 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
910 self._apply('.', html='foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
911 [(OUTSIDE, TEXT, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
912 (None, TEXT, u'CONTENT 1')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
913 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
914
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
915 def test_after_adjacent_elements(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
916 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
917 self._apply('*'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
918 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
919 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
920 (ENTER, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
921 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
922 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
923 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
924 (ENTER, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
925 (INSIDE, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
926 (EXIT, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
927 (None, TEXT, u'CONTENT 2'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
928 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
929
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
930 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
931
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
932 def test_after_all(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
933 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
934 self._apply('*|text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
935 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
936 (OUTSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
937 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
938 (ENTER, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
939 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
940 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
941 (None, TEXT, u'CONTENT 2'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
942 (ENTER, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
943 (INSIDE, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
944 (EXIT, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
945 (None, TEXT, u'CONTENT 3'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
946 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
947 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
948
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
949 def test_after_with_callback(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
950 count = [0]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
951 def content():
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
952 count[0] += 1
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
953 yield '%2i.' % count[0]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
954 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
955 self._apply('foo/text()', content),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
956 [(None, 'START', u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
957 (None, 'TEXT', u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
958 (None, 'START', u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
959 ('OUTSIDE', 'TEXT', u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
960 (None, 'TEXT', u' 1.'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
961 (None, 'END', u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
962 (None, 'START', u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
963 (None, 'TEXT', u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
964 (None, 'END', u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
965 (None, 'END', u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
966 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
967
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
968
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
969 class PrependTest(unittest.TestCase, ContentTestMixin):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
970 operation = 'prepend'
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
971
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
972 def test_prepend_element(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
973 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
974 self._apply('foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
975 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
976 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
977 (ENTER, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
978 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
979 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
980 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
981 (None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
982 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
983 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
984 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
985 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
986
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
987 def test_prepend_text(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
988 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
989 self._apply('text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
990 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
991 (OUTSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
992 (None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
993 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
994 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
995 (None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
996 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
997 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
998 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
999 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1000
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1001 def test_prepend_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1002 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1003 self._apply('.'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1004 [(ENTER, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1005 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1006 (INSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1007 (INSIDE, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1008 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1009 (INSIDE, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1010 (INSIDE, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1011 (INSIDE, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1012 (INSIDE, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1013 (EXIT, END, u'root')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1014 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1015
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1016 def test_prepend_text_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1017 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1018 self._apply('.', html='foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1019 [(OUTSIDE, TEXT, u'foo')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1020 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1021
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1022 def test_prepend_adjacent_elements(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1023 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1024 self._apply('*'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1025 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1026 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1027 (ENTER, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1028 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1029 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1030 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1031 (ENTER, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1032 (None, TEXT, u'CONTENT 2'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1033 (INSIDE, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1034 (EXIT, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1035 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1036
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1037 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1038
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1039 def test_prepend_all(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1040 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1041 self._apply('*|text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1042 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1043 (OUTSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1044 (ENTER, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1045 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1046 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1047 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1048 (ENTER, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1049 (None, TEXT, u'CONTENT 2'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1050 (INSIDE, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1051 (EXIT, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1052 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1053 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1054
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1055 def test_prepend_with_callback(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1056 count = [0]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1057 def content():
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1058 count[0] += 1
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1059 yield '%2i.' % count[0]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1060 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1061 self._apply('foo', content),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1062 [(None, 'START', u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1063 (None, 'TEXT', u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1064 (ENTER, 'START', u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1065 (None, 'TEXT', u' 1.'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1066 (INSIDE, 'TEXT', u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1067 (EXIT, 'END', u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1068 (None, 'START', u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1069 (None, 'TEXT', u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1070 (None, 'END', u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1071 (None, 'END', u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1072 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1073
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1074
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1075 class AppendTest(unittest.TestCase, ContentTestMixin):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1076 operation = 'append'
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1077
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1078 def test_append_element(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1079 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1080 self._apply('foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1081 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1082 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1083 (ENTER, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1084 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1085 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1086 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1087 (None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1088 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1089 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1090 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1091 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1092
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1093 def test_append_text(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1094 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1095 self._apply('text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1096 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1097 (OUTSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1098 (None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1099 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1100 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1101 (None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1102 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1103 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1104 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1105 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1106
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1107 def test_append_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1108 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1109 self._apply('.'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1110 [(ENTER, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1111 (INSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1112 (INSIDE, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1113 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1114 (INSIDE, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1115 (INSIDE, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1116 (INSIDE, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1117 (INSIDE, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1118 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1119 (EXIT, END, u'root')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1120 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1121
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1122 def test_append_text_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1123 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1124 self._apply('.', html='foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1125 [(OUTSIDE, TEXT, u'foo')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1126 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1127
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1128 def test_append_adjacent_elements(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1129 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1130 self._apply('*'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1131 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1132 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1133 (ENTER, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1134 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1135 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1136 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1137 (ENTER, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1138 (INSIDE, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1139 (None, TEXT, u'CONTENT 2'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1140 (EXIT, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1141 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1142
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1143 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1144
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1145 def test_append_all(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1146 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1147 self._apply('*|text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1148 [(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1149 (OUTSIDE, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1150 (ENTER, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1151 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1152 (None, TEXT, u'CONTENT 1'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1153 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1154 (ENTER, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1155 (INSIDE, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1156 (None, TEXT, u'CONTENT 2'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1157 (EXIT, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1158 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1159 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1160
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1161 def test_append_with_callback(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1162 count = [0]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1163 def content():
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1164 count[0] += 1
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1165 yield '%2i.' % count[0]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1166 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1167 self._apply('foo', content),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1168 [(None, 'START', u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1169 (None, 'TEXT', u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1170 (ENTER, 'START', u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1171 (INSIDE, 'TEXT', u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1172 (None, 'TEXT', u' 1.'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1173 (EXIT, 'END', u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1174 (None, 'START', u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1175 (None, 'TEXT', u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1176 (None, 'END', u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1177 (None, 'END', u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1178 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1179
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1180
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1181
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1182 class AttrTest(unittest.TestCase):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1183 def _attr(self, select, name, value):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1184 return _transform(FOOBAR, Transformer(select).attr(name, value),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1185 with_attrs=True)
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1186
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1187 def test_set_existing_attr(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1188 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1189 self._attr('foo', 'name', 'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1190 [(None, START, (u'root', {})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1191 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1192 (ENTER, START, (u'foo', {u'name': 'FOO', u'size': '100'})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1193 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1194 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1195 (None, START, (u'bar', {u'name': u'bar'})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1196 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1197 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1198 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1199 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1200
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1201 def test_set_new_attr(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1202 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1203 self._attr('foo', 'title', 'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1204 [(None, START, (u'root', {})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1205 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1206 (ENTER, START, (u'foo', {u'name': u'foo', u'title': 'FOO', u'size': '100'})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1207 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1208 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1209 (None, START, (u'bar', {u'name': u'bar'})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1210 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1211 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1212 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1213 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1214
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1215 def test_attr_from_function(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1216 def set(name, event):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1217 self.assertEqual(name, 'name')
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1218 return event[1][1].get('name').upper()
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1219
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1220 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1221 self._attr('foo|bar', 'name', set),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1222 [(None, START, (u'root', {})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1223 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1224 (ENTER, START, (u'foo', {u'name': 'FOO', u'size': '100'})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1225 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1226 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1227 (ENTER, START, (u'bar', {u'name': 'BAR'})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1228 (INSIDE, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1229 (EXIT, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1230 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1231 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1232
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1233 def test_remove_attr(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1234 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1235 self._attr('foo', 'name', None),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1236 [(None, START, (u'root', {})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1237 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1238 (ENTER, START, (u'foo', {u'size': '100'})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1239 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1240 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1241 (None, START, (u'bar', {u'name': u'bar'})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1242 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1243 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1244 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1245 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1246
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1247 def test_remove_attr_with_function(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1248 def set(name, event):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1249 return None
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1250
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1251 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1252 self._attr('foo', 'name', set),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1253 [(None, START, (u'root', {})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1254 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1255 (ENTER, START, (u'foo', {u'size': '100'})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1256 (INSIDE, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1257 (EXIT, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1258 (None, START, (u'bar', {u'name': u'bar'})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1259 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1260 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1261 (None, END, u'root')]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1262 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1263
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1264
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1265 class BufferTestMixin(object):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1266 def _apply(self, select, with_attrs=False):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1267 buffer = StreamBuffer()
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1268 events = buffer.events
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1269
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1270 class Trace(object):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1271 last = None
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1272 trace = []
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1273
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1274 def __call__(self, stream):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1275 for event in stream:
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1276 if events and hash(tuple(events)) != self.last:
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1277 self.last = hash(tuple(events))
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1278 self.trace.append(list(events))
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1279 yield event
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1280
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1281 trace = Trace()
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1282 output = _transform(FOOBAR, getattr(Transformer(select), self.operation)
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1283 (buffer).apply(trace), with_attrs=with_attrs)
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1284 simplified = []
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1285 for interval in trace.trace:
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1286 simplified.append(_simplify([(None, e) for e in interval],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1287 with_attrs=with_attrs))
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1288 return output, simplified
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1289
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1290
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1291 class CopyTest(unittest.TestCase, BufferTestMixin):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1292 operation = 'copy'
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1293
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1294 def test_copy_element(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1295 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1296 self._apply('foo')[1],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1297 [[(None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1298 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1299 (None, END, u'foo')]]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1300 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1301
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1302 def test_copy_adjacent_elements(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1303 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1304 self._apply('foo|bar')[1],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1305 [[(None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1306 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1307 (None, END, u'foo')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1308 [(None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1309 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1310 (None, END, u'bar')]]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1311 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1312
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1313 def test_copy_all(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1314 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1315 self._apply('*|text()')[1],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1316 [[(None, TEXT, u'ROOT')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1317 [(None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1318 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1319 (None, END, u'foo')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1320 [(None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1321 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1322 (None, END, u'bar')]]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1323 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1324
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1325 def test_copy_text(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1326 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1327 self._apply('*/text()')[1],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1328 [[(None, TEXT, u'FOO')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1329 [(None, TEXT, u'BAR')]]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1330 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1331
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1332 def test_copy_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1333 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1334 self._apply('.')[1],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1335 [[(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1336 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1337 (None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1338 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1339 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1340 (None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1341 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1342 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1343 (None, END, u'root')]]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1344 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1345
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1346 def test_copy_attribute(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1347 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1348 self._apply('foo/@name', with_attrs=True)[1],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1349 [[(None, ATTR, {'name': u'foo'})]]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1350 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1351
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1352 def test_copy_attributes(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1353 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1354 self._apply('foo/@*', with_attrs=True)[1],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1355 [[(None, ATTR, {u'name': u'foo', u'size': u'100'})]]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1356 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1357
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1358
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1359 class CutTest(unittest.TestCase, BufferTestMixin):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1360 operation = 'cut'
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1361
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1362 def test_cut_element(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1363 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1364 self._apply('foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1365 ([(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1366 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1367 (None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1368 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1369 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1370 (None, END, u'root')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1371 [[(None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1372 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1373 (None, END, u'foo')]])
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1374 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1375
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1376 def test_cut_adjacent_elements(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1377 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1378 self._apply('foo|bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1379 ([(None, START, u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1380 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1381 (BREAK, BREAK, None),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1382 (None, END, u'root')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1383 [[(None, START, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1384 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1385 (None, END, u'foo')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1386 [(None, START, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1387 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1388 (None, END, u'bar')]])
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1389 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1390
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1391 def test_cut_all(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1392 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1393 self._apply('*|text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1394 ([(None, 'START', u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1395 ('BREAK', 'BREAK', None),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1396 ('BREAK', 'BREAK', None),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1397 (None, 'END', u'root')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1398 [[(None, 'TEXT', u'ROOT')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1399 [(None, 'START', u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1400 (None, 'TEXT', u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1401 (None, 'END', u'foo')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1402 [(None, 'START', u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1403 (None, 'TEXT', u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1404 (None, 'END', u'bar')]])
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1405 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1406
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1407 def test_cut_text(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1408 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1409 self._apply('*/text()'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1410 ([(None, 'START', u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1411 (None, 'TEXT', u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1412 (None, 'START', u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1413 (None, 'END', u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1414 (None, 'START', u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1415 (None, 'END', u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1416 (None, 'END', u'root')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1417 [[(None, 'TEXT', u'FOO')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1418 [(None, 'TEXT', u'BAR')]])
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1419 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1420
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1421 def test_cut_context(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1422 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1423 self._apply('.')[1],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1424 [[(None, 'START', u'root'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1425 (None, 'TEXT', u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1426 (None, 'START', u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1427 (None, 'TEXT', u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1428 (None, 'END', u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1429 (None, 'START', u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1430 (None, 'TEXT', u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1431 (None, 'END', u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1432 (None, 'END', u'root')]]
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1433 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1434
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1435 def test_cut_attribute(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1436 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1437 self._apply('foo/@name', with_attrs=True),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1438 ([(None, START, (u'root', {})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1439 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1440 (None, START, (u'foo', {u'size': u'100'})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1441 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1442 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1443 (None, START, (u'bar', {u'name': u'bar'})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1444 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1445 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1446 (None, END, u'root')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1447 [[(None, ATTR, {u'name': u'foo'})]])
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1448 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1449
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1450 def test_cut_attributes(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1451 self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1452 self._apply('foo/@*', with_attrs=True),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1453 ([(None, START, (u'root', {})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1454 (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1455 (None, START, (u'foo', {})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1456 (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1457 (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1458 (None, START, (u'bar', {u'name': u'bar'})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1459 (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1460 (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1461 (None, END, u'root')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1462 [[(None, ATTR, {u'name': u'foo', u'size': u'100'})]])
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1463 )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1464
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1465 # XXX Test this when the XPath implementation is fixed (#233).
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1466 # def test_cut_attribute_or_attribute(self):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1467 # self.assertEqual(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1468 # self._apply('foo/@name | foo/@size', with_attrs=True),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1469 # ([(None, START, (u'root', {})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1470 # (None, TEXT, u'ROOT'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1471 # (None, START, (u'foo', {})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1472 # (None, TEXT, u'FOO'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1473 # (None, END, u'foo'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1474 # (None, START, (u'bar', {u'name': u'bar'})),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1475 # (None, TEXT, u'BAR'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1476 # (None, END, u'bar'),
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1477 # (None, END, u'root')],
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1478 # [[(None, ATTR, {u'name': u'foo', u'size': u'100'})]])
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1479 # )
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1480
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1481
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1482
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1483
501
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
1484 def suite():
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
1485 from genshi.input import HTML
668
ee48a06a16d6 Applied patch from cboos, fixing #168. Thanks!
athomas
parents: 501
diff changeset
1486 from genshi.core import Markup
ee48a06a16d6 Applied patch from cboos, fixing #168. Thanks!
athomas
parents: 501
diff changeset
1487 from genshi.builder import tag
744
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1488 suite = unittest.TestSuite()
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1489 for test in (SelectTest, InvertTest, EndTest,
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1490 EmptyTest, RemoveTest, UnwrapText, WrapTest, FilterTest,
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1491 MapTest, SubstituteTest, RenameTest, ReplaceTest, BeforeTest,
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1492 AfterTest, PrependTest, AppendTest, AttrTest, CopyTest, CutTest):
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1493 suite.addTest(unittest.makeSuite(test, 'test'))
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1494 suite.addTest(doctest.DocTestSuite(
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1495 genshi.filters.transform, optionflags=doctest.NORMALIZE_WHITESPACE,
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1496 extraglobs={'HTML': HTML, 'tag': tag, 'Markup': Markup}))
501
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
1497 return suite
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
1498
744
1f3c561f740a Lots of `Transformer` cleanup:
athomas
parents: 668
diff changeset
1499
501
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
1500 if __name__ == '__main__':
3073ac688651 Added new markup transformation filter contributed by Alec Thomas (#122). This provides gorgeous jQuery-inspired stream transformation capabilities based on XPath expressions.
cmlenz
parents:
diff changeset
1501 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software