annotate genshi/tests/builder.py @ 902:09cc3627654c experimental-inline

Sync `experimental/inline` branch with [source:trunk@1126].
author cmlenz
date Fri, 23 Apr 2010 21:08:26 +0000
parents 1837f39efd6f
children
rev   line source
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
2 #
66
822089ae65ce Switch copyright to Edgewall and URLs to markup.edgewall.org.
cmlenz
parents: 27
diff changeset
3 # Copyright (C) 2006 Edgewall Software
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
4 # All rights reserved.
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
5 #
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
230
24757b771651 Renamed Markup to Genshi in repository.
cmlenz
parents: 98
diff changeset
8 # are also available at http://genshi.edgewall.org/wiki/License.
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
9 #
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
230
24757b771651 Renamed Markup to Genshi in repository.
cmlenz
parents: 98
diff changeset
12 # history and logs, available at http://genshi.edgewall.org/log/.
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
13
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
14 import doctest
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
15 import unittest
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
16
230
24757b771651 Renamed Markup to Genshi in repository.
cmlenz
parents: 98
diff changeset
17 from genshi.builder import Element, tag
820
1837f39efd6f Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents: 395
diff changeset
18 from genshi.core import Attrs, Markup, Stream
395
55cf81951686 inline branch: Merged [439:479/trunk].
cmlenz
parents: 347
diff changeset
19 from genshi.input import XML
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
20
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
21
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
22 class ElementFactoryTestCase(unittest.TestCase):
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
23
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
24 def test_link(self):
20
e3d3c1d8c98a Fix tests broken in [20].
cmlenz
parents: 1
diff changeset
25 link = tag.a(href='#', title='Foo', accesskey=None)('Bar')
902
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
26 events = list(link.generate())
347
c0a4114786cc cspeedups branch: Merged [423:426/trunk].
cmlenz
parents: 230
diff changeset
27 self.assertEqual((Stream.START,
c0a4114786cc cspeedups branch: Merged [423:426/trunk].
cmlenz
parents: 230
diff changeset
28 ('a', Attrs([('href', "#"), ('title', "Foo")])),
902
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
29 (None, -1, -1)), events[0])
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
30 self.assertEqual((Stream.TEXT, 'Bar', (None, -1, -1)), events[1])
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
31 self.assertEqual((Stream.END, 'a', (None, -1, -1)), events[2])
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
32
98
bc73d3ab823f Bugfix in `builder` module: attribute values need to be converted to strings when generating streams.
cmlenz
parents: 94
diff changeset
33 def test_nonstring_attributes(self):
bc73d3ab823f Bugfix in `builder` module: attribute values need to be converted to strings when generating streams.
cmlenz
parents: 94
diff changeset
34 """
bc73d3ab823f Bugfix in `builder` module: attribute values need to be converted to strings when generating streams.
cmlenz
parents: 94
diff changeset
35 Verify that if an attribute value is given as an int (or some other
bc73d3ab823f Bugfix in `builder` module: attribute values need to be converted to strings when generating streams.
cmlenz
parents: 94
diff changeset
36 non-string type), it is coverted to a string when the stream is
bc73d3ab823f Bugfix in `builder` module: attribute values need to be converted to strings when generating streams.
cmlenz
parents: 94
diff changeset
37 generated.
bc73d3ab823f Bugfix in `builder` module: attribute values need to be converted to strings when generating streams.
cmlenz
parents: 94
diff changeset
38 """
902
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
39 events = list(tag.foo(id=3))
347
c0a4114786cc cspeedups branch: Merged [423:426/trunk].
cmlenz
parents: 230
diff changeset
40 self.assertEqual((Stream.START, ('foo', Attrs([('id', '3')])),
902
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
41 (None, -1, -1)), events[0])
98
bc73d3ab823f Bugfix in `builder` module: attribute values need to be converted to strings when generating streams.
cmlenz
parents: 94
diff changeset
42
820
1837f39efd6f Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents: 395
diff changeset
43 def test_duplicate_attributes(self):
1837f39efd6f Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents: 395
diff changeset
44 link = tag.a(href='#1', href_='#2')('Bar')
902
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
45 events = list(link.generate())
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
46 self.assertEqual((Stream.START, ('a', Attrs([('href', "#1")])),
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
47 (None, -1, -1)), events[0])
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
48 self.assertEqual((Stream.TEXT, 'Bar', (None, -1, -1)), events[1])
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
49 self.assertEqual((Stream.END, 'a', (None, -1, -1)), events[2])
820
1837f39efd6f Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents: 395
diff changeset
50
395
55cf81951686 inline branch: Merged [439:479/trunk].
cmlenz
parents: 347
diff changeset
51 def test_stream_as_child(self):
902
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
52 events = list(tag.span(XML('<b>Foo</b>')).generate())
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
53 self.assertEqual(5, len(events))
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
54 self.assertEqual((Stream.START, ('span', ())), events[0][:2])
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
55 self.assertEqual((Stream.START, ('b', ())), events[1][:2])
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
56 self.assertEqual((Stream.TEXT, 'Foo'), events[2][:2])
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
57 self.assertEqual((Stream.END, 'b'), events[3][:2])
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
58 self.assertEqual((Stream.END, 'span'), events[4][:2])
395
55cf81951686 inline branch: Merged [439:479/trunk].
cmlenz
parents: 347
diff changeset
59
820
1837f39efd6f Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents: 395
diff changeset
60 def test_markup_escape(self):
1837f39efd6f Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents: 395
diff changeset
61 m = Markup('See %s') % tag.a('genshi',
1837f39efd6f Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents: 395
diff changeset
62 href='http://genshi.edgwall.org')
1837f39efd6f Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents: 395
diff changeset
63 self.assertEqual(m, Markup('See <a href="http://genshi.edgwall.org">'
1837f39efd6f Sync (old) experimental inline branch with trunk@1027.
cmlenz
parents: 395
diff changeset
64 'genshi</a>'))
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
65
902
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
66
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
67 def suite():
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
68 suite = unittest.TestSuite()
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
69 suite.addTest(doctest.DocTestSuite(Element.__module__))
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
70 suite.addTest(unittest.makeSuite(ElementFactoryTestCase, 'test'))
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
71 return suite
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
72
902
09cc3627654c Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents: 820
diff changeset
73
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
74 if __name__ == '__main__':
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
75 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software