22"""
33Unit testing the variety of data types supported by tableformatter.
44"""
5+ from collections import OrderedDict
56import numpy as np
67import pandas as pd
78import tableformatter as tf
2728 [5 , 6 , 7 , 8 ]]
2829np_2d_array = np .array (iteralbe_of_iterables )
2930d = {'col1' : [1 , 5 ], 'col2' : [2 , 6 ], 'col3' : [3 , 7 ], 'col4' : [4 , 8 ]}
30- df = pd .DataFrame (data = d )
31+ od = OrderedDict (sorted (d .items (), key = lambda t : t [0 ]))
32+ df = pd .DataFrame (data = od )
3133
3234
3335def test_iterable_of_iterables ():
@@ -36,22 +38,23 @@ def test_iterable_of_iterables():
3638
3739
3840def test_numpy_2d_array ():
39- np_2d_array = np .array (iteralbe_of_iterables )
4041 table = tf .generate_table (np_2d_array )
4142 assert table == EXPECTED_BASIC
4243
4344
4445def test_iterable_of_dicts ():
45- iterable_of_dicts = [{1 : 'a' , 2 : 'b' , 3 : 'c' , 4 : 'd' },
46- {5 : 'e' , 6 : 'f' , 7 : 'g' , 8 : 'h' }]
46+ d1 = {1 : 'a' , 2 : 'b' , 3 : 'c' , 4 : 'd' }
47+ d2 = {5 : 'e' , 6 : 'f' , 7 : 'g' , 8 : 'h' }
48+ iterable_of_dicts = [OrderedDict (sorted (d1 .items (), key = lambda t : t [0 ])),
49+ OrderedDict (sorted (d2 .items (), key = lambda t : t [0 ]))]
4750 table = tf .generate_table (iterable_of_dicts )
4851 assert table == EXPECTED_BASIC
4952
5053
5154def test_numpy_record_array ():
5255 np_rec_array = np .rec .array ([(1 , 2. , 'Hello' ),
5356 (2 , 3. , "World" )],
54- dtype = [('foo' , 'i4' ), ('bar' , 'f4' ), ('baz' , 'U10' )])
57+ dtype = [('foo' , 'i4' ), ('bar' , 'f4' ), ('baz' , 'U10' )])
5558 table = tf .generate_table (np_rec_array )
5659 expected = '''
5760╔═════╤═════╤═══════╗
@@ -70,7 +73,7 @@ def test_pandas_dataframe():
7073
7174
7275def test_dict_of_iterables ():
73- table = tf .generate_table (d )
76+ table = tf .generate_table (od )
7477 assert table == EXPECTED_WITH_HEADERS
7578
7679
0 commit comments