|
2 | 2 | import json
|
3 | 3 | import pytest
|
4 | 4 | import sys
|
| 5 | +import os |
5 | 6 |
|
6 | 7 |
|
7 | 8 | @pytest.mark.parametrize('output_format', ['xlsx', 'csv'])
|
@@ -58,3 +59,37 @@ def test_roundtrip_360(tmpdir, output_format, use_titles):
|
58 | 59 | roundtripped_json = json.load(tmpdir.join('roundtrip.json'))
|
59 | 60 |
|
60 | 61 | 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