6
6
"""
7
7
from __future__ import unicode_literals
8
8
from .test_input_SpreadsheetInput import ListInput
9
+ from flattentool .schema import SchemaParser
9
10
from decimal import Decimal
10
11
from collections import OrderedDict
11
12
import sys
@@ -27,6 +28,9 @@ def inject_root_id(root_id, d):
27
28
28
29
UNICODE_TEST_STRING = 'éαГ😼𝒞人'
29
30
31
+ # TODO Actually create appropriate schema
32
+ SCHEMA = {}
33
+
30
34
# ROOT_ID will be replace by the appropirate root_id name in the test (e.g. ocid)
31
35
testdata = [
32
36
# Flat
@@ -106,6 +110,8 @@ def inject_root_id(root_id, d):
106
110
)
107
111
]
108
112
113
+ # Convert titles modes: with appropirate schema, without, off
114
+ @pytest .mark .parametrize ('convert_titles,use_schema' , [(False , False ), (True , False ), (True , True )])
109
115
@pytest .mark .parametrize ('root_id,root_id_kwargs' ,
110
116
[
111
117
('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):
114
120
('' , {'root_id' : '' })
115
121
])
116
122
@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 )
118
126
spreadsheet_input = ListInput (
119
127
sheets = {
120
128
'custom_main' : [
121
129
inject_root_id (root_id , input_row ) for input_row in input_list
122
130
]
123
131
},
124
132
main_sheet_name = 'custom_main' ,
125
- ** root_id_kwargs )
133
+ ** extra_kwargs )
126
134
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
127
142
expected_output_list = [
128
143
inject_root_id (root_id , expected_output_dict ) for expected_output_dict in expected_output_list
129
144
]
@@ -132,5 +147,6 @@ def test_unflatten(root_id, root_id_kwargs, input_list, expected_output_list, re
132
147
expected_output_list = []
133
148
assert list (spreadsheet_input .unflatten ()) == expected_output_list
134
149
# We expect no warnings
135
- assert recwarn .list == []
150
+ if not convert_titles : # TODO what are the warnings here
151
+ assert recwarn .list == []
136
152
0 commit comments