Skip to content

Commit 687e3b7

Browse files
committed
parameterize tests, define fixture where it is used
1 parent 807d769 commit 687e3b7

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

pandas/tests/tseries/conftest.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
import pytest
2-
import pandas.tseries.offsets as offsets
3-
4-
5-
@pytest.fixture(params=[getattr(offsets, o) for o in offsets.__all__])
6-
def offset_types(request):
7-
return request.param
82

93

104
@pytest.fixture(params=[None, 'UTC', 'Asia/Tokyo', 'US/Eastern',

pandas/tests/tseries/test_offsets.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@
4242
from pandas.tseries.holiday import USFederalHolidayCalendar
4343

4444

45+
offset_classes = [getattr(offsets, x) for x in dir(offsets)]
46+
offset_classes = [x for x in offset_classes if inspect.isclass(x) and
47+
issubclass(x, DateOffset)]
48+
49+
50+
@pytest.fixture(params=offset_classes)
51+
def offset_types(request):
52+
return request.param
53+
54+
4555
def test_monthrange():
4656
import calendar
4757
for y in range(2000, 2013):
@@ -4904,23 +4914,15 @@ def test_all_offset_classes(self):
49044914

49054915
# ---------------------------------------------------------------------
49064916

4907-
offset_classes = [getattr(offsets, x) for x in dir(offsets)]
4908-
offset_classes = [x for x in offset_classes if inspect.isclass(x) and
4909-
issubclass(x, DateOffset)]
4917+
month_classes = [x for x in offset_classes if
4918+
issubclass(x, offsets.MonthOffset)]
4919+
4920+
tick_classes = [x for x in offset_classes if issubclass(x, offsets.Tick)]
49104921

49114922

4912-
def test_valid_attributes():
4923+
@pytest.parametrize('cls', month_classes+tick_classes)
4924+
@pytest.parametrize('kwd', _rd_kwds)
4925+
def test_valid_attributes(kwd, cls):
49134926
# check that we cannot create e.g. MonthEnd(weeks=3)
4914-
month_classes = [x for x in offset_classes if
4915-
issubclass(x, offsets.MonthOffset)]
4916-
4917-
for cls in month_classes:
4918-
for kwd in _rd_kwds:
4919-
with pytest.raises(TypeError):
4920-
cls(**{kwd: 3})
4921-
4922-
tick_classes = [x for x in offset_classes if issubclass(x, offsets.Tick)]
4923-
for cls in tick_classes:
4924-
for kwd in _rd_kwds:
4925-
with pytest.raises(TypeError):
4926-
cls(**{kwd: 4})
4927+
with pytest.raises(TypeError):
4928+
cls(**{kwd: 3})

0 commit comments

Comments
 (0)