~ubuntu-branches/ubuntu/jaunty/python-django/jaunty-updates

« back to all changes in this revision

Viewing changes to tests/regressiontests/forms/util.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2008-11-15 19:15:33 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20081115191533-xbt1ut2xf4fvwtvc
Tags: 1.0.1-0ubuntu1
* New upstream release:
  - Bug fixes.

* The tests/ sub-directory appaers to have been dropped upstream, so pull
  our patch to workaround the tests and modify the rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# coding: utf-8
2
 
"""
3
 
Tests for forms/util.py module.
4
 
"""
5
 
 
6
 
tests = r"""
7
 
>>> from django.forms.util import *
8
 
>>> from django.utils.translation import ugettext_lazy
9
 
 
10
 
###########
11
 
# flatatt #
12
 
###########
13
 
 
14
 
>>> from django.forms.util import flatatt
15
 
>>> flatatt({'id': "header"})
16
 
u' id="header"'
17
 
>>> flatatt({'class': "news", 'title': "Read this"})
18
 
u' class="news" title="Read this"'
19
 
>>> flatatt({})
20
 
u''
21
 
 
22
 
###################
23
 
# ValidationError #
24
 
###################
25
 
 
26
 
# Can take a string.
27
 
>>> print ValidationError("There was an error.").messages
28
 
<ul class="errorlist"><li>There was an error.</li></ul>
29
 
 
30
 
# Can take a unicode string.
31
 
>>> print ValidationError(u"Not \u03C0.").messages
32
 
<ul class="errorlist"><li>Not π.</li></ul>
33
 
 
34
 
# Can take a lazy string.
35
 
>>> print ValidationError(ugettext_lazy("Error.")).messages
36
 
<ul class="errorlist"><li>Error.</li></ul>
37
 
 
38
 
# Can take a list.
39
 
>>> print ValidationError(["Error one.", "Error two."]).messages
40
 
<ul class="errorlist"><li>Error one.</li><li>Error two.</li></ul>
41
 
 
42
 
# Can take a mixture in a list.
43
 
>>> print ValidationError(["First error.", u"Not \u03C0.", ugettext_lazy("Error.")]).messages
44
 
<ul class="errorlist"><li>First error.</li><li>Not π.</li><li>Error.</li></ul>
45
 
 
46
 
>>> class VeryBadError:
47
 
...     def __unicode__(self): return u"A very bad error."
48
 
 
49
 
# Can take a non-string.
50
 
>>> print ValidationError(VeryBadError()).messages
51
 
<ul class="errorlist"><li>A very bad error.</li></ul>
52
 
"""