Skip to content

Commit 93c1024

Browse files
committed
fix #833: marked tests to be skipped if a necessary optional dependency is missing
1 parent 8c15ffb commit 93c1024

File tree

5 files changed

+46
-19
lines changed

5 files changed

+46
-19
lines changed

larray/tests/common.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111
import xlwings as xw
1212
except ImportError:
1313
xw = None
14+
try:
15+
import tables
16+
except ImportError:
17+
tables = None
18+
try:
19+
import xlrd
20+
except ImportError:
21+
xlrd = None
22+
try:
23+
import xlsxwriter
24+
except ImportError:
25+
xlsxwriter = None
1426

1527
from larray import Array, isnan, asarray, Metadata
1628

@@ -134,6 +146,10 @@ def meta():
134146

135147

136148
needs_xlwings = pytest.mark.skipif(xw is None, reason="xlwings is required for this test")
149+
needs_pytables = pytest.mark.skipif(tables is None, reason="pytables is required for this test")
150+
needs_xlrd = pytest.mark.skipif(xlrd is None, reason="xlrd is required for this test")
151+
needs_xlsxwriter = pytest.mark.skipif(xlsxwriter is None, reason="xlsxwriter is required for this test")
152+
137153
needs_python35 = pytest.mark.skipif(sys.version_info < (3, 5), reason="Python 3.5 is required for this test")
138154
needs_python36 = pytest.mark.skipif(sys.version_info < (3, 6), reason="Python 3.6 is required for this test")
139155
needs_python37 = pytest.mark.skipif(sys.version_info < (3, 7), reason="Python 3.7 is required for this test")

larray/tests/test_array.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@
1010
import pandas as pd
1111
from collections import OrderedDict
1212

13-
try:
14-
import xlwings as xw
15-
except ImportError:
16-
xw = None
17-
18-
from larray.tests.common import (inputpath, assert_array_equal, assert_array_nan_equal, assert_larray_equiv,
19-
tmp_path, meta, needs_xlwings, needs_python35, needs_python36, needs_python37,
20-
assert_larray_equal)
13+
from larray.tests.common import (inputpath, tmp_path, meta,
14+
assert_array_equal, assert_array_nan_equal, assert_larray_equiv, assert_larray_equal,
15+
needs_xlwings, needs_pytables, needs_xlsxwriter, needs_xlrd,
16+
needs_python35, needs_python36, needs_python37)
2117
from larray import (Array, LArray, Axis, LGroup, union, zeros, zeros_like, ndtest, empty, ones, eye, diag, stack,
2218
clip, exp, where, X, mean, isnan, round, read_hdf, read_csv, read_eurostat, read_excel,
2319
from_lists, from_string, open_excel, from_frame, sequence, nan, IGroup)
@@ -116,6 +112,7 @@ def test_read_set_update_delete_metadata(meta, tmpdir):
116112
assert meta2 == meta
117113

118114

115+
@needs_pytables
119116
def test_metadata_hdf(meta, tmpdir):
120117
key = 'meta'
121118
fname = os.path.join(tmpdir.strpath, 'test_metadata.hdf')
@@ -3092,6 +3089,7 @@ def test_extend(small_array):
30923089
assert small_array.shape == (3, 16)
30933090

30943091

3092+
@needs_pytables
30953093
def test_hdf_roundtrip(tmpdir, meta):
30963094
a = ndtest((2, 3), meta=meta)
30973095
fpath = tmp_path(tmpdir, 'test.h5')
@@ -3336,6 +3334,7 @@ def test_read_excel_xlwings():
33363334
assert_array_equal(bad4, good2)
33373335

33383336

3337+
@needs_xlrd
33393338
def test_read_excel_pandas():
33403339
arr = read_excel(inputpath('test.xlsx'), '1d', engine='xlrd')
33413340
assert_array_equal(arr, io_1d)
@@ -3906,6 +3905,7 @@ def test_to_csv(tmpdir):
39063905
assert f.readlines() == result
39073906

39083907

3908+
@needs_xlsxwriter
39093909
def test_to_excel_xlsxwriter(tmpdir):
39103910
fpath = tmp_path(tmpdir, 'test_to_excel_xlsxwriter.xlsx')
39113911

larray/tests/test_axis.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os.path
66
import numpy as np
77

8-
from larray.tests.common import assert_array_equal, assert_nparray_equal
8+
from larray.tests.common import assert_array_equal, assert_nparray_equal, needs_pytables
99
from larray import Axis, LGroup, IGroup, read_hdf, X
1010
from larray.core.axis import AxisReference
1111

