Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Migrated text doctests. Thanks to Stephan Jaekel.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13894 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1bcde8d6b451ffdd0271b7e1c100026b8501670a 1 parent 36ac6f1
Russell Keith-Magee authored September 27, 2010

Showing 1 changed file with 80 additions and 63 deletions. Show diff stats Hide diff stats

  1. 143  tests/regressiontests/text/tests.py
143  tests/regressiontests/text/tests.py
... ...
@@ -1,64 +1,81 @@
1 1
 # coding: utf-8
2  
-r"""
3  
-# Tests for stuff in django.utils.text and other text munging util functions.
4  
-
5  
->>> from django.utils.text import *
6  
-
7  
-### smart_split ###########################################################
8  
->>> list(smart_split(r'''This is "a person" test.'''))
9  
-[u'This', u'is', u'"a person"', u'test.']
10  
->>> print list(smart_split(r'''This is "a person's" test.'''))[2]
11  
-"a person's"
12  
->>> print list(smart_split(r'''This is "a person\"s" test.'''))[2]
13  
-"a person\"s"
14  
->>> list(smart_split('''"a 'one'''))
15  
-[u'"a', u"'one"]
16  
->>> print list(smart_split(r'''all friends' tests'''))[1]
17  
-friends'
18  
->>> list(smart_split(u'url search_page words="something else"'))
19  
-[u'url', u'search_page', u'words="something else"']
20  
->>> list(smart_split(u"url search_page words='something else'"))
21  
-[u'url', u'search_page', u"words='something else'"]
22  
->>> list(smart_split(u'url search_page words "something else"'))
23  
-[u'url', u'search_page', u'words', u'"something else"']
24  
->>> list(smart_split(u'url search_page words-"something else"'))
25  
-[u'url', u'search_page', u'words-"something else"']
26  
->>> list(smart_split(u'url search_page words=hello'))
27  
-[u'url', u'search_page', u'words=hello']
28  
->>> list(smart_split(u'url search_page words="something else'))
29  
-[u'url', u'search_page', u'words="something', u'else']
30  
->>> list(smart_split("cut:','|cut:' '"))
31  
-[u"cut:','|cut:' '"]
32  
-
33  
-### urlquote #############################################################
34  
->>> from django.utils.http import urlquote, urlquote_plus
35  
->>> urlquote(u'Paris & Orl\xe9ans')
36  
-u'Paris%20%26%20Orl%C3%A9ans'
37  
->>> urlquote(u'Paris & Orl\xe9ans', safe="&")
38  
-u'Paris%20&%20Orl%C3%A9ans'
39  
->>> urlquote_plus(u'Paris & Orl\xe9ans')
40  
-u'Paris+%26+Orl%C3%A9ans'
41  
->>> urlquote_plus(u'Paris & Orl\xe9ans', safe="&")
42  
-u'Paris+&+Orl%C3%A9ans'
43  
-
44  
-### cookie_date, http_date ###############################################
45  
->>> from django.utils.http import cookie_date, http_date
46  
->>> t = 1167616461.0
47  
->>> cookie_date(t)
48  
-'Mon, 01-Jan-2007 01:54:21 GMT'
49  
->>> http_date(t)
50  
-'Mon, 01 Jan 2007 01:54:21 GMT'
51  
-
52  
-### iri_to_uri ###########################################################
53  
->>> from django.utils.encoding import iri_to_uri
54  
->>> iri_to_uri(u'red%09ros\xe9#red')
55  
-'red%09ros%C3%A9#red'
56  
->>> iri_to_uri(u'/blog/for/J\xfcrgen M\xfcnster/')
57  
-'/blog/for/J%C3%BCrgen%20M%C3%BCnster/'
58  
->>> iri_to_uri(u'locations/%s' % urlquote_plus(u'Paris & Orl\xe9ans'))
59  
-'locations/Paris+%26+Orl%C3%A9ans'
60  
-
61  
-iri_to_uri() is idempotent:
62  
->>> iri_to_uri(iri_to_uri(u'red%09ros\xe9#red'))
63  
-'red%09ros%C3%A9#red'
64  
-"""
  2
+from django.test import TestCase
  3
+
  4
+from django.utils.text import *
  5
+from django.utils.http import urlquote, urlquote_plus, cookie_date, http_date
  6
