Opened 18 years ago

Closed 17 years ago

#3036 closed defect (fixed)

Misc minor doctest failures

Reported by: Yary H <spam-django@…> Owned by: Peter van Kampen
Component: Testing framework Version: dev
Severity: minor Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Tried running all the easily-runnable doctests in django's source, found these minor anomolies. Sorry if this is just "noise", all errors seem to be "pedantic" and not indicitive of true bugs.

File "django/core/validators.py", line 394, in django.core.validators.IsAPowerOf
Failed example:
    v(17, None)
Exception raised:
    Traceback (most recent call last):
...
      File "....django/core/validators.py", line 404, in __call__
        raise ValidationError, gettext("This value must be a power of %s.") % self.power_of
    ValidationError: ['This value must be a power of 2.']
**********************************************************************
1 items had failures:
   1 of   5 in django.core.validators.IsAPowerOf

To fix, change lines 394,395 of core\validators.py to read:

    >>> v(17, None)
    Traceback (most recent call last):
        ...
    ValidationError: ['This value must be a power of 2.']

next one:

File "django/core/serializers/__init__.py", line 7, in django.core.serializers
Failed example:
    json = serializers.serialize("json", some_query_set)
Exception raised:
    Traceback (most recent call last):
...
      File "<doctest django.core.serializers[1]>", line 1, in ?
        json = serializers.serialize("json", some_query_set)
    NameError: name 'some_query_set' is not defined
**********************************************************************
File "django/core/serializers/__init__.py", line 8, in django.core.serializers
Failed example:
    objects = list(serializers.deserialize("json", json))
Exception raised:
    Traceback (most recent call last):
...
      File "<doctest django.core.serializers[2]>", line 1, in ?
        objects = list(serializers.deserialize("json", json))
      File "django/core/serializers/json.py", line 32, in Deserializer
        for obj in PythonDeserializer(simplejson.load(stream)):
      File "django/utils/simplejson/__init__.py", line 177, in load
        return cls(encoding=encoding, **kw).decode(fp.read())
    AttributeError: 'module' object has no attribute 'read'
**********************************************************************
1 items had failures:
   2 of   3 in django.core.serializers
***Test Failed*** 2 failures.
(2, 3)

Not super-simple for me to fix!

Next ones-

File "django/template/__init__.py", line 37, in django.template
Failed example:
    import template
Exception raised:
    Traceback (most recent call last):
...
      File "<doctest django.template[0]>", line 1, in ?
        import template
    ImportError: No module named template
...
2 items had failures:
   6 of   7 in django.template
   3 of   4 in django.template.FilterExpression
***Test Failed*** 9 failures.
(9, 19)

was able to quickly fix a few (but not all) errors by changing line 37 to read:
>>> from django import template

next-

File "django/utils/datastructures.py", line 217, in django.utils.datastructures.DotExpandedDict
Failed example:
    d = DotExpandedDict({'person.1.firstname': ['Simon'],
Exception raised:
    Traceback (most recent call last):
    ...
      File "<doctest django.utils.datastructures.DotExpandedDict[0]>", line 1
         d = DotExpandedDict({'person.1.firstname': ['Simon'],
                                                              ^
     SyntaxError: unexpected EOF while parsing

hmm, missing the ' ... ' continuation markers.

django/utils/simplejson/encoder.py has a simple whitespace issue? change line 264 to '{"foo": ["bar", "baz"]}' - that is, add a single space between ':' and '['

Also check django.utils.feedgenerator

I also listed a different one of these in ticket #3035 for utils.text

thanks!

Attachments (1)

3036.diff (5.3 KB ) - added by Peter van Kampen 17 years ago.
Patch for #3036

Download all attachments as: .zip

Change History (7)

comment:1 by mir@…, 18 years ago

Triage Stage: UnreviewedAccepted

Hmhm, at least the first and the last cases are still buggy. How can this be? Doesn't the testsuite run all the doctests?

A proper patch to fix these docstrings would be very welcome ;-)

comment:2 by Peter van Kampen, 17 years ago

Owner: changed from nobody to Peter van Kampen
Status: newassigned

by Peter van Kampen, 17 years ago

Attachment: 3036.diff added

Patch for #3036

comment:3 by Peter van Kampen, 17 years ago

Has patch: set
Resolution: fixed
Status: assignedclosed

Checked these by doing:

$cd myproject
$./manage.py shell
>>> from django.core import validators, serializers
>>> import doctest
>>> doctest.testmod(validators)
  • Added a traceback at line 417 in core/validators.py
  • Removed the prompt ('>>>') from sample usage in serializers.py (Is not a test. See tests/regressiontests/serializers_regress/ for those)
  • Changed the import from template and changed all output to unicode in template. Reworked sample/test for FilterExpression that has been refactored quite a bit sonce these tests/samples were written.
  • Changed the tests for DotExpandedDict to have predictable output (order of dict keys is not guaranteed to be the same) and fixed a syntax error
  • django/utils/simplejson/encoder.py produces no errors?
  • Added import statement to feedgenerator

comment:4 by makoto tsuyuki, 17 years ago

Resolution: fixed
Status: closedreopened

This patch is not reviewed and is not commited to trunk yet.

comment:5 by Simon G. <dev@…>, 17 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Russell Keith-Magee, 17 years ago

Resolution: fixed
Status: reopenedclosed

(In [6268]) Fixed #3036 -- Fixed some doctest strings that were failing. Thanks to pterk for the original patch.

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