@@ -486,6 +486,7 @@ def test_contains():
486486
assert age[['2', '7']] not in agg
487487

488488

489+
@needs_pytables
489490
def test_h5_io(tmpdir):
490491
age = Axis('age=0..10')
491492
lipro = Axis('lipro=P01..P05')

larray/tests/test_group.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os.path
66
import numpy as np
77

8-
from larray.tests.common import assert_array_equal
8+
from larray.tests.common import assert_array_equal, needs_pytables
99
from larray import Axis, IGroup, LGroup, LSet, ndtest, read_hdf
1010
from larray.util.oset import OrderedSet
1111

@@ -186,6 +186,7 @@ def test_to_lset_lgroup():
186186
assert res.key == OrderedSet(['c'])
187187

188188

189+
@needs_pytables
189190
def test_h5_io_lgroup(tmpdir):
190191
fpath = os.path.join(str(tmpdir), 'lgroups.h5')
191192
age.to_hdf(fpath)
@@ -426,6 +427,7 @@ def test_to_lset_igroup():
426427
assert res.key == OrderedSet(['c'])
427428

428429

430+
@needs_pytables
429431
def test_h5_io_igroup(tmpdir):
430432
fpath = os.path.join(str(tmpdir), 'igroups.h5')
431433
age.to_hdf(fpath)

larray/tests/test_session.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import pandas as pd
88
import pytest
99

10-
from larray.tests.common import assert_array_nan_equal, inputpath, tmp_path, meta, needs_xlwings
10+
from larray.tests.common import (assert_array_nan_equal, inputpath, tmp_path, meta,
11+
needs_xlwings, needs_pytables, needs_xlrd)
1112
from larray import (Session, Axis, Array, Group, isnan, zeros_like, ndtest, ones_like, ones, full,
1213
local_arrays, global_arrays, arrays)
1314
from larray.util.misc import pickle, PY2
@@ -54,22 +55,27 @@ def test_init_session(meta):
5455
s = Session(b, b024, a, a01, a2=a2, anonymous=anonymous, ano01=ano01, c=c, d=d, e=e, f=f, g=g, h=h)
5556
assert s.names == ['a', 'a01', 'a2', 'ano01', 'anonymous', 'b', 'b024', 'c', 'd', 'e', 'f', 'g', 'h']
5657

57-
s = Session(inputpath('test_session.h5'))
58-
assert s.names == ['e', 'f', 'g']
59-
60-
# this needs xlwings installed
61-
# s = Session('test_session_ef.xlsx')
62-
# assertEqual(s.names, ['e', 'f'])
63-
6458
# TODO: format autodetection does not work in this case
6559
# s = Session('test_session_csv')
66-
# assertEqual(s.names, ['e', 'f', 'g'])
60+
# assert s.names == ['e', 'f', 'g']
6761

6862
# metadata
6963
s = Session(b, b024, a, a01, a2=a2, anonymous=anonymous, ano01=ano01, c=c, d=d, e=e, f=f, g=g, h=h, meta=meta)
7064
assert s.meta == meta
7165

7266

67+
@needs_xlwings
68+
def test_init_session_xlsx():
69+
s = Session(inputpath('demography_eurostat.xlsx'))
70+
assert s.names == ['births', 'deaths', 'immigration', 'pop', 'pop_benelux']
71+
72+
73+
@needs_pytables
74+
def test_init_session_hdf():
75+
s = Session(inputpath('test_session.h5'))
76+
assert s.names == ['e', 'f', 'g']
77+
78+
7379
def test_getitem(session):
7480
assert session['a'] is a
7581
assert session['a2'] is a2
@@ -219,11 +225,13 @@ def _test_io(fpath, session, meta, engine):
219225
assert s.meta == meta
220226

221227

228+
@needs_pytables
222229
def test_h5_io(tmpdir, session, meta):
223230
fpath = tmp_path(tmpdir, 'test_session.h5')
224231
_test_io(fpath, session, meta, engine='pandas_hdf')
225232

226233

234+
@needs_xlrd
227235
def test_xlsx_pandas_io(tmpdir, session, meta):
228236
fpath = tmp_path(tmpdir, 'test_session.xlsx')
229237
_test_io(fpath, session, meta, engine='pandas_excel')

0 commit comments

Comments
 (0)