Skip to content

Commit 22eeb75

Browse files
author
Rajat Bishnoi
committed
TST: insert 'match' to bare pytest raises in pandas/tests/tseries/offsets/test_ticks.py
1 parent 027f365 commit 22eeb75

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

pandas/tests/tseries/offsets/test_ticks.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Tests for offsets.Tick and subclasses
33
"""
44
from datetime import datetime, timedelta
5+
import operator
56

67
from hypothesis import assume, example, given, settings, strategies as st
78
import numpy as np
@@ -266,10 +267,15 @@ def test_tick_rdiv(cls):
266267
off = cls(10)
267268
delta = off.delta
268269
td64 = delta.to_timedelta64()
270+
instance__type = ".".join([cls.__module__, cls.__name__])
271+
msg = (
272+
"unsupported operand type\\(s\\) for \\/: 'int'|'float' and "
273+
f"'{instance__type}'"
274+
)
269275

270-
with pytest.raises(TypeError):
276+
with pytest.raises(TypeError, match=msg):
271277
2 / off
272-
with pytest.raises(TypeError):
278+
with pytest.raises(TypeError, match=msg):
273279
2.0 / off
274280

275281
assert (td64 * 2.5) / off == 2.5
@@ -319,26 +325,32 @@ def test_compare_ticks(cls):
319325
assert cls(3) != cls(4)
320326

321327

322-
@pytest.mark.parametrize("cls", tick_classes)
323-
def test_compare_ticks_to_strs(cls):
328+
@pytest.mark.parametrize(
329+
"cls, left, right, comparison",
330+
[
331+
(cls, left, right, comparison)
332+
for cls in tick_classes
333+
for left, right in (("infer", cls(19)), (cls(19), "infer"))
334+
for comparison in (operator.lt, operator.le, operator.gt, operator.ge)
335+
],
336+
)
337+
def test_compare_ticks_to_strs(cls, left, right, comparison):
324338
# GH#23524
325339
off = cls(19)
326-
327340
# These tests should work with any strings, but we particularly are
328341
# interested in "infer" as that comparison is convenient to make in
329342
# Datetime/Timedelta Array/Index constructors
330343
assert not off == "infer"
331344
assert not "foo" == off
332345

333-
for left, right in [("infer", off), (off, "infer")]:
334-
with pytest.raises(TypeError):
335-
left < right
336-
with pytest.raises(TypeError):
337-
left <= right
338-
with pytest.raises(TypeError):
339-
left > right
340-
with pytest.raises(TypeError):
341-
left >= right
346+
instance_type = ".".join([cls.__module__, cls.__name__])
347+
msg = (
348+
"'<'|'<='|'>'|'>=' not supported between instances of "
349+
f"'str' and '{instance_type}'|'{instance_type}' and 'str'"
350+
)
351+
352+
with pytest.raises(TypeError, match=msg):
353+
comparison(left, right)
342354

343355

344356
@pytest.mark.parametrize("cls", tick_classes)

0 commit comments

Comments
 (0)