annotate genshi/tests/builder.py @ 230:24757b771651

Renamed Markup to Genshi in repository.
author cmlenz
date Mon, 11 Sep 2006 15:07:07 +0000
parents markup/tests/builder.py@bc73d3ab823f
children 8e75b83d3e71 676b78a0c5a0
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 from HTMLParser import HTMLParseError
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
16 import unittest
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
17
230
24757b771651 Renamed Markup to Genshi in repository.
cmlenz
parents: 98
diff changeset
18 from genshi.builder import Element, tag
24757b771651 Renamed Markup to Genshi in repository.
cmlenz
parents: 98
diff changeset
19 from genshi.core import Stream
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')
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
26 bits = iter(link.generate())
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
27 self.assertEqual((Stream.START, ('a', [('href', "#"), ('title', "Foo")]),
94
80c72e936e72 Some bugfixes and minor performance improvements for the builder module.
cmlenz
parents: 66
diff changeset
28 (None, -1, -1)), bits.next())
80c72e936e72 Some bugfixes and minor performance improvements for the builder module.
cmlenz
parents: 66
diff changeset
29 self.assertEqual((Stream.TEXT, u'Bar', (None, -1, -1)), bits.next())
80c72e936e72 Some bugfixes and minor performance improvements for the builder module.
cmlenz
parents: 66
diff changeset
30 self.assertEqual((Stream.END, 'a', (None, -1, -1)), bits.next())
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
31
98
bc73d3ab823f Bugfix in `builder` module: attribute values need to be converted to strings when generating streams.
cmlenz
parents: 94
diff changeset
32 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
33 """
bc73d3ab823f Bugfix in `builder` module: attribute values need to be converted to strings when generating streams.
cmlenz
parents: 94
diff changeset
34 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
35 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
36 generated.
bc73d3ab823f Bugfix in `builder` module: attribute values need to be converted to strings when generating streams.
cmlenz
parents: 94
diff changeset
37 """
bc73d3ab823f Bugfix in `builder` module: attribute values need to be converted to strings when generating streams.
cmlenz
parents: 94
diff changeset
38 event = iter(tag.foo(id=3)).next()
bc73d3ab823f Bugfix in `builder` module: attribute values need to be converted to strings when generating streams.
cmlenz
parents: 94
diff changeset
39 self.assertEqual((Stream.START, ('foo', [('id', '3')]), (None, -1, -1)),
bc73d3ab823f Bugfix in `builder` module: attribute values need to be converted to strings when generating streams.
cmlenz
parents: 94
diff changeset
40 event)
bc73d3ab823f Bugfix in `builder` module: attribute values need to be converted to strings when generating streams.
cmlenz
parents: 94
diff changeset
41
1
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
42
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
43 def suite():
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
44 suite = unittest.TestSuite()
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
45 suite.addTest(doctest.DocTestSuite(Element.__module__))
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
46 suite.addTest(unittest.makeSuite(ElementFactoryTestCase, 'test'))
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
47 return suite
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
48
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
49 if __name__ == '__main__':
821114ec4f69 Initial import.
cmlenz
parents:
diff changeset
50 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software