Django

Code

Ticket #7441 (closed: fixed)

Opened 6 months ago

Last modified 5 months ago

Doctest OutputChecker for xml and json

Reported by: leosoto Assigned to: nobody
Milestone: Component: Testing framework
Version: SVN Keywords: jython
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

doctest_xml_and_json_checkers.patch (5.7 kB) - added by leosoto on 06/12/08 22:41:56.
7441_wrapper_for_xml_outputchecker.diff (2.2 kB) - added by leosoto on 07/19/08 18:49:10.

Change History

06/12/08 22:41:56 changed by leosoto

  • attachment doctest_xml_and_json_checkers.patch added.

06/12/08 23:34:27 changed by anonymous

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • component changed from Uncategorized to Unit test system.
  • needs_tests changed.
  • needs_docs changed.

06/12/08 23:34:54 changed by russellm

Sorry - that last change was me.

(follow-up: ↓ 4 ) 06/29/08 23:36:57 changed 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,

(in reply to: ↑ 3 ) 06/30/08 08:59:22 changed 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.

07/19/08 09:46:55 changed by russellm

  • status changed from new to closed.
  • resolution set to fixed.

(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.

07/19/08 18:49:10 changed by leosoto

  • attachment 7441_wrapper_for_xml_outputchecker.diff added.

07/19/08 18:49:38 changed by leosoto

  • status changed from closed to reopened.
  • resolution deleted.

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.

07/19/08 18:51:24 changed by leosoto

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

07/20/08 00:46:41 changed by russellm

  • status changed from reopened to closed.
  • resolution set to fixed.

(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.

07/20/08 03:47:10 changed by russellm

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


Add/Change #7441 (Doctest OutputChecker for xml and json)




Change Properties
Action