Django

Code

root/django/trunk/tests/regressiontests/forms/util.py

Revision 7971, 1.4 kB (checked in by jacob, 1 month ago)

Fixed #7741: django.newforms is now django.forms. This is obviously a backwards-incompatible change. There's a warning upon import of django.newforms itself, but deeper imports will raise errors.

  • Property svn:eol-style set to native
Line 
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 """
Note: See TracBrowser for help on using the browser.