Opened 19 years ago
Closed 18 years ago
#3036 closed defect (fixed)
Misc minor doctest failures
| Reported by: | 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)
Change History (7)
comment:1 by , 19 years ago
| Triage Stage: | Unreviewed → Accepted | 
|---|
comment:2 by , 18 years ago
| Owner: | changed from to | 
|---|---|
| Status: | new → assigned | 
comment:3 by , 18 years ago
| Has patch: | set | 
|---|---|
| Resolution: | → fixed | 
| Status: | assigned → closed | 
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 , 18 years ago
| Resolution: | fixed | 
|---|---|
| Status: | closed → reopened | 
This patch is not reviewed and is not commited to trunk yet.
comment:5 by , 18 years ago
| Triage Stage: | Accepted → Ready for checkin | 
|---|
comment:6 by , 18 years ago
| Resolution: | → fixed | 
|---|---|
| Status: | reopened → closed | 
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 ;-)