Django

Code

Ticket #3036 (closed: fixed)

Opened 2 years ago

Last modified 1 year ago

Misc minor doctest failures

Reported by: Yary H <spam-django@yary.ack.org> Assigned to: pterk
Milestone: Component: Testing framework
Version: SVN Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

3036.diff (5.3 kB) - added by pterk on 09/14/07 08:21:01.
Patch for #3036

Change History

01/30/07 15:43:35 changed by mir@noris.de

  • stage changed from Unreviewed to Accepted.

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 ;-)

09/14/07 06:18:30 changed by pterk

  • owner changed from nobody to pterk.
  • status changed from new to assigned.

09/14/07 08:21:01 changed by pterk

  • attachment 3036.diff added.

Patch for #3036

09/14/07 08:21:34 changed by pterk

  • status changed from assigned to closed.
  • has_patch set to 1.
  • resolution set to fixed.

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

09/14/07 08:51:41 changed by mtsuyuki

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

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

09/14/07 17:25:40 changed by Simon G. <dev@simon.net.nz>

  • stage changed from Accepted to Ready for checkin.

09/15/07 03:29:59 changed by russellm

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

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


Add/Change #3036 (Misc minor doctest failures)




Change Properties
Action