Skip to content

Commit 9f911c8

Browse files
committed
[#77] Start writing a schema for titles tests
1 parent f14643f commit 9f911c8

File tree

1 file changed

+67
-26
lines changed

1 file changed

+67
-26
lines changed

flattentool/tests/test_input_SpreadsheetInput_unflatten.py

Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ def inject_root_id(root_id, d):
3737
return d
3838

3939

40-
# TODO Actually create appropriate schema
41-
SCHEMA = {}
42-
4340
UNICODE_TEST_STRING = 'éαГ😼𝒞人'
4441
# ROOT_ID will be replace by the appropirate root_id name in the test (e.g. ocid)
4542

@@ -141,52 +138,92 @@ def inject_root_id(root_id, d):
141138
)
142139
]
143140

141+
def create_schema(root_id):
142+
schema = {
143+
'properties': {
144+
'id': {
145+
'title': 'Identifier',
146+
'type': 'integer',
147+
},
148+
'testA': {
149+
'title': 'A title',
150+
'type': 'integer',
151+
},
152+
'testB': {
153+
'title': 'B title',
154+
'type': 'object',
155+
'properties': {
156+
'testC': {
157+
'title': 'C title',
158+
'type': 'integer',
159+
},
160+
'testD': {
161+
'title': 'D title',
162+
'type': 'integer',
163+
}
164+
}
165+
},
166+
'testU': {
167+
'title': UNICODE_TEST_STRING,
168+
'type': 'string',
169+
},
170+
}
171+
}
172+
if root_id:
173+
schema.update({
174+
root_id: {
175+
'title': ROOT_ID_TITLES[root_id],
176+
'type': 'string'
177+
}
178+
})
179+
return schema
180+
144181
testdata_titles = [
145182
# Basic flat
146-
pytest.mark.xfail((
183+
(
147184
[{
148-
'ROOT_ID': 1,
185+
'ROOT_ID_TITLE': 1,
149186
'Identifier': 2,
150-
'testA': 3
187+
'A title': 3
151188
}],
152189
[{
153-
'ROOT_ID': 1,
154-
'id': 2,
155-
'testA': 3
190+
'ROOT_ID': 1,
191+
'id': 2,
192+
'testA': 3
156193
}]
157-
)),
194+
),
158195
# Nested
159196
pytest.mark.xfail((
160197
[{
161-
'ROOT_ID': 1,
198+
'ROOT_ID_TITLE': 1,
162199
'id': 2,
163-
'testA/testB': 3,
164-
'testA/testC': 4,
200+
'B title:C title': 3,
201+
'B title:C title': 4,
165202
}],
166203
[{
167204
'ROOT_ID': 1,
168205
'id': 2,
169-
'testA': {'testB': 3, 'testC': 4}
206+
'testB': {'testC': 3, 'testD': 4}
170207
}]
171208
)),
172209
# Unicode
173210
pytest.mark.xfail((
174211
[{
175-
'ROOT_ID': UNICODE_TEST_STRING,
176-
'testA': UNICODE_TEST_STRING
212+
'ROOT_ID_TITLE': UNICODE_TEST_STRING,
213+
'UNICODE_TEST_STRING': UNICODE_TEST_STRING
177214
}],
178215
[{
179216
'ROOT_ID': UNICODE_TEST_STRING,
180-
'testA': UNICODE_TEST_STRING
217+
'testU': UNICODE_TEST_STRING
181218
}]
182219
)),
183220
# Rollup
184221
pytest.mark.xfail((
185222
[{
186-
'ROOT_ID': 1,
223+
'ROOT_ID_TITLE': 1,
187224
'id': 2,
188-
'testA[]/id': 3,
189-
'testA[]/testB': 4
225+
'A title:Identifier': 3,
226+
'A title:B title': 4
190227
}],
191228
[{
192229
'ROOT_ID': 1, 'id': 2, 'testA': [{
@@ -197,9 +234,9 @@ def inject_root_id(root_id, d):
197234
# Rollup without an ID
198235
pytest.mark.xfail((
199236
[{
200-
'ROOT_ID': '1',
201-
'testA[]/id': '2',
202-
'testA[]/testB': '3',
237+
'ROOT_ID_TITLE': '1',
238+
'A title:Identifier': 2,
239+
'A title:B title': 3
203240
}],
204241
[{
205242
'ROOT_ID': '1',
@@ -223,7 +260,7 @@ def inject_root_id(root_id, d):
223260
[]
224261
),
225262
# Empty except for root id
226-
pytest.mark.xfail((
263+
(
227264
[{
228265
'ROOT_ID_TITLE': 1,
229266
'Identifier': '',
@@ -236,7 +273,7 @@ def inject_root_id(root_id, d):
236273
[{
237274
'ROOT_ID': 1
238275
}]
239-
))
276+
)
240277
]
241278

242279
ROOT_ID_PARAMS = [
@@ -267,7 +304,7 @@ def test_unflatten(convert_titles, use_schema, root_id, root_id_kwargs, input_li
267304
spreadsheet_input.read_sheets()
268305
if convert_titles:
269306
parser = SchemaParser(
270-
root_schema_dict=SCHEMA if use_schema else {},
307+
root_schema_dict=create_schema(root_id) if use_schema else {},
271308
use_titles=True
272309
)
273310
parser.parse()
@@ -292,6 +329,10 @@ def test_unflatten_titles(root_id, root_id_kwargs, input_list, expected_output_l
292329
use_schema are always true, as both of these are needed to convert titles
293330
properly. (and runs with different test data).
294331
"""
332+
if root_id != '':
333+
# Skip all tests with a root ID for now, as this is broken
334+
# https://github.com/OpenDataServices/flatten-tool/issues/84
335+
pytest.skip()
295336
return test_unflatten(convert_titles=True, use_schema=True, root_id=root_id, root_id_kwargs=root_id_kwargs, input_list=input_list, expected_output_list=expected_output_list, recwarn=recwarn)
296337

297338

0 commit comments

Comments
 (0)