Mercurial > genshi > genshi-test
annotate markup/tests/builder.py @ 143:ef761afcedff
CDATA sections in XML input now appear as CDATA sections in the output. This should address the problem with escaping the contents of `<style>` and `<script>` elements, which would only get interpreted correctly if the output was served as `application/xhtml+xml`. Closes #24.
author | cmlenz |
---|---|
date | Fri, 11 Aug 2006 14:08:13 +0000 |
parents | bc73d3ab823f |
children |
rev | line source |
---|---|
1 | 1 # -*- coding: utf-8 -*- |
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 | 4 # All rights reserved. |
5 # | |
6 # This software is licensed as described in the file COPYING, which | |
7 # you should have received as part of this distribution. The terms | |
66
822089ae65ce
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 | 9 # |
10 # This software consists of voluntary contributions made by many | |
11 # individuals. For the exact contribution history, see the revision | |
66
822089ae65ce
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 | 13 |
14 import doctest | |
15 from HTMLParser import HTMLParseError | |
16 import unittest | |
17 | |
18 from markup.builder import Element, tag | |
19 from markup.core import Stream | |
20 | |
21 | |
22 class ElementFactoryTestCase(unittest.TestCase): | |
23 | |
24 def test_link(self): | |
20 | 25 link = tag.a(href='#', title='Foo', accesskey=None)('Bar') |
1 | 26 bits = iter(link.generate()) |
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 | 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 | 42 |
43 def suite(): | |
44 suite = unittest.TestSuite() | |
45 suite.addTest(doctest.DocTestSuite(Element.__module__)) | |
46 suite.addTest(unittest.makeSuite(ElementFactoryTestCase, 'test')) | |
47 return suite | |
48 | |
49 if __name__ == '__main__': | |
50 unittest.main(defaultTest='suite') |