Skip to content

Commit 6e7b89a

Browse files
committed
[#67] Add rollup roundtrip test
1 parent 8ae18d0 commit 6e7b89a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

flattentool/tests/test_roundtrip.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import pytest
44
import sys
5+
import os
56

67

78
@pytest.mark.parametrize('output_format', ['xlsx', 'csv'])
@@ -58,3 +59,37 @@ def test_roundtrip_360(tmpdir, output_format, use_titles):
5859
roundtripped_json = json.load(tmpdir.join('roundtrip.json'))
5960

6061
assert original_json == roundtripped_json
62+
63+
64+
@pytest.mark.parametrize('use_titles', [False, True])
65+
def test_roundtrip_360_rollup(tmpdir, use_titles):
66+
input_name = 'flattentool/tests/fixtures/WellcomeTrust-grants_fixed_2_grants.json'
67+
output_format = 'csv'
68+
output_name = tmpdir.join('flattened').strpath+'.'+output_format
69+
moved_name = tmpdir.mkdir('flattened_main_only').strpath
70+
71+
flatten(
72+
input_name=input_name,
73+
output_name=output_name,
74+
output_format=output_format,
75+
schema='flattentool/tests/fixtures/360-giving-schema.json',
76+
root_list_path='grants',
77+
root_id='',
78+
use_titles=use_titles,
79+
rollup=True,
80+
main_sheet_name='grants')
81+
82+
os.rename(output_name+'/grants.csv', moved_name+'/grants.csv')
83+
84+
unflatten(
85+
input_name=moved_name,
86+
output_name=tmpdir.join('roundtrip.json').strpath,
87+
input_format=output_format,
88+
schema='flattentool/tests/fixtures/360-giving-schema.json',
89+
root_list_path='grants',
90+
root_id='',
91+
convert_titles=use_titles)
92+
93+
original_json = json.load(open(input_name))
94+
roundtripped_json = json.load(tmpdir.join('roundtrip.json'))
95+
assert original_json == roundtripped_json

0 commit comments

Comments
 (0)