|
2 | 2 | Tests for offsets.Tick and subclasses
|
3 | 3 | """
|
4 | 4 | from datetime import datetime, timedelta
|
| 5 | +import operator |
5 | 6 |
|
6 | 7 | from hypothesis import assume, example, given, settings, strategies as st
|
7 | 8 | import numpy as np
|
@@ -266,10 +267,15 @@ def test_tick_rdiv(cls):
|
266 | 267 | off = cls(10)
|
267 | 268 | delta = off.delta
|
268 | 269 | 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 | + ) |
269 | 275 |
|
270 |
| - with pytest.raises(TypeError): |
| 276 | + with pytest.raises(TypeError, match=msg): |
271 | 277 | 2 / off
|
272 |
| - with pytest.raises(TypeError): |
| 278 | + with pytest.raises(TypeError, match=msg): |
273 | 279 | 2.0 / off
|
274 | 280 |
|
275 | 281 | assert (td64 * 2.5) / off == 2.5
|
@@ -319,26 +325,32 @@ def test_compare_ticks(cls):
|
319 | 325 | assert cls(3) != cls(4)
|
320 | 326 |
|
321 | 327 |
|
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): |
324 | 338 | # GH#23524
|
325 | 339 | off = cls(19)
|
326 |
| - |
327 | 340 | # These tests should work with any strings, but we particularly are
|
328 | 341 | # interested in "infer" as that comparison is convenient to make in
|
329 | 342 | # Datetime/Timedelta Array/Index constructors
|
330 | 343 | assert not off == "infer"
|
331 | 344 | assert not "foo" == off
|
332 | 345 |
|
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) |
342 | 354 |
|
343 | 355 |
|
344 | 356 | @pytest.mark.parametrize("cls", tick_classes)
|
|
0 commit comments