Ticket #5849: strip_blocktrans_tests.py

File strip_blocktrans_tests.py, 3.8 KB (added by Dmitri Fedortchenko <zeraien@…>, 17 years ago)

Some unit tests to show and test outcome of stripping process

Line 
1import unittest
2from django.utils.translation import strip_blocktrans
3
4class BlockTransStripTest(unittest.TestCase):
5 def testOneLine(self):
6 s1 = "One Line No Indent"
7
8 s1_expected = "One Line No Indent"
9
10 self.assertEquals(s1_expected,strip_blocktrans(s1))
11
12 def testEmpty(self):
13 s1 = ""
14
15 s1_expected = ""
16
17 self.assertEquals(s1_expected,strip_blocktrans(s1))
18
19 def testStrip(self):
20 s1 = """
21 8 spaces
22 8 spaces
23 8 spaces
24
25 """
26
27 s1_expected = """8 spaces
288 spaces
298 spaces"""
30
31 self.assertEquals(s1_expected,strip_blocktrans(s1))
32
33 def testStrip2(self):
34 "If the first line has no indentation, the remaining lines are not touched."
35
36 s1 = """not indented
37 8 spaces
38 8 spaces
39
40 """
41
42 s1_expected = """not indented
43 8 spaces
44 8 spaces"""
45
46 self.assertEquals(s1_expected,strip_blocktrans(s1))
47
48 def testStrip2Tabs(self):
49 "If the first line has no indentation, the remaining lines are not touched."
50
51 s1 = """not indented
52 2 tabs
53 2 tabs
54
55 """
56
57 s1_expected = """not indented
58 2 tabs
59 2 tabs"""
60
61 self.assertEquals(s1_expected,strip_blocktrans(s1))
62
63
64 def testStrip3(self):
65 "If a single line has less indentation then the first line, the indetation is stripped anyway."
66
67 s1 = """
68 8 spaces
69 7 spaces
70 8 spaces
71
72 """
73
74 s1_expected = """8 spaces
757 spaces
768 spaces"""
77
78 self.assertEquals(s1_expected,strip_blocktrans(s1))
79
80 def testStrip4Tabs(self):
81 "Only indetation equal to the indentation of the first line is stripped, any line with additional spacing is stripped up to the indetation of the first line. This is indentation with tabs."
82
83 s1 = """
84 2 tabs
85 3 tabs
86 2 tabs
87
88 """
89
90 s1_expected = """2 tabs
91 3 tabs
922 tabs"""
93
94 self.assertEquals(s1_expected,strip_blocktrans(s1))
95
96
97 def testStrip5Mixed(self):
98
99 s1 = """
100 4 spaces
101 8 spaces
102 12 spaces
103
104 """
105
106 s1_expected = """4 spaces
107 8 spaces
108 12 spaces"""
109
110 self.assertEquals(s1_expected,strip_blocktrans(s1))
111
112
113 def testStrip4Mixed(self):
114 "Only indetation equal to the indentation of the first line is stripped, any line with additional spacing is stripped up to the indetation of the first line. This is mixed indetation with tabs and spaces."
115
116 s1 = """
117 4 spaces
118 1 tab and 4 spaces
119 2 tabs and 4 spaces
120
121 """
122
123 s1_expected = """4 spaces
124 1 tab and 4 spaces
125 2 tabs and 4 spaces"""
126
127 self.assertEquals(s1_expected,strip_blocktrans(s1))
128
129
130 def testStrip4(self):
131 "Only indetation equal to the indentation of the first line is stripped, any line with additional spacing is stripped up to the indetation of the first line."
132
133 s1 = """
134 8 spaces
135 12 spaces
136 2 tabs
137
138 """
139
140 s1_expected = """8 spaces
141 12 spaces
1422 tabs"""
143
144 def testStrip4(self):
145 "Only indetation equal to the indentation of the first line is stripped, any line with additional spacing is stripped up to the indetation of the first line."
146
147 s1 = """
148 8 spaces
149 12 spaces
150 8 spaces
151
152 """
153
154 s1_expected = """8 spaces
155 12 spaces
1568 spaces"""
157
158 self.assertEquals(s1_expected,strip_blocktrans(s1))
159
160
161if __name__ == '__main__':
162 unittest.main()
Back to Top