annotate markup/tests/builder.py @ 181:e103b75a96ce trunk

Some error message improvements for template directives. Thanks to Christian Boos for the patch!
author cmlenz
date Mon, 21 Aug 2006 19:51:07 +0000
parents 44af12832c5a
children
rev   line source
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
2 #
66
59eb24184e9c Switch copyright to Edgewall and URLs to markup.edgewall.org.
cmlenz
parents: 27
diff changeset
3 # Copyright (C) 2006 Edgewall Software
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
4 # All rights reserved.
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
5 #
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
66
59eb24184e9c Switch copyright to Edgewall and URLs to markup.edgewall.org.
cmlenz
parents: 27
diff changeset
8 # are also available at http://markup.edgewall.org/wiki/License.
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
9 #
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
66
59eb24184e9c Switch copyright to Edgewall and URLs to markup.edgewall.org.
cmlenz
parents: 27
diff changeset
12 # history and logs, available at http://markup.edgewall.org/log/.
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
13
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
14 import doctest
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
15 from HTMLParser import HTMLParseError
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
16 import unittest
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
17
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
18 from markup.builder import Element, tag
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
19 from markup.core import Stream
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
20
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
21
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
22 class ElementFactoryTestCase(unittest.TestCase):
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
23
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
24 def test_link(self):
20
cc92d74ce9e5 Fix tests broken in [20].
cmlenz
parents: 1
diff changeset
25 link = tag.a(href='#', title='Foo', accesskey=None)('Bar')
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
26 bits = iter(link.generate())
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
27 self.assertEqual((Stream.START, ('a', [('href', "#"), ('title', "Foo")]),
94
0f8800c46e21 Some bugfixes and minor performance improvements for the builder module.
cmlenz
parents: 66
diff changeset
28 (None, -1, -1)), bits.next())
0f8800c46e21 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())
0f8800c46e21 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
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
31
98
44af12832c5a 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):
44af12832c5a Bugfix in `builder` module: attribute values need to be converted to strings when generating streams.
cmlenz
parents: 94
diff changeset
33 """
44af12832c5a 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
44af12832c5a 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
44af12832c5a Bugfix in `builder` module: attribute values need to be converted to strings when generating streams.
cmlenz
parents: 94
diff changeset
36 generated.
44af12832c5a Bugfix in `builder` module: attribute values need to be converted to strings when generating streams.
cmlenz
parents: 94
diff changeset
37 """
44af12832c5a 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()
44af12832c5a 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)),
44af12832c5a Bugfix in `builder` module: attribute values need to be converted to strings when generating streams.
cmlenz
parents: 94
diff changeset
40 event)
44af12832c5a Bugfix in `builder` module: attribute values need to be converted to strings when generating streams.
cmlenz
parents: 94
diff changeset
41
1
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
42
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
43 def suite():
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
44 suite = unittest.TestSuite()
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
45 suite.addTest(doctest.DocTestSuite(Element.__module__))
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
46 suite.addTest(unittest.makeSuite(ElementFactoryTestCase, 'test'))
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
47 return suite
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
48
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
49 if __name__ == '__main__':
5479aae32f5a Initial import.
cmlenz
parents:
diff changeset
50 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software