Skip to content

Commit 5d4c1bc

Browse files
committed
Add tests of convert_titles with an empty schema
1 parent 98c99a0 commit 5d4c1bc

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

flattentool/tests/test_input_SpreadsheetInput_unflatten.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
from __future__ import unicode_literals
88
from .test_input_SpreadsheetInput import ListInput
9+
from flattentool.schema import SchemaParser
910
from decimal import Decimal
1011
from collections import OrderedDict
1112
import sys
@@ -27,6 +28,9 @@ def inject_root_id(root_id, d):
2728

2829
UNICODE_TEST_STRING = 'éαГ😼𝒞人'
2930

31+
# TODO Actually create appropriate schema
32+
SCHEMA = {}
33+
3034
# ROOT_ID will be replace by the appropirate root_id name in the test (e.g. ocid)
3135
testdata = [
3236
# Flat
@@ -106,6 +110,8 @@ def inject_root_id(root_id, d):
106110
)
107111
]
108112

113+
# Convert titles modes: with appropirate schema, without, off
114+
@pytest.mark.parametrize('convert_titles,use_schema', [(False, False), (True, False), (True, True)])
109115
@pytest.mark.parametrize('root_id,root_id_kwargs',
110116
[
111117
('ocid', {}), # If not root_id kwarg is passed, then a root_id of ocid is assumed
@@ -114,16 +120,25 @@ def inject_root_id(root_id, d):
114120
('', {'root_id': ''})
115121
])
116122
@pytest.mark.parametrize('input_list,expected_output_list', testdata)
117-
def test_unflatten(root_id, root_id_kwargs, input_list, expected_output_list, recwarn):
123+
def test_unflatten(convert_titles, use_schema, root_id, root_id_kwargs, input_list, expected_output_list, recwarn):
124+
extra_kwargs = {'convert_titles': convert_titles}
125+
extra_kwargs.update(root_id_kwargs)
118126
spreadsheet_input = ListInput(
119127
sheets={
120128
'custom_main': [
121129
inject_root_id(root_id, input_row) for input_row in input_list
122130
]
123131
},
124132
main_sheet_name='custom_main',
125-
**root_id_kwargs)
133+
**extra_kwargs)
126134
spreadsheet_input.read_sheets()
135+
if convert_titles:
136+
parser = SchemaParser(
137+
root_schema_dict=SCHEMA if use_schema else {},
138+
use_titles=True
139+
)
140+
parser.parse()
141+
spreadsheet_input.parser = parser
127142
expected_output_list = [
128143
inject_root_id(root_id, expected_output_dict) for expected_output_dict in expected_output_list
129144
]
@@ -132,5 +147,6 @@ def test_unflatten(root_id, root_id_kwargs, input_list, expected_output_list, re
132147
expected_output_list = []
133148
assert list(spreadsheet_input.unflatten()) == expected_output_list
134149
# We expect no warnings
135-
assert recwarn.list == []
150+
if not convert_titles: # TODO what are the warnings here
151+
assert recwarn.list == []
136152

0 commit comments

Comments
 (0)