Mercurial > genshi > genshi-test
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 | 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 | |
230 | 8 # are also available at http://genshi.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 | |
230 | 12 # history and logs, available at http://genshi.edgewall.org/log/. |
1 | 13 |
14 import doctest | |
15 import unittest | |
16 | |
230 | 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 | 19 from genshi.input import XML |
1 | 20 |
21 | |
22 class ElementFactoryTestCase(unittest.TestCase): | |
23 | |
24 def test_link(self): | |
20 | 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 | 27 self.assertEqual((Stream.START, |
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 | 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 | 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 | 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 | 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 | 65 |
902
09cc3627654c
Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents:
820
diff
changeset
|
66 |
1 | 67 def suite(): |
68 suite = unittest.TestSuite() | |
69 suite.addTest(doctest.DocTestSuite(Element.__module__)) | |
70 suite.addTest(unittest.makeSuite(ElementFactoryTestCase, 'test')) | |
71 return suite | |
72 | |
902
09cc3627654c
Sync `experimental/inline` branch with [source:trunk@1126].
cmlenz
parents:
820
diff
changeset
|
73 |
1 | 74 if __name__ == '__main__': |
75 unittest.main(defaultTest='suite') |