Skip to content

Commit 4bcf260

Browse files
committed
Pass comment strings to the parameterized unflatten tests
This means that pytest will show the comment string when a test fails, which makes it easier to find what failed in the test file.
1 parent 6732a80 commit 4bcf260

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

flattentool/tests/test_input_SpreadsheetInput_unflatten.py

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def inject_root_id(root_id, d):
4141
# ROOT_ID will be replace by the appropirate root_id name in the test (e.g. ocid)
4242

4343
testdata = [
44-
# Basic flat
4544
(
45+
'Basic flat',
4646
[{
4747
'ROOT_ID': '1',
4848
'id': 2,
@@ -54,8 +54,8 @@ def inject_root_id(root_id, d):
5454
'testA': 3
5555
}]
5656
),
57-
# Nested
5857
(
58+
'Nested',
5959
[{
6060
'ROOT_ID': '1',
6161
'id': 2,
@@ -68,8 +68,8 @@ def inject_root_id(root_id, d):
6868
'testO': {'testB': 3, 'testC': 4}
6969
}]
7070
),
71-
# Unicode
7271
(
72+
'Unicode',
7373
[{
7474
'ROOT_ID': UNICODE_TEST_STRING,
7575
'testU': UNICODE_TEST_STRING
@@ -79,8 +79,8 @@ def inject_root_id(root_id, d):
7979
'testU': UNICODE_TEST_STRING
8080
}]
8181
),
82-
# Single item array
8382
(
83+
'Single item array',
8484
[{
8585
'ROOT_ID': '1',
8686
'id': 2,
@@ -93,8 +93,8 @@ def inject_root_id(root_id, d):
9393
}]
9494
}]
9595
),
96-
# Single item array withou parent ID
9796
(
97+
'Single item array without parent ID',
9898
[{
9999
'ROOT_ID': '1',
100100
'testL/0/id': '2',
@@ -108,8 +108,8 @@ def inject_root_id(root_id, d):
108108
}]
109109
}]
110110
),
111-
# Empty
112111
(
112+
'Empty',
113113
[{
114114
'ROOT_ID': '',
115115
'id': '',
@@ -121,8 +121,8 @@ def inject_root_id(root_id, d):
121121
}],
122122
[]
123123
),
124-
# Empty except for root id
125124
(
125+
'Empty except for root id',
126126
[{
127127
'ROOT_ID': 1,
128128
'id': '',
@@ -139,8 +139,8 @@ def inject_root_id(root_id, d):
139139
]
140140

141141
testdata_pointer = [
142-
# Single item array without json numbering
143142
(
143+
'Single item array without json numbering',
144144
[{
145145
'ROOT_ID': '1',
146146
'testR/id': '2',
@@ -156,8 +156,8 @@ def inject_root_id(root_id, d):
156156
}]
157157
}]
158158
),
159-
# Multi item array one with varied numbering
160159
(
160+
'Multi item array one with varied numbering ',
161161
[{
162162
'ROOT_ID': '1',
163163
'testR/id': '-1',
@@ -265,8 +265,8 @@ def create_schema(root_id):
265265
return schema
266266

267267
testdata_titles = [
268-
# Basic flat
269268
(
269+
'Basic flat',
270270
[{
271271
'ROOT_ID_TITLE': 1,
272272
'Identifier': 2,
@@ -278,8 +278,8 @@ def create_schema(root_id):
278278
'testA': 3
279279
}]
280280
),
281-
# Nested
282281
(
282+
'Nested',
283283
[{
284284
'ROOT_ID_TITLE': 1,
285285
'Identifier': 2,
@@ -292,8 +292,8 @@ def create_schema(root_id):
292292
'testB': {'testC': 3, 'testD': 4}
293293
}]
294294
),
295-
# Nested titles should be converted individually
296295
(
296+
'Nested titles should be converted individually',
297297
[{
298298
'ROOT_ID_TITLE': 1,
299299
'Identifier': 2,
@@ -306,8 +306,8 @@ def create_schema(root_id):
306306
'testB': {'testC': 3, 'Not in schema': 4}
307307
}]
308308
),
309-
# Should be space and case invariant
310309
(
310+
'Should be space and case invariant',
311311
[{
312312
'ROOT_ID_TITLE': 1,
313313
'Identifier': 2,
@@ -320,8 +320,8 @@ def create_schema(root_id):
320320
'testB': {'testC': 3, 'Not in schema': 4}
321321
}]
322322
),
323-
# Unicode
324323
(
324+
'Unicode',
325325
[{
326326
'ROOT_ID_TITLE': UNICODE_TEST_STRING,
327327
UNICODE_TEST_STRING: UNICODE_TEST_STRING
@@ -331,8 +331,8 @@ def create_schema(root_id):
331331
'testU': UNICODE_TEST_STRING
332332
}]
333333
),
334-
# Single item array
335334
(
335+
'Single item array',
336336
[{
337337
'ROOT_ID_TITLE': 1,
338338
'Identifier': 2,
@@ -347,8 +347,8 @@ def create_schema(root_id):
347347
}]
348348
}]
349349
),
350-
# Single item array without parent ID
351350
(
351+
'Single item array without parent ID',
352352
[{
353353
'ROOT_ID_TITLE': '1',
354354
'R title:Identifier': '2',
@@ -362,9 +362,11 @@ def create_schema(root_id):
362362
}]
363363
}]
364364
),
365-
# Properties of a single item array shouldn't need to be in rollUp list
366-
# for their titles to be converted
367365
(
366+
'''
367+
Properties of a single item array shouldn't need to be in rollUp list
368+
for their titles to be converted
369+
''',
368370
[{
369371
'ROOT_ID_TITLE': 1,
370372
'Identifier': 2,
@@ -380,8 +382,8 @@ def create_schema(root_id):
380382
}]
381383
}]
382384
),
383-
# Single item array, titles should be converted individually
384385
(
386+
'Single item array, titles should be converted individually',
385387
[{
386388
'ROOT_ID_TITLE': 1,
387389
'Identifier': 2,
@@ -397,8 +399,8 @@ def create_schema(root_id):
397399
}]
398400
}]
399401
),
400-
# Multi item array, allow numbering
401402
pytest.mark.xfail((
403+
'Multi item array, allow numbering',
402404
[{
403405
'ROOT_ID_TITLE': 1,
404406
'Identifier': 2,
@@ -427,8 +429,8 @@ def create_schema(root_id):
427429
]
428430
}]
429431
)),
430-
# Empty
431432
(
433+
'Empty',
432434
[{
433435
'ROOT_ID_TITLE': '',
434436
'Identifier': '',
@@ -440,8 +442,8 @@ def create_schema(root_id):
440442
}],
441443
[]
442444
),
443-
# Empty except for root id
444445
(
446+
'Empty except for root id',
445447
[{
446448
'ROOT_ID_TITLE': 1,
447449
'Identifier': '',
@@ -455,8 +457,8 @@ def create_schema(root_id):
455457
'ROOT_ID': 1
456458
}]
457459
),
458-
# Test arrays of strings
459460
(
461+
'Test arrays of strings (1 item)',
460462
[{
461463
'ROOT_ID_TITLE': 1,
462464
'Identifier': 2,
@@ -469,6 +471,7 @@ def create_schema(root_id):
469471
}]
470472
),
471473
(
474+
'Test arrays of strings (2 items)',
472475
[{
473476
'ROOT_ID_TITLE': 1,
474477
'Identifier': 2,
@@ -495,8 +498,8 @@ def create_schema(root_id):
495498
@pytest.mark.parametrize('convert_titles', [True, False])
496499
@pytest.mark.parametrize('use_schema', [True, False])
497500
@pytest.mark.parametrize('root_id,root_id_kwargs', ROOT_ID_PARAMS)
498-
@pytest.mark.parametrize('input_list,expected_output_list', testdata)
499-
def test_unflatten(convert_titles, use_schema, root_id, root_id_kwargs, input_list, expected_output_list, recwarn):
501+
@pytest.mark.parametrize('comment,input_list,expected_output_list', testdata)
502+
def test_unflatten(convert_titles, use_schema, root_id, root_id_kwargs, input_list, expected_output_list, recwarn, comment):
500503
extra_kwargs = {'convert_titles': convert_titles}
501504
extra_kwargs.update(root_id_kwargs)
502505
spreadsheet_input = ListInput(
@@ -532,14 +535,14 @@ def test_unflatten(convert_titles, use_schema, root_id, root_id_kwargs, input_li
532535

533536
@pytest.mark.parametrize('convert_titles', [True, False])
534537
@pytest.mark.parametrize('root_id,root_id_kwargs', ROOT_ID_PARAMS)
535-
@pytest.mark.parametrize('input_list,expected_output_list', testdata_pointer)
536-
def test_unflatten_pointer(convert_titles, root_id, root_id_kwargs, input_list, expected_output_list, recwarn):
537-
return test_unflatten(convert_titles=convert_titles, 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)
538+
@pytest.mark.parametrize('comment,input_list,expected_output_list', testdata_pointer)
539+
def test_unflatten_pointer(convert_titles, root_id, root_id_kwargs, input_list, expected_output_list, recwarn, comment):
540+
return test_unflatten(convert_titles=convert_titles, 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, comment=comment)
538541

539542

540-
@pytest.mark.parametrize('input_list,expected_output_list', testdata_titles)
543+
@pytest.mark.parametrize('comment,input_list,expected_output_list', testdata_titles)
541544
@pytest.mark.parametrize('root_id,root_id_kwargs', ROOT_ID_PARAMS)
542-
def test_unflatten_titles(root_id, root_id_kwargs, input_list, expected_output_list, recwarn):
545+
def test_unflatten_titles(root_id, root_id_kwargs, input_list, expected_output_list, recwarn, comment):
543546
"""
544547
Essentially the same as test unflatten, except that convert_titles and
545548
use_schema are always true, as both of these are needed to convert titles
@@ -549,6 +552,6 @@ def test_unflatten_titles(root_id, root_id_kwargs, input_list, expected_output_l
549552
# Skip all tests with a root ID for now, as this is broken
550553
# https://github.com/OpenDataServices/flatten-tool/issues/84
551554
pytest.skip()
552-
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)
555+
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, comment=comment)
553556

554557

0 commit comments

Comments
 (0)