Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#7441 closed (fixed)

Doctest OutputChecker for xml and json

Reported by: leosoto 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 leosoto 7 years ago.
7441_wrapper_for_xml_outputchecker.diff (2.2 KB) - added by leosoto 7 years ago.

Download all attachments as: .zip

Change History (11)

Changed 7 years ago by leosoto

comment:1 Changed 7 years ago by anonymous

  • Component changed from Uncategorized to Unit test system
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 7 years ago by russellm

Sorry - that last change was me.

comment:3 follow-up: Changed 7 years ago by mtredinnick

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 7 years ago by leosoto

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 7 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(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 7 years ago by leosoto

comment:6 Changed 7 years ago by leosoto

  • Resolution fixed deleted
  • Status changed from closed to reopened

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 7 years ago by leosoto

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

comment:8 Changed 7 years ago by russellm

  • Resolution set to fixed
  • Status changed from reopened to closed

(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 7 years ago by russellm

(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