6
6
"""
7
7
from __future__ import unicode_literals
8
8
9
+ import datetime
9
10
from collections import OrderedDict
10
11
from decimal import Decimal
11
12
@@ -48,6 +49,7 @@ def inject_root_id(root_id, d):
48
49
[{"ROOT_ID" : "1" , "id" : 2 , "testA" : 3 }],
49
50
[],
50
51
True ,
52
+ True ,
51
53
),
52
54
(
53
55
"Basic with float" ,
@@ -58,41 +60,63 @@ def inject_root_id(root_id, d):
58
60
[{"ROOT_ID" : "1" , "id" : 2 , "testA" : 3 }],
59
61
[],
60
62
True ,
63
+ True ,
61
64
),
62
65
(
63
66
"Basic with zero" ,
64
67
[{"ROOT_ID" : "1" , "id" : 2 , "testA" : 0 }],
65
68
[{"ROOT_ID" : "1" , "id" : 2 , "testA" : 0 }],
66
69
[],
67
70
True ,
71
+ True ,
72
+ ),
73
+ (
74
+ "Basic with date-time" ,
75
+ [{"ROOT_ID" : "1" , "id" : 2 , "testDateTime" : datetime .datetime (2020 , 1 , 1 )}],
76
+ [{"ROOT_ID" : "1" , "id" : 2 , "testDateTime" : "2020-01-01T00:00:00+00:00" }],
77
+ [],
78
+ False ,
79
+ True ,
80
+ ),
81
+ (
82
+ "Basic with date" ,
83
+ [{"ROOT_ID" : "1" , "id" : 2 , "testDate" : datetime .datetime (2020 , 1 , 1 )}],
84
+ [{"ROOT_ID" : "1" , "id" : 2 , "testDate" : "2020-01-01" }],
85
+ [],
86
+ False ,
87
+ False ,
68
88
),
69
89
(
70
90
"Nested" ,
71
91
[{"ROOT_ID" : "1" , "id" : 2 , "testO/testB" : 3 , "testO/testC" : 4 ,}],
72
92
[{"ROOT_ID" : "1" , "id" : 2 , "testO" : {"testB" : 3 , "testC" : 4 }}],
73
93
[],
74
94
True ,
95
+ True ,
75
96
),
76
97
(
77
98
"Unicode" ,
78
99
[{"ROOT_ID" : UNICODE_TEST_STRING , "testU" : UNICODE_TEST_STRING }],
79
100
[{"ROOT_ID" : UNICODE_TEST_STRING , "testU" : UNICODE_TEST_STRING }],
80
101
[],
81
102
True ,
103
+ True ,
82
104
),
83
105
(
84
106
"Single item array" ,
85
107
[{"ROOT_ID" : "1" , "id" : 2 , "testL/0/id" : 3 , "testL/0/testB" : 4 }],
86
108
[{"ROOT_ID" : "1" , "id" : 2 , "testL" : [{"id" : 3 , "testB" : 4 }],}],
87
109
[],
88
110
False ,
111
+ True ,
89
112
),
90
113
(
91
114
"Single item array without parent ID" ,
92
115
[{"ROOT_ID" : "1" , "testL/0/id" : "2" , "testL/0/testB" : "3" ,}],
93
116
[{"ROOT_ID" : "1" , "testL" : [{"id" : "2" , "testB" : "3" }],}],
94
117
[],
95
118
False ,
119
+ True ,
96
120
),
97
121
(
98
122
"Empty" ,
@@ -110,6 +134,7 @@ def inject_root_id(root_id, d):
110
134
[],
111
135
[],
112
136
False ,
137
+ True ,
113
138
),
114
139
(
115
140
"Empty except for root id" ,
@@ -127,6 +152,7 @@ def inject_root_id(root_id, d):
127
152
[{"ROOT_ID" : 1 }],
128
153
[],
129
154
False ,
155
+ True ,
130
156
),
131
157
# Previously this caused the error: TypeError: unorderable types: str() < int()
132
158
# Now one of the columns is ignored
@@ -142,6 +168,7 @@ def inject_root_id(root_id, d):
142
168
"Column newtest/0/a has been ignored, because it treats newtest as an array, but another column does not."
143
169
],
144
170
False ,
171
+ True ,
145
172
),
146
173
# Previously this caused the error: TypeError: unorderable types: str() < int()
147
174
# Now one of the columns is ignored
@@ -157,6 +184,7 @@ def inject_root_id(root_id, d):
157
184
"Column newtest/a has been ignored, because it treats newtest as an object, but another column does not."
158
185
],
159
186
False ,
187
+ True ,
160
188
),
161
189
# Previously this caused the error: 'Cell' object has no attribute 'get'
162
190
# Now one of the columns is ignored
@@ -168,6 +196,7 @@ def inject_root_id(root_id, d):
168
196
"Column newtest/0/a has been ignored, because it treats newtest as an array, but another column does not."
169
197
],
170
198
False ,
199
+ True ,
171
200
),
172
201
(
173
202
"str / object mixing" ,
@@ -177,6 +206,7 @@ def inject_root_id(root_id, d):
177
206
"Column newtest/a has been ignored, because it treats newtest as an object, but another column does not."
178
207
],
179
208
False ,
209
+ True ,
180
210
),
181
211
(
182
212
"array / str mixing" ,
@@ -195,6 +225,7 @@ def inject_root_id(root_id, d):
195
225
"Column nest/newtest has been ignored, because another column treats it as an array or object"
196
226
],
197
227
False ,
228
+ True ,
198
229
),
199
230
(
200
231
"object / str mixing" ,
@@ -204,6 +235,7 @@ def inject_root_id(root_id, d):
204
235
"Column newtest has been ignored, because another column treats it as an array or object"
205
236
],
206
237
False ,
238
+ True ,
207
239
),
208
240
(
209
241
"Mismatch of object/array for field not in schema (multiline)" ,
@@ -216,6 +248,7 @@ def inject_root_id(root_id, d):
216
248
"Column nest/newtest/0/a has been ignored, because it treats newtest as an array, but another column does not"
217
249
],
218
250
False ,
251
+ True ,
219
252
),
220
253
# Previously this caused the error: TypeError: unorderable types: str() < int()
221
254
# Now one of the columns is ignored
@@ -230,6 +263,7 @@ def inject_root_id(root_id, d):
230
263
"Column newtest/a has been ignored, because it treats newtest as an object, but another column does not"
231
264
],
232
265
False ,
266
+ True ,
233
267
),
234
268
# Previously this caused the error: 'Cell' object has no attribute 'get'
235
269
# Now one of the columns is ignored
@@ -252,6 +286,7 @@ def inject_root_id(root_id, d):
252
286
"Column nest/newtest/0/b has been ignored, because it treats newtest as an array, but another column does not" ,
253
287
],
254
288
False ,
289
+ True ,
255
290
),
256
291
(
257
292
"array / str mixing multiline" ,
@@ -265,6 +300,7 @@ def inject_root_id(root_id, d):
265
300
"Column nest/newtest has been ignored, because another column treats it as an array or object"
266
301
],
267
302
False ,
303
+ True ,
268
304
),
269
305
# WARNING: Conflict when merging field "newtest" for id "2" in sheet custom_main: "3"
270
306
(
@@ -281,6 +317,7 @@ def inject_root_id(root_id, d):
281
317
"Column newtest/b has been ignored, because it treats newtest as an object, but another column does not" ,
282
318
],
283
319
False ,
320
+ True ,
284
321
),
285
322
(
286
323
"object / str mixing multiline" ,
@@ -293,6 +330,7 @@ def inject_root_id(root_id, d):
293
330
"Column newtest has been ignored, because another column treats it as an array or object"
294
331
],
295
332
False ,
333
+ True ,
296
334
),
297
335
# Previously this caused the error: KeyError('ocid',)
298
336
# Now it works, but probably not as intended
@@ -304,6 +342,7 @@ def inject_root_id(root_id, d):
304
342
[{"id" : 2 , "testA" : 3 }],
305
343
[],
306
344
False ,
345
+ True ,
307
346
),
308
347
# We should be able to handle numbers as column headings
309
348
(
@@ -329,6 +368,7 @@ def inject_root_id(root_id, d):
329
368
'Column "4" has been ignored because it is a number.' ,
330
369
],
331
370
False ,
371
+ True ,
332
372
),
333
373
]
334
374
@@ -377,6 +417,8 @@ def create_schema(root_id):
377
417
"properties" : {
378
418
"id" : {"title" : "Identifier" , "type" : "integer" ,},
379
419
"testA" : {"title" : "A title" , "type" : "integer" ,},
420
+ "testDateTime" : {"type" : "string" , "format" : "date-time" ,},
421
+ "testDate" : {"type" : "string" , "format" : "date" },
380
422
"testB" : {
381
423
"title" : "B title" ,
382
424
"type" : "object" ,
@@ -685,7 +727,8 @@ def create_schema(root_id):
685
727
@pytest .mark .parametrize ("use_schema" , [True , False ])
686
728
@pytest .mark .parametrize ("root_id,root_id_kwargs" , ROOT_ID_PARAMS )
687
729
@pytest .mark .parametrize (
688
- "comment,input_list,expected_output_list,warning_messages,reversible" , testdata
730
+ "comment,input_list,expected_output_list,warning_messages,reversible,works_without_schema" ,
731
+ testdata ,
689
732
)
690
733
def test_unflatten (
691
734
convert_titles ,
@@ -698,7 +741,11 @@ def test_unflatten(
698
741
comment ,
699
742
warning_messages ,
700
743
reversible ,
744
+ works_without_schema ,
701
745
):
746
+ if not use_schema and not works_without_schema :
747
+ pytest .skip ()
748
+
702
749
# Not sure why, but this seems to be necessary to have warnings picked up
703
750
# on Python 2.7 and 3.3, but 3.4 and 3.5 are fine without it
704
751
import warnings
@@ -764,6 +811,7 @@ def test_unflatten_pointer(
764
811
comment = comment ,
765
812
warning_messages = warning_messages ,
766
813
reversible = False ,
814
+ works_without_schema = True ,
767
815
)
768
816
769
817
@@ -802,4 +850,5 @@ def test_unflatten_titles(
802
850
comment = comment ,
803
851
warning_messages = warning_messages ,
804
852
reversible = reversible ,
853
+ works_without_schema = True ,
805
854
)
0 commit comments