Mercurial > genshi > mirror
comparison genshi/template/tests/directives.py @ 967:19ac5d8fd96c trunk
Fix a number of tests which Python's new hash randomization is causing to fail randomly.
author | hodgestar |
---|---|
date | Sat, 29 Dec 2012 19:14:10 +0000 |
parents | d1edb246cc61 |
children |
comparison
equal
deleted
inserted
replaced
966:570226c48119 | 967:19ac5d8fd96c |
---|---|
28 Verify that the directive has access to the loop variables. | 28 Verify that the directive has access to the loop variables. |
29 """ | 29 """ |
30 tmpl = MarkupTemplate("""<doc xmlns:py="http://genshi.edgewall.org/"> | 30 tmpl = MarkupTemplate("""<doc xmlns:py="http://genshi.edgewall.org/"> |
31 <elem py:for="item in items" py:attrs="item"/> | 31 <elem py:for="item in items" py:attrs="item"/> |
32 </doc>""") | 32 </doc>""") |
33 items = [{'id': 1, 'class': 'foo'}, {'id': 2, 'class': 'bar'}] | 33 items = [{'id': 1}, {'id': 2}] |
34 self.assertEqual("""<doc> | 34 self.assertEqual("""<doc> |
35 <elem id="1" class="foo"/><elem id="2" class="bar"/> | 35 <elem id="1"/><elem id="2"/> |
36 </doc>""", tmpl.generate(items=items).render(encoding=None)) | 36 </doc>""", tmpl.generate(items=items).render(encoding=None)) |
37 | 37 |
38 def test_update_existing_attr(self): | 38 def test_update_existing_attr(self): |
39 """ | 39 """ |
40 Verify that an attribute value that evaluates to `None` removes an | 40 Verify that an attribute value that evaluates to `None` removes an |
393 expected. | 393 expected. |
394 """ | 394 """ |
395 tmpl = MarkupTemplate("""<doc xmlns:py="http://genshi.edgewall.org/"> | 395 tmpl = MarkupTemplate("""<doc xmlns:py="http://genshi.edgewall.org/"> |
396 <div py:def="f(*args, **kwargs)"> | 396 <div py:def="f(*args, **kwargs)"> |
397 ${repr(args)} | 397 ${repr(args)} |
398 ${repr(kwargs)} | 398 ${repr(sorted(kwargs.items()))} |
399 </div> | 399 </div> |
400 ${f(1, 2, a=3, b=4)} | 400 ${f(1, 2, a=3, b=4)} |
401 </doc>""") | 401 </doc>""") |
402 self.assertEqual("""<doc> | 402 self.assertEqual("""<doc> |
403 <div> | 403 <div> |
404 [1, 2] | 404 [1, 2] |
405 {'a': 3, 'b': 4} | 405 [('a', 3), ('b', 4)] |
406 </div> | 406 </div> |
407 </doc>""", tmpl.generate().render(encoding=None)) | 407 </doc>""", tmpl.generate().render(encoding=None)) |
408 | 408 |
409 | 409 |
410 class ForDirectiveTestCase(unittest.TestCase): | 410 class ForDirectiveTestCase(unittest.TestCase): |
455 </py:for> | 455 </py:for> |
456 </doc>""") | 456 </doc>""") |
457 self.assertEqual("""<doc> | 457 self.assertEqual("""<doc> |
458 <p>key=a, value=1</p> | 458 <p>key=a, value=1</p> |
459 <p>key=b, value=2</p> | 459 <p>key=b, value=2</p> |
460 </doc>""", tmpl.generate(items=dict(a=1, b=2).items()) | 460 </doc>""", tmpl.generate(items=(('a', 1), ('b', 2))) |
461 .render(encoding=None)) | 461 .render(encoding=None)) |
462 | 462 |
463 def test_nested_assignment(self): | 463 def test_nested_assignment(self): |
464 """ | 464 """ |
465 Verify that assignment to nested tuples works correctly. | 465 Verify that assignment to nested tuples works correctly. |
470 </py:for> | 470 </py:for> |
471 </doc>""") | 471 </doc>""") |
472 self.assertEqual("""<doc> | 472 self.assertEqual("""<doc> |
473 <p>0: key=a, value=1</p> | 473 <p>0: key=a, value=1</p> |
474 <p>1: key=b, value=2</p> | 474 <p>1: key=b, value=2</p> |
475 </doc>""", tmpl.generate(items=enumerate(dict(a=1, b=2).items())) | 475 </doc>""", tmpl.generate(items=enumerate([('a', 1), ('b', 2)])) |
476 .render(encoding=None)) | 476 .render(encoding=None)) |
477 | 477 |
478 def test_not_iterable(self): | 478 def test_not_iterable(self): |
479 """ | 479 """ |
480 Verify that assignment to nested tuples works correctly. | 480 Verify that assignment to nested tuples works correctly. |