Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#7441 closed (fixed)

Doctest OutputChecker for xml and json

Reported by: Leo Soto M. Owned by: nobody
Component: Testing framework Version: master
Severity: Keywords: jython
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Currently, there are many doctests which checks for XHTML and JSON output. These checks don't pass on Jython, because the differences in dictionary attribute ordering tend to produce output where the XML or JSON attribute ordering is also different of what is expected.

The attached patch adds XML and JSON checking to django.test.testcases.OutputChecker, allowing this tests to pass on Jython (and, presumably, on other VMs).

Attachments (2)

doctest_xml_and_json_checkers.patch (5.7 KB) - added by Leo Soto M. 8 years ago.
7441_wrapper_for_xml_outputchecker.diff (2.2 KB) - added by Leo Soto M. 8 years ago.

Download all attachments as: .zip

Change History (11)

Changed 8 years ago by Leo Soto M.

comment:1 Changed 8 years ago by anonymous

Component: UncategorizedUnit test system
Triage Stage: UnreviewedAccepted

comment:2 Changed 8 years ago by Russell Keith-Magee

Sorry - that last change was me.

comment:3 Changed 8 years ago by Malcolm Tredinnick

Except for an "oh dear... more processing in the test suite to slow things down" sinking feeling, I really like this approach. I'm sure I'll learn to overcome that former problem in the many minutes I spend contemplating my navel whilst waiting for the tests to run,

comment:4 in reply to:  3 Changed 8 years ago by Leo Soto M.

Replying to mtredinnick:

Except for an "oh dear... more processing in the test suite to slow things down"

Yep, it will slow things down a bit, but only if the other output checkers (which are ran first) don't yield a successful comparison. Right now, this means zero slowdown on CPython, and some slowdown on Jython, in places where we previously had failures.

comment:5 Changed 8 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

(In [7981]) 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.

Changed 8 years ago by Leo Soto M.

comment:6 Changed 8 years ago by Leo Soto M.

Resolution: fixed
Status: closedreopened

Seems that the looks_like_markup method was a premature optimization which are doing more harm that good. On source:django/trunk/tests/regressiontests/admin_widgets/models.py there are doctest output like:
e

Currently: <a target="_blank" href="%(MEDIA_URL)stest">test</a> <br />Change: <input type="file" name="test" />

So I think we have to drop that (the repr_re hack also not very good, raising false negatives with every attribute value containing "at" or "object".

Also the "wrapper" strategy to check xml fragments was dropped from the patch when it was committed to trunk, but it is needed for cases like the shown above.

I'm attaching a patch fixing these two issues.

comment:7 Changed 8 years ago by Leo Soto M.

Oops, sorry for the amount of typos, forgot to preview the message.

comment:8 Changed 8 years ago by Russell Keith-Magee

Resolution: fixed
Status: reopenedclosed

(In [8003]) Fixed #7441 -- Removed some of the shortcuts in the doctest output comparators, and added a wrapper to allow comparison of xml fragments. Thanks to Leo Soto for the report and fix.

comment:9 Changed 8 years ago by Russell Keith-Magee

(In [8005]) Made the test case for doctest comparison of XML fragments a little more rigorous. Refs #7441.

Note: See TracTickets for help on using tickets.
Back to Top