PageRenderTime 123ms CodeModel.GetById 19ms RepoModel.GetById 2ms app.codeStats 2ms

/lib/django-1.5/tests/regressiontests/test_utils/tests.py

https://github.com/theosp/google_appengine
Python | 607 lines | 564 code | 41 blank | 2 comment | 35 complexity | 7d8b7158f82d1e0a2d68b21a71efd0b2 MD5 | raw file
  1. # -*- coding: utf-8 -*-
  2. from __future__ import absolute_import, unicode_literals
  3. from django.forms import EmailField, IntegerField
  4. from django.http import HttpResponse
  5. from django.template.loader import render_to_string
  6. from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
  7. from django.utils import six
  8. from django.utils.unittest import skip
  9. from .models import Person
  10. class SkippingTestCase(TestCase):
  11. def test_skip_unless_db_feature(self):
  12. "A test that might be skipped is actually called."
  13. # Total hack, but it works, just want an attribute that's always true.
  14. @skipUnlessDBFeature("__class__")
  15. def test_func():
  16. raise ValueError
  17. self.assertRaises(ValueError, test_func)
  18. class AssertNumQueriesTests(TestCase):
  19. urls = 'regressiontests.test_utils.urls'
  20. def test_assert_num_queries(self):
  21. def test_func():
  22. raise ValueError
  23. self.assertRaises(ValueError,
  24. self.assertNumQueries, 2, test_func
  25. )
  26. def test_assert_num_queries_with_client(self):
  27. person = Person.objects.create(name='test')
  28. self.assertNumQueries(
  29. 1,
  30. self.client.get,
  31. "/test_utils/get_person/%s/" % person.pk
  32. )
  33. self.assertNumQueries(
  34. 1,
  35. self.client.get,
  36. "/test_utils/get_person/%s/" % person.pk
  37. )
  38. def test_func():
  39. self.client.get("/test_utils/get_person/%s/" % person.pk)
  40. self.client.get("/test_utils/get_person/%s/" % person.pk)
  41. self.assertNumQueries(2, test_func)
  42. class AssertNumQueriesContextManagerTests(TestCase):
  43. urls = 'regressiontests.test_utils.urls'
  44. def test_simple(self):
  45. with self.assertNumQueries(0):
  46. pass
  47. with self.assertNumQueries(1):
  48. Person.objects.count()
  49. with self.assertNumQueries(2):
  50. Person.objects.count()
  51. Person.objects.count()
  52. def test_failure(self):
  53. with self.assertRaises(AssertionError) as exc_info:
  54. with self.assertNumQueries(2):
  55. Person.objects.count()
  56. self.assertIn("1 queries executed, 2 expected", str(exc_info.exception))
  57. with self.assertRaises(TypeError):
  58. with self.assertNumQueries(4000):
  59. raise TypeError
  60. def test_with_client(self):
  61. person = Person.objects.create(name="test")
  62. with self.assertNumQueries(1):
  63. self.client.get("/test_utils/get_person/%s/" % person.pk)
  64. with self.assertNumQueries(1):
  65. self.client.get("/test_utils/get_person/%s/" % person.pk)
  66. with self.assertNumQueries(2):
  67. self.client.get("/test_utils/get_person/%s/" % person.pk)
  68. self.client.get("/test_utils/get_person/%s/" % person.pk)
  69. class AssertTemplateUsedContextManagerTests(TestCase):
  70. def test_usage(self):
  71. with self.assertTemplateUsed('template_used/base.html'):
  72. render_to_string('template_used/base.html')
  73. with self.assertTemplateUsed(template_name='template_used/base.html'):
  74. render_to_string('template_used/base.html')
  75. with self.assertTemplateUsed('template_used/base.html'):
  76. render_to_string('template_used/include.html')
  77. with self.assertTemplateUsed('template_used/base.html'):
  78. render_to_string('template_used/extends.html')
  79. with self.assertTemplateUsed('template_used/base.html'):
  80. render_to_string('template_used/base.html')
  81. render_to_string('template_used/base.html')
  82. def test_nested_usage(self):
  83. with self.assertTemplateUsed('template_used/base.html'):
  84. with self.assertTemplateUsed('template_used/include.html'):
  85. render_to_string('template_used/include.html')
  86. with self.assertTemplateUsed('template_used/extends.html'):
  87. with self.assertTemplateUsed('template_used/base.html'):
  88. render_to_string('template_used/extends.html')
  89. with self.assertTemplateUsed('template_used/base.html'):
  90. with self.assertTemplateUsed('template_used/alternative.html'):
  91. render_to_string('template_used/alternative.html')
  92. render_to_string('template_used/base.html')
  93. with self.assertTemplateUsed('template_used/base.html'):
  94. render_to_string('template_used/extends.html')
  95. with self.assertTemplateNotUsed('template_used/base.html'):
  96. render_to_string('template_used/alternative.html')
  97. render_to_string('template_used/base.html')
  98. def test_not_used(self):
  99. with self.assertTemplateNotUsed('template_used/base.html'):
  100. pass
  101. with self.assertTemplateNotUsed('template_used/alternative.html'):
  102. pass
  103. def test_error_message(self):
  104. with six.assertRaisesRegex(self, AssertionError, r'^template_used/base\.html'):
  105. with self.assertTemplateUsed('template_used/base.html'):
  106. pass
  107. with six.assertRaisesRegex(self, AssertionError, r'^template_used/base\.html'):
  108. with self.assertTemplateUsed(template_name='template_used/base.html'):
  109. pass
  110. with six.assertRaisesRegex(self, AssertionError, r'^template_used/base\.html.*template_used/alternative\.html$'):
  111. with self.assertTemplateUsed('template_used/base.html'):
  112. render_to_string('template_used/alternative.html')
  113. def test_failure(self):
  114. with self.assertRaises(TypeError):
  115. with self.assertTemplateUsed():
  116. pass
  117. with self.assertRaises(AssertionError):
  118. with self.assertTemplateUsed(''):
  119. pass
  120. with self.assertRaises(AssertionError):
  121. with self.assertTemplateUsed(''):
  122. render_to_string('template_used/base.html')
  123. with self.assertRaises(AssertionError):
  124. with self.assertTemplateUsed(template_name=''):
  125. pass
  126. with self.assertRaises(AssertionError):
  127. with self.assertTemplateUsed('template_used/base.html'):
  128. render_to_string('template_used/alternative.html')
  129. class SaveRestoreWarningState(TestCase):
  130. def test_save_restore_warnings_state(self):
  131. """
  132. Ensure save_warnings_state/restore_warnings_state work correctly.
  133. """
  134. # In reality this test could be satisfied by many broken implementations
  135. # of save_warnings_state/restore_warnings_state (e.g. just
  136. # warnings.resetwarnings()) , but it is difficult to test more.
  137. import warnings
  138. self.save_warnings_state()
  139. class MyWarning(Warning):
  140. pass
  141. # Add a filter that causes an exception to be thrown, so we can catch it
  142. warnings.simplefilter("error", MyWarning)
  143. self.assertRaises(Warning, lambda: warnings.warn("warn", MyWarning))
  144. # Now restore.
  145. self.restore_warnings_state()
  146. # After restoring, we shouldn't get an exception. But we don't want a
  147. # warning printed either, so we have to silence the warning.
  148. warnings.simplefilter("ignore", MyWarning)
  149. warnings.warn("warn", MyWarning)
  150. # Remove the filter we just added.
  151. self.restore_warnings_state()
  152. class HTMLEqualTests(TestCase):
  153. def test_html_parser(self):
  154. from django.test.html import parse_html
  155. element = parse_html('<div><p>Hello</p></div>')
  156. self.assertEqual(len(element.children), 1)
  157. self.assertEqual(element.children[0].name, 'p')
  158. self.assertEqual(element.children[0].children[0], 'Hello')
  159. parse_html('<p>')
  160. parse_html('<p attr>')
  161. dom = parse_html('<p>foo')
  162. self.assertEqual(len(dom.children), 1)
  163. self.assertEqual(dom.name, 'p')
  164. self.assertEqual(dom[0], 'foo')
  165. def test_parse_html_in_script(self):
  166. from django.test.html import parse_html
  167. parse_html('<script>var a = "<p" + ">";</script>');
  168. parse_html('''
  169. <script>
  170. var js_sha_link='<p>***</p>';
  171. </script>
  172. ''')
  173. # script content will be parsed to text
  174. dom = parse_html('''
  175. <script><p>foo</p> '</scr'+'ipt>' <span>bar</span></script>
  176. ''')
  177. self.assertEqual(len(dom.children), 1)
  178. self.assertEqual(dom.children[0], "<p>foo</p> '</scr'+'ipt>' <span>bar</span>")
  179. def test_self_closing_tags(self):
  180. from django.test.html import parse_html
  181. self_closing_tags = ('br' , 'hr', 'input', 'img', 'meta', 'spacer',
  182. 'link', 'frame', 'base', 'col')
  183. for tag in self_closing_tags:
  184. dom = parse_html('<p>Hello <%s> world</p>' % tag)
  185. self.assertEqual(len(dom.children), 3)
  186. self.assertEqual(dom[0], 'Hello')
  187. self.assertEqual(dom[1].name, tag)
  188. self.assertEqual(dom[2], 'world')
  189. dom = parse_html('<p>Hello <%s /> world</p>' % tag)
  190. self.assertEqual(len(dom.children), 3)
  191. self.assertEqual(dom[0], 'Hello')
  192. self.assertEqual(dom[1].name, tag)
  193. self.assertEqual(dom[2], 'world')
  194. def test_simple_equal_html(self):
  195. self.assertHTMLEqual('', '')
  196. self.assertHTMLEqual('<p></p>', '<p></p>')
  197. self.assertHTMLEqual('<p></p>', ' <p> </p> ')
  198. self.assertHTMLEqual(
  199. '<div><p>Hello</p></div>',
  200. '<div><p>Hello</p></div>')
  201. self.assertHTMLEqual(
  202. '<div><p>Hello</p></div>',
  203. '<div> <p>Hello</p> </div>')
  204. self.assertHTMLEqual(
  205. '<div>\n<p>Hello</p></div>',
  206. '<div><p>Hello</p></div>\n')
  207. self.assertHTMLEqual(
  208. '<div><p>Hello\nWorld !</p></div>',
  209. '<div><p>Hello World\n!</p></div>')
  210. self.assertHTMLEqual(
  211. '<div><p>Hello\nWorld !</p></div>',
  212. '<div><p>Hello World\n!</p></div>')
  213. self.assertHTMLEqual(
  214. '<p>Hello World !</p>',
  215. '<p>Hello World\n\n!</p>')
  216. self.assertHTMLEqual('<p> </p>', '<p></p>')
  217. self.assertHTMLEqual('<p/>', '<p></p>')
  218. self.assertHTMLEqual('<p />', '<p></p>')
  219. self.assertHTMLEqual('<input checked>', '<input checked="checked">')
  220. self.assertHTMLEqual('<p>Hello', '<p> Hello')
  221. self.assertHTMLEqual('<p>Hello</p>World', '<p>Hello</p> World')
  222. def test_ignore_comments(self):
  223. self.assertHTMLEqual(
  224. '<div>Hello<!-- this is a comment --> World!</div>',
  225. '<div>Hello World!</div>')
  226. def test_unequal_html(self):
  227. self.assertHTMLNotEqual('<p>Hello</p>', '<p>Hello!</p>')
  228. self.assertHTMLNotEqual('<p>foo&#20;bar</p>', '<p>foo&nbsp;bar</p>')
  229. self.assertHTMLNotEqual('<p>foo bar</p>', '<p>foo &nbsp;bar</p>')
  230. self.assertHTMLNotEqual('<p>foo nbsp</p>', '<p>foo &nbsp;</p>')
  231. self.assertHTMLNotEqual('<p>foo #20</p>', '<p>foo &#20;</p>')
  232. self.assertHTMLNotEqual(
  233. '<p><span>Hello</span><span>World</span></p>',
  234. '<p><span>Hello</span>World</p>')
  235. self.assertHTMLNotEqual(
  236. '<p><span>Hello</span>World</p>',
  237. '<p><span>Hello</span><span>World</span></p>')
  238. def test_attributes(self):
  239. self.assertHTMLEqual(
  240. '<input type="text" id="id_name" />',
  241. '<input id="id_name" type="text" />')
  242. self.assertHTMLEqual(
  243. '''<input type='text' id="id_name" />''',
  244. '<input id="id_name" type="text" />')
  245. self.assertHTMLNotEqual(
  246. '<input type="text" id="id_name" />',
  247. '<input type="password" id="id_name" />')
  248. def test_complex_examples(self):
  249. self.assertHTMLEqual(
  250. """<tr><th><label for="id_first_name">First name:</label></th>
  251. <td><input type="text" name="first_name" value="John" id="id_first_name" /></td></tr>
  252. <tr><th><label for="id_last_name">Last name:</label></th>
  253. <td><input type="text" id="id_last_name" name="last_name" value="Lennon" /></td></tr>
  254. <tr><th><label for="id_birthday">Birthday:</label></th>
  255. <td><input type="text" value="1940-10-9" name="birthday" id="id_birthday" /></td></tr>""",
  256. """
  257. <tr><th>
  258. <label for="id_first_name">First name:</label></th><td><input type="text" name="first_name" value="John" id="id_first_name" />
  259. </td></tr>
  260. <tr><th>
  261. <label for="id_last_name">Last name:</label></th><td><input type="text" name="last_name" value="Lennon" id="id_last_name" />
  262. </td></tr>
  263. <tr><th>
  264. <label for="id_birthday">Birthday:</label></th><td><input type="text" name="birthday" value="1940-10-9" id="id_birthday" />
  265. </td></tr>
  266. """)
  267. self.assertHTMLEqual(
  268. """<!DOCTYPE html>
  269. <html>
  270. <head>
  271. <link rel="stylesheet">
  272. <title>Document</title>
  273. <meta attribute="value">
  274. </head>
  275. <body>
  276. <p>
  277. This is a valid paragraph
  278. <div> this is a div AFTER the p</div>
  279. </body>
  280. </html>""", """
  281. <html>
  282. <head>
  283. <link rel="stylesheet">
  284. <title>Document</title>
  285. <meta attribute="value">
  286. </head>
  287. <body>
  288. <p> This is a valid paragraph
  289. <!-- browsers would close the p tag here -->
  290. <div> this is a div AFTER the p</div>
  291. </p> <!-- this is invalid HTML parsing, but it should make no
  292. difference in most cases -->
  293. </body>
  294. </html>""")
  295. def test_html_contain(self):
  296. from django.test.html import parse_html
  297. # equal html contains each other
  298. dom1 = parse_html('<p>foo')
  299. dom2 = parse_html('<p>foo</p>')
  300. self.assertTrue(dom1 in dom2)
  301. self.assertTrue(dom2 in dom1)
  302. dom2 = parse_html('<div><p>foo</p></div>')
  303. self.assertTrue(dom1 in dom2)
  304. self.assertTrue(dom2 not in dom1)
  305. self.assertFalse('<p>foo</p>' in dom2)
  306. self.assertTrue('foo' in dom2)
  307. # when a root element is used ...
  308. dom1 = parse_html('<p>foo</p><p>bar</p>')
  309. dom2 = parse_html('<p>foo</p><p>bar</p>')
  310. self.assertTrue(dom1 in dom2)
  311. dom1 = parse_html('<p>foo</p>')
  312. self.assertTrue(dom1 in dom2)
  313. dom1 = parse_html('<p>bar</p>')
  314. self.assertTrue(dom1 in dom2)
  315. def test_count(self):
  316. from django.test.html import parse_html
  317. # equal html contains each other one time
  318. dom1 = parse_html('<p>foo')
  319. dom2 = parse_html('<p>foo</p>')
  320. self.assertEqual(dom1.count(dom2), 1)
  321. self.assertEqual(dom2.count(dom1), 1)
  322. dom2 = parse_html('<p>foo</p><p>bar</p>')
  323. self.assertEqual(dom2.count(dom1), 1)
  324. dom2 = parse_html('<p>foo foo</p><p>foo</p>')
  325. self.assertEqual(dom2.count('foo'), 3)
  326. dom2 = parse_html('<p class="bar">foo</p>')
  327. self.assertEqual(dom2.count('bar'), 0)
  328. self.assertEqual(dom2.count('class'), 0)
  329. self.assertEqual(dom2.count('p'), 0)
  330. self.assertEqual(dom2.count('o'), 2)
  331. dom2 = parse_html('<p>foo</p><p>foo</p>')
  332. self.assertEqual(dom2.count(dom1), 2)
  333. dom2 = parse_html('<div><p>foo<input type=""></p><p>foo</p></div>')
  334. self.assertEqual(dom2.count(dom1), 1)
  335. dom2 = parse_html('<div><div><p>foo</p></div></div>')
  336. self.assertEqual(dom2.count(dom1), 1)
  337. dom2 = parse_html('<p>foo<p>foo</p></p>')
  338. self.assertEqual(dom2.count(dom1), 1)
  339. dom2 = parse_html('<p>foo<p>bar</p></p>')
  340. self.assertEqual(dom2.count(dom1), 0)
  341. def test_parsing_errors(self):
  342. from django.test.html import HTMLParseError, parse_html
  343. with self.assertRaises(AssertionError):
  344. self.assertHTMLEqual('<p>', '')
  345. with self.assertRaises(AssertionError):
  346. self.assertHTMLEqual('', '<p>')
  347. with self.assertRaises(HTMLParseError):
  348. parse_html('</p>')
  349. def test_contains_html(self):
  350. response = HttpResponse('''<body>
  351. This is a form: <form action="" method="get">
  352. <input type="text" name="Hello" />
  353. </form></body>''')
  354. self.assertNotContains(response, "<input name='Hello' type='text'>")
  355. self.assertContains(response, '<form action="" method="get">')
  356. self.assertContains(response, "<input name='Hello' type='text'>", html=True)
  357. self.assertNotContains(response, '<form action="" method="get">', html=True)
  358. invalid_response = HttpResponse('''<body <bad>>''')
  359. with self.assertRaises(AssertionError):
  360. self.assertContains(invalid_response, '<p></p>')
  361. with self.assertRaises(AssertionError):
  362. self.assertContains(response, '<p "whats" that>')
  363. def test_unicode_handling(self):
  364. from django.http import HttpResponse
  365. response = HttpResponse('<p class="help">Some help text for the title (with unicode ŠĐĆŽćžšđ)</p>')
  366. self.assertContains(response, '<p class="help">Some help text for the title (with unicode ŠĐĆŽćžšđ)</p>', html=True)
  367. class XMLEqualTests(TestCase):
  368. def test_simple_equal(self):
  369. xml1 = "<elem attr1='a' attr2='b' />"
  370. xml2 = "<elem attr1='a' attr2='b' />"
  371. self.assertXMLEqual(xml1, xml2)
  372. def test_simple_equal_unordered(self):
  373. xml1 = "<elem attr1='a' attr2='b' />"
  374. xml2 = "<elem attr2='b' attr1='a' />"
  375. self.assertXMLEqual(xml1, xml2)
  376. def test_simple_equal_raise(self):
  377. xml1 = "<elem attr1='a' />"
  378. xml2 = "<elem attr2='b' attr1='a' />"
  379. with self.assertRaises(AssertionError):
  380. self.assertXMLEqual(xml1, xml2)
  381. def test_simple_not_equal(self):
  382. xml1 = "<elem attr1='a' attr2='c' />"
  383. xml2 = "<elem attr1='a' attr2='b' />"
  384. self.assertXMLNotEqual(xml1, xml2)
  385. def test_simple_not_equal_raise(self):
  386. xml1 = "<elem attr1='a' attr2='b' />"
  387. xml2 = "<elem attr2='b' attr1='a' />"
  388. with self.assertRaises(AssertionError):
  389. self.assertXMLNotEqual(xml1, xml2)
  390. def test_parsing_errors(self):
  391. xml_unvalid = "<elem attr1='a attr2='b' />"
  392. xml2 = "<elem attr2='b' attr1='a' />"
  393. with self.assertRaises(AssertionError):
  394. self.assertXMLNotEqual(xml_unvalid, xml2)
  395. def test_comment_root(self):
  396. xml1 = "<?xml version='1.0'?><!-- comment1 --><elem attr1='a' attr2='b' />"
  397. xml2 = "<?xml version='1.0'?><!-- comment2 --><elem attr2='b' attr1='a' />"
  398. self.assertXMLEqual(xml1, xml2)
  399. class SkippingExtraTests(TestCase):
  400. fixtures = ['should_not_be_loaded.json']
  401. # HACK: This depends on internals of our TestCase subclasses
  402. def __call__(self, result=None):
  403. # Detect fixture loading by counting SQL queries, should be zero
  404. with self.assertNumQueries(0):
  405. super(SkippingExtraTests, self).__call__(result)
  406. @skip("Fixture loading should not be performed for skipped tests.")
  407. def test_fixtures_are_skipped(self):
  408. pass
  409. class AssertRaisesMsgTest(SimpleTestCase):
  410. def test_special_re_chars(self):
  411. """assertRaisesMessage shouldn't interpret RE special chars."""
  412. def func1():
  413. raise ValueError("[.*x+]y?")
  414. self.assertRaisesMessage(ValueError, "[.*x+]y?", func1)
  415. class AssertFieldOutputTests(SimpleTestCase):
  416. def test_assert_field_output(self):
  417. error_invalid = ['Enter a valid email address.']
  418. self.assertFieldOutput(EmailField, {'a@a.com': 'a@a.com'}, {'aaa': error_invalid})
  419. self.assertRaises(AssertionError, self.assertFieldOutput, EmailField, {'a@a.com': 'a@a.com'}, {'aaa': error_invalid + ['Another error']})
  420. self.assertRaises(AssertionError, self.assertFieldOutput, EmailField, {'a@a.com': 'Wrong output'}, {'aaa': error_invalid})
  421. self.assertRaises(AssertionError, self.assertFieldOutput, EmailField, {'a@a.com': 'a@a.com'}, {'aaa': ['Come on, gimme some well formatted data, dude.']})
  422. def test_custom_required_message(self):
  423. class MyCustomField(IntegerField):
  424. default_error_messages = {
  425. 'required': 'This is really required.',
  426. }
  427. self.assertFieldOutput(MyCustomField, {}, {}, empty_value=None)
  428. __test__ = {"API_TEST": r"""
  429. # Some checks of the doctest output normalizer.
  430. # Standard doctests do fairly
  431. >>> import json
  432. >>> from django.utils.xmlutils import SimplerXMLGenerator
  433. >>> from django.utils.six import StringIO
  434. >>> def produce_json():
  435. ... return json.dumps(['foo', {'bar': ('baz', None, 1.0, 2), 'whiz': 42}])
  436. >>> def produce_xml():
  437. ... stream = StringIO()
  438. ... xml = SimplerXMLGenerator(stream, encoding='utf-8')
  439. ... xml.startDocument()
  440. ... xml.startElement("foo", {"aaa" : "1.0", "bbb": "2.0"})
  441. ... xml.startElement("bar", {"ccc" : "3.0"})
  442. ... xml.characters("Hello")
  443. ... xml.endElement("bar")
  444. ... xml.startElement("whiz", {})
  445. ... xml.characters("Goodbye")
  446. ... xml.endElement("whiz")
  447. ... xml.endElement("foo")
  448. ... xml.endDocument()
  449. ... return stream.getvalue()
  450. >>> def produce_xml_fragment():
  451. ... stream = StringIO()
  452. ... xml = SimplerXMLGenerator(stream, encoding='utf-8')
  453. ... xml.startElement("foo", {"aaa": "1.0", "bbb": "2.0"})
  454. ... xml.characters("Hello")
  455. ... xml.endElement("foo")
  456. ... xml.startElement("bar", {"ccc": "3.0", "ddd": "4.0"})
  457. ... xml.endElement("bar")
  458. ... return stream.getvalue()
  459. # JSON output is normalized for field order, so it doesn't matter
  460. # which order json dictionary attributes are listed in output
  461. >>> produce_json()
  462. '["foo", {"bar": ["baz", null, 1.0, 2], "whiz": 42}]'
  463. >>> produce_json()
  464. '["foo", {"whiz": 42, "bar": ["baz", null, 1.0, 2]}]'
  465. # XML output is normalized for attribute order, so it doesn't matter
  466. # which order XML element attributes are listed in output
  467. >>> produce_xml()
  468. '<?xml version="1.0" encoding="UTF-8"?>\n<foo aaa="1.0" bbb="2.0"><bar ccc="3.0">Hello</bar><whiz>Goodbye</whiz></foo>'
  469. >>> produce_xml()
  470. '<?xml version="1.0" encoding="UTF-8"?>\n<foo bbb="2.0" aaa="1.0"><bar ccc="3.0">Hello</bar><whiz>Goodbye</whiz></foo>'
  471. >>> produce_xml_fragment()
  472. '<foo aaa="1.0" bbb="2.0">Hello</foo><bar ccc="3.0" ddd="4.0"></bar>'
  473. >>> produce_xml_fragment()
  474. '<foo bbb="2.0" aaa="1.0">Hello</foo><bar ddd="4.0" ccc="3.0"></bar>'
  475. """}
  476. if not six.PY3:
  477. __test__["API_TEST"] += """
  478. >>> def produce_long():
  479. ... return 42L
  480. >>> def produce_int():
  481. ... return 42
  482. # Long values are normalized and are comparable to normal integers ...
  483. >>> produce_long()
  484. 42
  485. # ... and vice versa
  486. >>> produce_int()
  487. 42L
  488. """