summaryrefslogtreecommitdiff
path: root/tests/regressiontests/test_utils
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2008-07-19 14:46:55 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2008-07-19 14:46:55 +0000
commit0cffff024bde801620a1fae6ffe9f8e02be6f0ca (patch)
tree7aebeeff307b1e44354b57635252695ae4e9d9ce /tests/regressiontests/test_utils
parentc819252bf5e590b9bf66eb71d42938bb1ade2072 (diff)
Fixed #7441 - Improved the doctest OutputChecker to be more lenient with JSON an XML outputs. This is required so that output ordering that doesn't matter at a semantic level (such as the order of keys in a JSON dictionary, or attributes in an XML element) isn't caught as a test failure. Thanks to Leo Soto for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7981 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/test_utils')
-rw-r--r--tests/regressiontests/test_utils/__init__.py0
-rw-r--r--tests/regressiontests/test_utils/models.py0
-rw-r--r--tests/regressiontests/test_utils/tests.py57
3 files changed, 57 insertions, 0 deletions
diff --git a/tests/regressiontests/test_utils/__init__.py b/tests/regressiontests/test_utils/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/regressiontests/test_utils/__init__.py
diff --git a/tests/regressiontests/test_utils/models.py b/tests/regressiontests/test_utils/models.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/regressiontests/test_utils/models.py
diff --git a/tests/regressiontests/test_utils/tests.py b/tests/regressiontests/test_utils/tests.py
new file mode 100644
index 0000000000..9deb60b2ca
--- /dev/null
+++ b/tests/regressiontests/test_utils/tests.py
@@ -0,0 +1,57 @@
+r"""
+# Some checks of the doctest output normalizer.
+# Standard doctests do fairly
+>>> from django.utils import simplejson
+>>> from django.utils.xmlutils import SimplerXMLGenerator
+>>> from StringIO import StringIO
+
+>>> def produce_long():
+... return 42L
+
+>>> def produce_int():
+... return 42
+
+>>> def produce_json():
+... return simplejson.dumps(['foo', {'bar': ('baz', None, 1.0, 2), 'whiz': 42}])
+
+>>> def produce_xml():
+... stream = StringIO()
+... xml = SimplerXMLGenerator(stream, encoding='utf-8')
+... xml.startDocument()
+... xml.startElement("foo", {"aaa" : "1.0", "bbb": "2.0"})
+... xml.startElement("bar", {"ccc" : "3.0"})
+... xml.characters("Hello")
+... xml.endElement("bar")
+... xml.startElement("whiz", {})
+... xml.characters("Goodbye")
+... xml.endElement("whiz")
+... xml.endElement("foo")
+... xml.endDocument()
+... return stream.getvalue()
+
+# Long values are normalized and are comparable to normal integers ...
+>>> produce_long()
+42
+
+# ... and vice versa
+>>> produce_int()
+42L
+
+# JSON output is normalized for field order, so it doesn't matter
+# which order json dictionary attributes are listed in output
+>>> produce_json()
+'["foo", {"bar": ["baz", null, 1.0, 2], "whiz": 42}]'
+
+>>> produce_json()
+'["foo", {"whiz": 42, "bar": ["baz", null, 1.0, 2]}]'
+
+# XML output is normalized for attribute order, so it doesn't matter
+# which order XML element attributes are listed in output
+>>> produce_xml()
+'<?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>'
+
+>>> produce_xml()
+'<?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>'
+
+
+""" \ No newline at end of file