From 84e824fbbf7b1c90e0d6191e8e69577cfce0664b Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sat, 15 Sep 2007 08:29:56 +0000 Subject: [PATCH] Fixed #3036 -- Fixed some doctest strings that were failing. Thanks to pterk for the original patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6268 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/serializers/__init__.py | 6 +++--- django/core/validators.py | 17 +++++++++++------ django/template/__init__.py | 27 +++++++++++---------------- django/utils/datastructures.py | 16 +++++++--------- django/utils/feedgenerator.py | 1 + 5 files changed, 33 insertions(+), 34 deletions(-) diff --git a/django/core/serializers/__init__.py b/django/core/serializers/__init__.py index 049edf7521..1e24e2bd22 100644 --- a/django/core/serializers/__init__.py +++ b/django/core/serializers/__init__.py @@ -3,9 +3,9 @@ Interfaces for serializing Django objects. 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:: diff --git a/django/core/validators.py b/django/core/validators.py index 7611aef921..874edaefdd 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -405,12 +405,17 @@ class NumberIsInRange(object): 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 diff --git a/django/template/__init__.py b/django/template/__init__.py index de8591ac5c..449e0d0c28 100644 --- a/django/template/__init__.py +++ b/django/template/__init__.py @@ -34,14 +34,8 @@ will be raised if the template doesn't have proper syntax. Sample code: ->>> import template ->>> s = ''' -... -... {% if test %} -...

{{ varvalue }}

-... {% endif %} -... -... ''' +>>> from django import template +>>> s = u'{% if test %}

{{ varvalue }}

{% endif %}' >>> t = template.Template(s) (t is now a compiled template, and its render() method can be called multiple @@ -49,10 +43,10 @@ times with multiple contexts) >>> c = template.Context({'test':True, 'varvalue': 'Hello'}) >>> t.render(c) -'\n\n\n

Hello

\n\n\n' +u'

Hello

' >>> c = template.Context({'test':False, 'varvalue': 'Hello'}) >>> t.render(c) -'\n\n\n\n' +u'' """ import re from inspect import getargspec @@ -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 @@ -647,7 +642,7 @@ 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 @@ -655,7 +650,7 @@ def resolve_variable(path, context): >>> c.article = AClass() >>> c.article.section = 'News' >>> resolve_variable('article.section', c) - 'News' + u'News' (The example assumes VARIABLE_ATTRIBUTE_SEPARATOR is '.') """ diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index d96e45b9c8..ac890d5da6 100644 --- a/django/utils/datastructures.py +++ b/django/utils/datastructures.py @@ -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(): diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py index 44c96af147..e296331324 100644 --- a/django/utils/feedgenerator.py +++ b/django/utils/feedgenerator.py @@ -3,6 +3,7 @@ Syndication feed generation library -- used for generating RSS, etc. 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",