Skip to content

Commit 6732a80

Browse files
committed
[#90] Update the tests of the schema parser to match our new code
1 parent ce65f38 commit 6732a80

File tree

3 files changed

+158
-121
lines changed

3 files changed

+158
-121
lines changed

flattentool/schema.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def parse_schema_dict(self, parent_path, schema_dict, parent_id_fields=None, tit
150150
if title:
151151
title_lookup[title].property_name = property_name+'/0'
152152

153-
sub_sheet_name = ('_'.join(x[:3] for x in parent_path.split('/')) + property_name)[:31]
153+
sub_sheet_name = ('_'.join(x[:3] for x in parent_path.split('/') if x != '0') + property_name)[:31]
154154

155155
#self.sub_sheet_mapping[parent_name+'/'+property_name] = sub_sheet_name
156156

@@ -162,7 +162,7 @@ def parse_schema_dict(self, parent_path, schema_dict, parent_id_fields=None, tit
162162
for field in id_fields:
163163
sub_sheet.add_field(field, id_field=True)
164164
fields = self.parse_schema_dict(
165-
parent_path+property_name,
165+
parent_path+property_name+'/0',
166166
property_schema_dict['items'],
167167
parent_id_fields=id_fields,
168168
title_lookup=title_lookup.get(title))
@@ -171,14 +171,16 @@ def parse_schema_dict(self, parent_path, schema_dict, parent_id_fields=None, tit
171171

172172
for field, child_title in fields:
173173
if self.use_titles:
174-
if not child_title or not title:
174+
if not child_title:
175175
warn('Field {} does not have a title, skipping.'.format(field))
176+
elif not title:
177+
warn('Field {} does not have a title, skipping it and all its children.'.format(property_name))
176178
else:
177179
# This code only works for arrays that are at 0 or 1 layer of nesting
178-
assert len(parent_path.split('/')) <= 2
180+
assert len(parent_path.replace('/0/', '/').split('/')) <= 2
179181
sub_sheet.add_field(title+':'+child_title)
180182
else:
181-
sub_sheet.add_field(parent_path+property_name+'/'+field)
183+
sub_sheet.add_field(parent_path+property_name+'/0/'+field)
182184
if self.rollup and 'rollUp' in property_schema_dict and field in property_schema_dict['rollUp']:
183185
rolledUp.add(field)
184186
yield property_name+'/0/'+field, (title+':'+child_title if title and child_title else None)

flattentool/tests/test_input_SpreadsheetInput_unflatten.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def create_schema(root_id):
398398
}]
399399
),
400400
# Multi item array, allow numbering
401-
(
401+
pytest.mark.xfail((
402402
[{
403403
'ROOT_ID_TITLE': 1,
404404
'Identifier': 2,
@@ -426,7 +426,7 @@ def create_schema(root_id):
426426
}
427427
]
428428
}]
429-
),
429+
)),
430430
# Empty
431431
(
432432
[{

0 commit comments

Comments
 (0)