+from django.utils.encoding import iri_to_uri
  7
+
  8
+class TextTests(TestCase):
  9
+    """
  10
+    Tests for stuff in django.utils.text and other text munging util functions.
  11
+    """
  12
+
  13
+    def test_smart_split(self):
  14
+
  15
+        self.assertEquals(list(smart_split(r'''This is "a person" test.''')),
  16
+            [u'This', u'is', u'"a person"', u'test.'])
  17
+
  18
+        self.assertEquals(list(smart_split(r'''This is "a person's" test.'''))[2],
  19
+            u'"a person\'s"')
  20
+
  21
+        self.assertEquals(list(smart_split(r'''This is "a person\"s" test.'''))[2],
  22
+            u'"a person\\"s"')
  23
+
  24
+        self.assertEquals(list(smart_split('''"a 'one''')), [u'"a', u"'one"])
  25
+
  26
+        self.assertEquals(list(smart_split(r'''all friends' tests'''))[1],
  27
+            "friends'")
  28
+
  29
+        self.assertEquals(list(smart_split(u'url search_page words="something else"')),
  30
+            [u'url', u'search_page', u'words="something else"'])
  31
+
  32
+        self.assertEquals(list(smart_split(u"url search_page words='something else'")),
  33
+            [u'url', u'search_page', u"words='something else'"])
  34
+
  35
+        self.assertEquals(list(smart_split(u'url search_page words "something else"')),
  36
+            [u'url', u'search_page', u'words', u'"something else"'])
  37
+
  38
+        self.assertEquals(list(smart_split(u'url search_page words-"something else"')),
  39
+            [u'url', u'search_page', u'words-"something else"'])
  40
+
  41
+        self.assertEquals(list(smart_split(u'url search_page words=hello')),
  42
+            [u'url', u'search_page', u'words=hello'])
  43
+
  44
+        self.assertEquals(list(smart_split(u'url search_page words="something else')),
  45
+            [u'url', u'search_page', u'words="something', u'else'])
  46
+
  47
+        self.assertEquals(list(smart_split("cut:','|cut:' '")),
  48
+            [u"cut:','|cut:' '"])
  49
+
  50
+    def test_urlquote(self):
  51
+
  52
+        self.assertEquals(urlquote(u'Paris & Orl\xe9ans'),
  53
+            u'Paris%20%26%20Orl%C3%A9ans')
  54
+        self.assertEquals(urlquote(u'Paris & Orl\xe9ans', safe="&"),
  55
+            u'Paris%20&%20Orl%C3%A9ans')
  56
+        self.assertEquals(urlquote_plus(u'Paris & Orl\xe9ans'),
  57
+            u'Paris+%26+Orl%C3%A9ans')
  58
+        self.assertEquals(urlquote_plus(u'Paris & Orl\xe9ans', safe="&"),
  59
+            u'Paris+&+Orl%C3%A9ans')
  60
+
  61
+    def test_cookie_date(self):
  62
+        t = 1167616461.0
  63
+        self.assertEquals(cookie_date(t), 'Mon, 01-Jan-2007 01:54:21 GMT')
  64
+
  65
+    def test_http_date(self):
  66
+        t = 1167616461.0
  67
+        self.assertEquals(http_date(t), 'Mon, 01 Jan 2007 01:54:21 GMT')
  68
+
  69
+    def test_iri_to_uri(self):
  70
+        self.assertEquals(iri_to_uri(u'red%09ros\xe9#red'),
  71
+            'red%09ros%C3%A9#red')
  72
+
  73
+        self.assertEquals(iri_to_uri(u'/blog/for/J\xfcrgen M\xfcnster/'),
  74
+            '/blog/for/J%C3%BCrgen%20M%C3%BCnster/')
  75
+
  76
+        self.assertEquals(iri_to_uri(u'locations/%s' % urlquote_plus(u'Paris & Orl\xe9ans')),
  77
+            'locations/Paris+%26+Orl%C3%A9ans')
  78
+
  79
+    def test_iri_to_uri_idempotent(self):
  80
+        self.assertEquals(iri_to_uri(iri_to_uri(u'red%09ros\xe9#red')),
  81
+            'red%09ros%C3%A9#red')

0 notes on commit 1bcde8d

Please sign in to comment.
Something went wrong with that request. Please try again.