Skip to content

Commit

Permalink
Fixed #3036 -- Fixed some doctest strings that were failing. Thanks t…
Browse files Browse the repository at this point in the history
…o pterk for the original patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6268 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
freakboy3742 committed Sep 15, 2007
1 parent 671a835 commit 84e824f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 34 deletions.
6 changes: 3 additions & 3 deletions django/core/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
Usage::
>>> from django.core import serializers
>>> json = serializers.serialize("json", some_query_set)
>>> objects = list(serializers.deserialize("json", json))
from django.core import serializers
json = serializers.serialize("json", some_query_set)
objects = list(serializers.deserialize("json", json))
To add your own serializers, use the SERIALIZATION_MODULES setting::
Expand Down
17 changes: 11 additions & 6 deletions django/core/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,17 @@ def __call__(self, field_data, all_data):

class IsAPowerOf(object):
"""
>>> v = IsAPowerOf(2)
>>> v(4, None)
>>> v(8, None)
>>> v(16, None)
>>> v(17, None)
django.core.validators.ValidationError: ['This value must be a power of 2.']
Usage: If you create an instance of the IsPowerOf validator:
v = IsAPowerOf(2)
The following calls will succeed:
v(4, None)
v(8, None)
v(16, None)
But this call:
v(17, None)
will raise "django.core.validators.ValidationError: ['This value must be a power of 2.']"
"""
def __init__(self, power_of):
self.power_of = power_of
Expand Down
27 changes: 11 additions & 16 deletions django/template/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,19 @@
Sample code:
>>> import template
>>> s = '''
... <html>
... {% if test %}
... <h1>{{ varvalue }}</h1>
... {% endif %}
... </html>
... '''
>>> from django import template
>>> s = u'<html>{% if test %}<h1>{{ varvalue }}</h1>{% endif %}</html>'
>>> t = template.Template(s)
(t is now a compiled template, and its render() method can be called multiple
times with multiple contexts)
>>> c = template.Context({'test':True, 'varvalue': 'Hello'})
>>> t.render(c)
'\n<html>\n\n <h1>Hello</h1>\n\n</html>\n'
u'<html><h1>Hello</h1></html>'
>>> c = template.Context({'test':False, 'varvalue': 'Hello'})
>>> t.render(c)
'\n<html>\n\n</html>\n'
u'<html></html>'
"""
import re
from inspect import getargspec
Expand Down Expand Up @@ -529,10 +523,11 @@ class FilterExpression(object):
and return a list of tuples of the filter name and arguments.
Sample:
>>> token = 'variable|default:"Default value"|date:"Y-m-d"'
>>> p = FilterParser(token)
>>> p.filters
[('default', 'Default value'), ('date', 'Y-m-d')]
>>> p.var
>>> p = Parser('')
>>> fe = FilterExpression(token, p)
>>> len(fe.filters)
2
>>> fe.var
'variable'
This class should never be instantiated outside of the
Expand Down Expand Up @@ -647,15 +642,15 @@ def resolve_variable(path, context):
>>> c = {'article': {'section':'News'}}
>>> resolve_variable('article.section', c)
'News'
u'News'
>>> resolve_variable('article', c)
{'section': 'News'}
>>> class AClass: pass
>>> c = AClass()
>>> c.article = AClass()
>>> c.article.section = 'News'
>>> resolve_variable('article.section', c)
'News'
u'News'
(The example assumes VARIABLE_ATTRIBUTE_SEPARATOR is '.')
"""
Expand Down
16 changes: 7 additions & 9 deletions django/utils/datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,22 +238,20 @@ class DotExpandedDict(dict):
may contain dots to specify inner dictionaries. It's confusing, but this
example should make sense.
>>> d = DotExpandedDict({'person.1.firstname': ['Simon'],
'person.1.lastname': ['Willison'],
'person.2.firstname': ['Adrian'],
>>> d = DotExpandedDict({'person.1.firstname': ['Simon'], \
'person.1.lastname': ['Willison'], \
'person.2.firstname': ['Adrian'], \
'person.2.lastname': ['Holovaty']})
>>> d
{'person': {'1': {'lastname': ['Willison'], 'firstname': ['Simon']},
'2': {'lastname': ['Holovaty'], 'firstname': ['Adrian']}}}
{'person': {'1': {'lastname': ['Willison'], 'firstname': ['Simon']}, '2': {'lastname': ['Holovaty'], 'firstname': ['Adrian']}}}
>>> d['person']
{'1': {'firstname': ['Simon'], 'lastname': ['Willison'],
'2': {'firstname': ['Adrian'], 'lastname': ['Holovaty']}
{'1': {'lastname': ['Willison'], 'firstname': ['Simon']}, '2': {'lastname': ['Holovaty'], 'firstname': ['Adrian']}}
>>> d['person']['1']
{'firstname': ['Simon'], 'lastname': ['Willison']}
{'lastname': ['Willison'], 'firstname': ['Simon']}
# Gotcha: Results are unpredictable if the dots are "uneven":
>>> DotExpandedDict({'c.1': 2, 'c.2': 3, 'c': 1})
>>> {'c': 1}
{'c': 1}
"""
def __init__(self, key_to_list_mapping):
for k, v in key_to_list_mapping.items():
Expand Down
1 change: 1 addition & 0 deletions django/utils/feedgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Sample usage:
>>> from django.utils import feedgenerator
>>> feed = feedgenerator.Rss201rev2Feed(
... title=u"Poynter E-Media Tidbits",
... link=u"http://www.poynter.org/column.asp?id=31",
Expand Down

0 comments on commit 84e824f

Please sign in to comment.