Skip to content

Commit 748613d

Browse files
committed
Now only run unit tests involving numpy and pandas if those packages are installed
Also: - numpy and pandas no longer installed by tox on Python 3.4 (installed for all other Python versions) - This is to fix a crazy slow install time on Python 3.4 and to also hopefully to increase code coverage
1 parent d30428d commit 748613d

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

tests/test_data_types.py

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
Unit testing the variety of data types supported by tableformatter.
44
"""
55
from collections import OrderedDict
6-
import numpy as np
7-
import pandas as pd
86
import tableformatter as tf
97

108

@@ -26,22 +24,15 @@
2624

2725
iteralbe_of_iterables = [[1, 2, 3, 4],
2826
[5, 6, 7, 8]]
29-
np_2d_array = np.array(iteralbe_of_iterables)
3027
d = {'col1': [1, 5], 'col2': [2, 6], 'col3': [3, 7], 'col4': [4, 8]}
3128
od = OrderedDict(sorted(d.items(), key=lambda t: t[0]))
32-
df = pd.DataFrame(data=od)
3329

3430

3531
def test_iterable_of_iterables():
3632
table = tf.generate_table(iteralbe_of_iterables)
3733
assert table == EXPECTED_BASIC
3834

3935

40-
def test_numpy_2d_array():
41-
table = tf.generate_table(np_2d_array)
42-
assert table == EXPECTED_BASIC
43-
44-
4536
def test_iterable_of_dicts():
4637
d1 = {1: 'a', 2: 'b', 3: 'c', 4: 'd'}
4738
d2 = {5: 'e', 6: 'f', 7: 'g', 8: 'h'}
@@ -51,27 +42,6 @@ def test_iterable_of_dicts():
5142
assert table == EXPECTED_BASIC
5243

5344

54-
def test_numpy_record_array():
55-
np_rec_array = np.rec.array([(1, 2., 'Hello'),
56-
(2, 3., "World")],
57-
dtype=[('foo', 'i4'), ('bar', 'f4'), ('baz', 'U10')])
58-
table = tf.generate_table(np_rec_array)
59-
expected = '''
60-
╔═════╤═════╤═══════╗
61-
║ foo │ bar │ baz ║
62-
╠═════╪═════╪═══════╣
63-
║ 1 │ 2.0 │ Hello ║
64-
║ 2 │ 3.0 │ World ║
65-
╚═════╧═════╧═══════╝
66-
'''.lstrip('\n')
67-
assert table == expected
68-
69-
70-
def test_pandas_dataframe():
71-
table = tf.generate_table(df)
72-
assert table == EXPECTED_WITH_HEADERS
73-
74-
7545
def test_dict_of_iterables():
7646
table = tf.generate_table(od)
7747
assert table == EXPECTED_WITH_HEADERS
@@ -99,3 +69,41 @@ def test_iterable_of_non_iterable_objects():
9969
tf.Column('col4', attrib='field4'))
10070
table = tf.generate_table(rows, columns)
10171
assert table == EXPECTED_WITH_HEADERS
72+
73+
74+
try:
75+
import numpy as np
76+
except ImportError:
77+
pass
78+
else:
79+
np_2d_array = np.array(iteralbe_of_iterables)
80+
81+
def test_numpy_2d_array():
82+
table = tf.generate_table(np_2d_array)
83+
assert table == EXPECTED_BASIC
84+
85+
def test_numpy_record_array():
86+
np_rec_array = np.rec.array([(1, 2., 'Hello'),
87+
(2, 3., "World")],
88+
dtype=[('foo', 'i4'), ('bar', 'f4'), ('baz', 'U10')])
89+
table = tf.generate_table(np_rec_array)
90+
expected = '''
91+
╔═════╤═════╤═══════╗
92+
║ foo │ bar │ baz ║
93+
╠═════╪═════╪═══════╣
94+
║ 1 │ 2.0 │ Hello ║
95+
║ 2 │ 3.0 │ World ║
96+
╚═════╧═════╧═══════╝
97+
'''.lstrip('\n')
98+
assert table == expected
99+
100+
try:
101+
import pandas as pd
102+
except ImportError:
103+
pass
104+
else:
105+
df = pd.DataFrame(data=od)
106+
107+
def test_pandas_dataframe():
108+
table = tf.generate_table(df)
109+
assert table == EXPECTED_WITH_HEADERS

tox.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ setenv =
1212
[testenv:py34]
1313
deps =
1414
codecov
15-
numpy
16-
pandas
1715
pytest
1816
pytest-cov
1917
commands =

0 commit comments

Comments
 (0)