Mercurial > hg > Lemuriformes
comparison tests/test_json2csv.py @ 18:56596902e9ae default tip
add some setup + tests
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 10 Dec 2017 17:57:03 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
17:4793f99b73e0 | 18:56596902e9ae |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 """ | |
4 test JSON to CSV conversion | |
5 """ | |
6 | |
7 import unittest | |
8 from lemuriformes import json2csv | |
9 | |
10 | |
11 class TestJSON2CSV(unittest.TestCase): | |
12 | |
13 def test_flatten(self): | |
14 data = [{'a': 'B', 'c': 1, 'd': 'd'}, | |
15 {'a': 'a', 'c': 2, 'd': 'e'}, | |
16 {'a': 'H', 'c': 3, 'd': 'I'}, | |
17 {'a': 'K', 'c': 5, 'd': 'L'}, | |
18 ] | |
19 header = ['a', 'c', 'd'] | |
20 expected = [['B', 1, 'd'], | |
21 ['a', 2, 'e'], | |
22 ['H', 3, 'I'], | |
23 ['K', 5, 'L'], | |
24 ] | |
25 | |
26 received_header, flattened = json2csv.flatten_list_of_dicts(data, header=header) | |
27 assert flattened == expected | |
28 assert received_header == header | |
29 | |
30 if __name__ == '__main__': | |
31 unittest.main() |