Skip to content

Commit cfb6d48

Browse files
committed
predefine a few common pytest.skipif clauses
1 parent fbbd31b commit cfb6d48

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

larray/tests/common.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
from __future__ import absolute_import, division, print_function
22

33
import os
4+
import sys
5+
46
import pytest
57
import datetime as dt
68
import numpy as np
79
import pandas as pd
10+
try:
11+
import xlwings as xw
12+
except ImportError:
13+
xw = None
14+
815
from larray import LArray, isnan, aslarray, Metadata
916

1017

@@ -124,3 +131,9 @@ def meta():
124131
return Metadata([('title', title), ('description', description), ('author', author),
125132
('location', location), ('office_number', office_number),
126133
('score', score), ('date', date)])
134+
135+
136+
needs_xlwings = pytest.mark.skipif(xw is None, reason="xlwings is required for this test")
137+
needs_python35 = pytest.mark.skipif(sys.version_info < (3, 5), reason="Python 3.5 is required for this test")
138+
needs_python36 = pytest.mark.skipif(sys.version_info < (3, 6), reason="Python 3.6 is required for this test")
139+
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
@@ -14,10 +14,10 @@
1414
xw = None
1515

1616
from larray.tests.common import (inputpath, assert_array_equal, assert_array_nan_equal, assert_larray_equiv,
17-
tmp_path, meta)
17+
tmp_path, meta, needs_xlwings, needs_python35, needs_python36, needs_python37)
1818
from larray import (LArray, Axis, LGroup, union, zeros, zeros_like, ndtest, empty, ones, eye, diag, stack,
1919
clip, exp, where, X, mean, isnan, round, read_hdf, read_csv, read_eurostat, read_excel,
20-
from_lists, from_string, open_excel, from_frame, sequence, nan, nan_equal, IGroup)
20+
from_lists, from_string, open_excel, from_frame, sequence, nan, IGroup)
2121
from larray.inout.pandas import from_series
2222
from larray.core.axis import _to_ticks, _to_key
2323
from larray.util.misc import StringIO, LHDFStore
@@ -3013,7 +3013,7 @@ def test_read_eurostat():
30133013
[3722, 3395, 3347])
30143014

30153015

3016-
@pytest.mark.skipif(xw is None, reason="xlwings is not available")
3016+
@needs_xlwings
30173017
def test_read_excel_xlwings():
30183018
arr = read_excel(inputpath('test.xlsx'), '1d')
30193019
assert_array_equal(arr, io_1d)
@@ -3807,7 +3807,7 @@ def test_to_excel_xlsxwriter(tmpdir):
38073807
a3[group].to_excel(fpath, group, engine='xlsxwriter')
38083808

38093809

3810-
@pytest.mark.skipif(xw is None, reason="xlwings is not available")
3810+
@needs_xlwings
38113811
def test_to_excel_xlwings(tmpdir):
38123812
fpath = tmp_path(tmpdir, 'test_to_excel_xlwings.xlsx')
38133813

@@ -3915,11 +3915,11 @@ def test_as_table():
39153915
['a2', 2]]
39163916

39173917

3918-
@pytest.mark.skipif(xw is None, reason="xlwings is not available")
3918+
@needs_xlwings
39193919
def test_open_excel(tmpdir):
39203920
# 1) Create new file
39213921
# ==================
3922-
fpath = inputpath('should_not_extist.xlsx')
3922+
fpath = inputpath('should_not_exist.xlsx')
39233923
# overwrite_file must be set to True to create a new file
39243924
with pytest.raises(ValueError):
39253925
open_excel(fpath)
@@ -4239,7 +4239,7 @@ def test_diag():
42394239
assert d.i[1] == 1.0
42404240

42414241

4242-
@pytest.mark.skipif(sys.version_info < (3, 5), reason="@ unavailable (Python < 3.5)")
4242+
@needs_python35
42434243
def test_matmul():
42444244
# 2D / anonymous axes
42454245
a1 = ndtest([Axis(3), Axis(3)])
@@ -4398,7 +4398,7 @@ def test_matmul():
43984398
assert_array_equal(arr2d.__matmul__(arr4d), res)
43994399

44004400

4401-
@pytest.mark.skipif(sys.version_info < (3, 5), reason="@ unavailable (Python < 3.5)")
4401+
@needs_python35
44024402
def test_rmatmul():
44034403
a1 = eye(3) * 2
44044404
a2 = ndtest([Axis(3), Axis(3)])

larray/tests/test_excel.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55
import pytest
66
import numpy as np
77

8-
try:
9-
import xlwings as xw
10-
except ImportError:
11-
xw = None
12-
8+
from larray.tests.common import needs_xlwings
139
from larray import ndtest, larray_equal, open_excel, aslarray, Axis
1410
from larray.inout import xw_excel
1511

1612

17-
@pytest.mark.skipif(xw is None, reason="xlwings is not available")
13+
@needs_xlwings
1814
class TestWorkbook(object):
1915
def test_open_excel(self):
2016
# not using context manager because we call .quit manually
@@ -106,7 +102,7 @@ def test_rename(self):
106102
assert wb.sheet_names() == ['renamed']
107103

108104

109-
@pytest.mark.skipif(xw is None, reason="xlwings is not available")
105+
@needs_xlwings
110106
class TestSheet(object):
111107
def test_get_and_set_item(self):
112108
arr = ndtest((2, 3))
@@ -170,7 +166,7 @@ def test_repr(self):
170166
assert re.match('<larray.inout.xw_excel.Sheet \[Book\d+\]Sheet1>', repr(sheet))
171167

172168

173-
@pytest.mark.skipif(xw is None, reason="xlwings is not available")
169+
@needs_xlwings
174170
class TestRange(object):
175171
def test_scalar_convert(self):
176172
with open_excel(visible=False) as wb:

larray/tests/test_session.py

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

10-
from larray.tests.common import assert_array_nan_equal, inputpath, tmp_path, meta
10+
from larray.tests.common import assert_array_nan_equal, inputpath, tmp_path, meta, needs_xlwings
1111
from larray import (Session, Axis, LArray, Group, isnan, zeros_like, ndtest, ones_like,
12-
local_arrays, global_arrays, arrays, nan)
12+
local_arrays, global_arrays, arrays)
1313
from larray.util.misc import pickle
1414

15-
try:
16-
import xlwings as xw
17-
except ImportError:
18-
xw = None
19-
2015

2116
def equal(o1, o2):
2217
if isinstance(o1, LArray) or isinstance(o2, LArray):
@@ -222,7 +217,7 @@ def test_xlsx_pandas_io(tmpdir, session, meta):
222217
assert s.meta == meta
223218

224219

225-
@pytest.mark.skipif(xw is None, reason="xlwings is not available")
220+
@needs_xlwings
226221
def test_xlsx_xlwings_io(tmpdir, session, meta):
227222
fpath = tmp_path(tmpdir, 'test_session_xw.xlsx')
228223
session.meta = meta

0 commit comments

Comments
 (0)