@@ -19,6 +19,42 @@ def test_pythonvalue(self):
19
19
result = instance .pythonvalue ("foobar" )
20
20
assert result == "foobar"
21
21
22
+ result = instance .pythonvalue (" foo\t bar\r \n " )
23
+ assert result == " foo\t bar\r \n "
24
+
25
+
26
+ class TestNormalizedString :
27
+ def test_xmlvalue (self ):
28
+ instance = builtins .NormalizedString ()
29
+ result = instance .xmlvalue ("foobar" )
30
+ assert result == "foobar"
31
+
32
+ def test_pythonvalue (self ):
33
+ instance = builtins .NormalizedString ()
34
+ result = instance .pythonvalue ("foobar" )
35
+ assert result == "foobar"
36
+
37
+ result = instance .pythonvalue ("fo\t ob\r ar\n " )
38
+ assert result == "fo ob ar "
39
+
40
+
41
+ class TestToken :
42
+ def test_xmlvalue (self ):
43
+ instance = builtins .Token ()
44
+ result = instance .xmlvalue ("foobar" )
45
+ assert result == "foobar"
46
+
47
+ def test_pythonvalue (self ):
48
+ instance = builtins .Token ()
49
+ result = instance .pythonvalue ("foobar" )
50
+ assert result == "foobar"
51
+
52
+ result = instance .pythonvalue ("fo\t ob\r ar" )
53
+ assert result == "fo ob ar"
54
+
55
+ result = instance .pythonvalue (" foobar " )
56
+ assert result == "foobar"
57
+
22
58
23
59
class TestBoolean :
24
60
def test_xmlvalue (self ):
@@ -36,6 +72,7 @@ def test_pythonvalue(self):
36
72
assert instance .pythonvalue ("true" ) is True
37
73
assert instance .pythonvalue ("0" ) is False
38
74
assert instance .pythonvalue ("false" ) is False
75
+ assert instance .pythonvalue ("\t \r \n false " ) is False
39
76
40
77
41
78
class TestDecimal :
@@ -53,6 +90,7 @@ def test_pythonvalue(self):
53
90
assert instance .pythonvalue ("10.001" ) == D ("10.001" )
54
91
assert instance .pythonvalue ("+10.001" ) == D ("10.001" )
55
92
assert instance .pythonvalue ("-10.001" ) == D ("-10.001" )
93
+ assert instance .pythonvalue (" \r \n 10 \t " ) == D ("10" )
56
94
57
95
58
96
class TestFloat :
@@ -74,6 +112,7 @@ def test_pythonvalue(self):
74
112
assert instance .pythonvalue ("-0" ) == float (0 )
75
113
assert instance .pythonvalue ("0" ) == float (0 )
76
114
assert instance .pythonvalue ("INF" ) == float ("inf" )
115
+ assert instance .pythonvalue ("\t \r 12.78e-2\n " ) == float ("0.1278" )
77
116
78
117
79
118
class TestDouble :
@@ -89,6 +128,7 @@ def test_pythonvalue(self):
89
128
assert instance .pythonvalue ("12" ) == float (12 )
90
129
assert instance .pythonvalue ("-0" ) == float (0 )
91
130
assert instance .pythonvalue ("0" ) == float (0 )
131
+ assert instance .pythonvalue (" \r \n 0 \t " ) == float (0 )
92
132
93
133
94
134
class TestDuration :
@@ -103,6 +143,10 @@ def test_pythonvalue(self):
103
143
value = "P0Y1347M0D"
104
144
assert instance .pythonvalue (value ) == expected
105
145
146
+ expected = isodate .parse_duration ("P0Y1347M0D" )
147
+ value = "\r \n P0Y1347M0D\t "
148
+ assert instance .pythonvalue (value ) == expected
149
+
106
150
107
151
class TestDateTime :
108
152
def test_xmlvalue (self ):
@@ -137,6 +181,9 @@ def test_pythonvalue(self):
137
181
value = datetime .datetime (2016 , 3 , 4 , 0 , 0 , 0 )
138
182
assert instance .pythonvalue ("2016-03-04" ) == value
139
183
184
+ value = datetime .datetime (2016 , 3 , 4 , 0 , 0 , 0 )
185
+ assert instance .pythonvalue (" \r \n \t 2016-03-04 " ) == value
186
+
140
187
def test_pythonvalue_invalid (self ):
141
188
instance = builtins .DateTime ()
142
189
with pytest .raises (ValueError ):
@@ -161,6 +208,9 @@ def test_pythonvalue(self):
161
208
value = isodate .parse_time ("21:14:42.120+0200" )
162
209
assert instance .pythonvalue ("21:14:42.120+0200" ) == value
163
210
211
+ value = datetime .time (21 , 14 , 42 )
212
+ assert instance .pythonvalue ("\t \r \n 21:14:42 " ) == value
213
+
164
214
def test_pythonvalue_invalid (self ):
165
215
instance = builtins .Time ()
166
216
with pytest .raises (ValueError ):
@@ -181,6 +231,7 @@ def test_pythonvalue(self):
181
231
assert instance .pythonvalue ("2001-10-26+02:00" ) == datetime .date (2001 , 10 , 26 )
182
232
assert instance .pythonvalue ("2001-10-26Z" ) == datetime .date (2001 , 10 , 26 )
183
233
assert instance .pythonvalue ("2001-10-26+00:00" ) == datetime .date (2001 , 10 , 26 )
234
+ assert instance .pythonvalue ("\r \n \t 2016-03-04 " ) == datetime .date (2016 , 3 , 4 )
184
235
185
236
def test_pythonvalue_invalid (self ):
186
237
instance = builtins .Date ()
@@ -218,8 +269,8 @@ def test_pythonvalue(self):
218
269
class TestgYear :
219
270
def test_xmlvalue (self ):
220
271
instance = builtins .gYear ()
221
- instance .xmlvalue ((2001 , None )) == "2001"
222
- instance .xmlvalue ((2001 , pytz .utc )) == "2001Z"
272
+ assert instance .xmlvalue ((2001 , None )) == "2001"
273
+ assert instance .xmlvalue ((2001 , pytz .utc )) == "2001Z"
223
274
224
275
def test_pythonvalue (self ):
225
276
instance = builtins .gYear ()
@@ -229,6 +280,7 @@ def test_pythonvalue(self):
229
280
assert instance .pythonvalue ("2001+00:00" ) == (2001 , pytz .utc )
230
281
assert instance .pythonvalue ("-2001" ) == (- 2001 , None )
231
282
assert instance .pythonvalue ("-20000" ) == (- 20000 , None )
283
+ assert instance .pythonvalue (" \t 2001+02:00\r \n " ) == (2001 , pytz .FixedOffset (120 ))
232
284
233
285
with pytest .raises (builtins .ParseError ):
234
286
assert instance .pythonvalue ("99" )
@@ -247,6 +299,7 @@ def test_pythonvalue(self):
247
299
assert instance .pythonvalue ("--11-01-04:00" ) == (11 , 1 , pytz .FixedOffset (- 240 ))
248
300
assert instance .pythonvalue ("--11-15" ) == (11 , 15 , None )
249
301
assert instance .pythonvalue ("--02-29" ) == (2 , 29 , None )
302
+ assert instance .pythonvalue ("\t \r \n --05-01 " ) == (5 , 1 , None )
250
303
251
304
with pytest .raises (builtins .ParseError ):
252
305
assert instance .pythonvalue ("99" )
@@ -265,6 +318,7 @@ def test_pythonvalue(self):
265
318
assert instance .pythonvalue ("--11-04:00" ) == (11 , pytz .FixedOffset (- 240 ))
266
319
assert instance .pythonvalue ("--11" ) == (11 , None )
267
320
assert instance .pythonvalue ("--02" ) == (2 , None )
321
+ assert instance .pythonvalue ("\n \t --11Z \r " ) == (11 , pytz .utc )
268
322
269
323
with pytest .raises (builtins .ParseError ):
270
324
assert instance .pythonvalue ("99" )
@@ -291,6 +345,7 @@ def test_pythonvalue(self):
291
345
assert instance .pythonvalue ("---01-04:00" ) == (1 , pytz .FixedOffset (- 240 ))
292
346
assert instance .pythonvalue ("---15" ) == (15 , None )
293
347
assert instance .pythonvalue ("---31" ) == (31 , None )
348
+ assert instance .pythonvalue ("\r \n \t ---31 " ) == (31 , None )
294
349
with pytest .raises (builtins .ParseError ):
295
350
assert instance .pythonvalue ("99" )
296
351
0 commit comments