|
120 | 120 | text_clean,
|
121 | 121 | zoned_datetimes,
|
122 | 122 | )
|
123 |
| -from utilities.math import is_integral |
| 123 | +from utilities.math import MAX_INT32, MIN_INT32, is_integral, round_to_float |
124 | 124 | from utilities.zoneinfo import UTC, HongKong, Tokyo
|
125 | 125 |
|
126 | 126 | if TYPE_CHECKING:
|
|
129 | 129 | from utilities.types import Number
|
130 | 130 |
|
131 | 131 |
|
| 132 | +@mark.skip |
132 | 133 | class TestAddDuration:
|
133 | 134 | @given(date=dates(), days=integers())
|
134 | 135 | def test_date(self, *, date: dt.date, days: int) -> None:
|
@@ -215,7 +216,6 @@ def test_datetime(self, *, datetime: dt.datetime) -> None:
|
215 | 216 | check_zoned_datetime(datetime)
|
216 | 217 |
|
217 | 218 |
|
218 |
| -@mark.only |
219 | 219 | class TestDateDurationToInt:
|
220 | 220 | @given(n=integers())
|
221 | 221 | def test_int(self, *, n: int) -> None:
|
@@ -253,7 +253,6 @@ def test_error_timedelta(self, *, n: int, frac: dt.timedelta) -> None:
|
253 | 253 | _ = date_duration_to_int(timedelta)
|
254 | 254 |
|
255 | 255 |
|
256 |
| -@mark.only |
257 | 256 | class TestDateDurationToTimeDelta:
|
258 | 257 | @given(n=integers())
|
259 | 258 | def test_int(self, *, n: int) -> None:
|
@@ -310,28 +309,34 @@ def test_main(self, *, date: dt.date) -> None:
|
310 | 309 |
|
311 | 310 |
|
312 | 311 | class TestDateTimeDurationToFloat:
|
313 |
| - @given(duration=integers(0, 10) | floats(0.0, 10.0)) |
314 |
| - def test_number(self, *, duration: Number) -> None: |
315 |
| - result = datetime_duration_to_float(duration) |
316 |
| - assert result == duration |
| 312 | + @given(n=int32s()) |
| 313 | + def test_int(self, *, n: int) -> None: |
| 314 | + result = datetime_duration_to_float(n) |
| 315 | + assert result == n |
317 | 316 |
|
318 |
| - @given(duration=timedeltas()) |
319 |
| - def test_timedelta(self, *, duration: dt.timedelta) -> None: |
320 |
| - result = datetime_duration_to_float(duration) |
321 |
| - assert result == duration.total_seconds() |
| 317 | + @given(n=floats(allow_nan=False, allow_infinity=False)) |
| 318 | + def test_float(self, *, n: Number) -> None: |
| 319 | + result = datetime_duration_to_float(n) |
| 320 | + assert result == n |
| 321 | + |
| 322 | + @given(timedelta=timedeltas()) |
| 323 | + def test_timedelta(self, *, timedelta: dt.timedelta) -> None: |
| 324 | + result = datetime_duration_to_float(timedelta) |
| 325 | + assert result == timedelta.total_seconds() |
322 | 326 |
|
323 | 327 |
|
324 | 328 | class TestDateTimeDurationToTimedelta:
|
325 |
| - @given(duration=integers(0, 10)) |
326 |
| - def test_int(self, *, duration: int) -> None: |
327 |
| - result = datetime_duration_to_timedelta(duration) |
328 |
| - assert result.total_seconds() == duration |
| 329 | + @given(n=int32s()) |
| 330 | + def test_int(self, *, n: int) -> None: |
| 331 | + result = datetime_duration_to_timedelta(n) |
| 332 | + assert result.total_seconds() == n |
329 | 333 |
|
330 |
| - @given(duration=floats(0.0, 10.0)) |
331 |
| - def test_float(self, *, duration: float) -> None: |
332 |
| - duration = round(10 * duration) / 10 |
333 |
| - result = datetime_duration_to_timedelta(duration) |
334 |
| - assert isclose(result.total_seconds(), duration) |
| 334 | + @given(n=floats(min_value=MIN_INT32, max_value=MAX_INT32)) |
| 335 | + def test_float(self, *, n: float) -> None: |
| 336 | + n = round_to_float(n, 1e-6) |
| 337 | + with assume_does_not_raise(OverflowError): |
| 338 | + result = datetime_duration_to_timedelta(n) |
| 339 | + assert isclose(result.total_seconds(), n) |
335 | 340 |
|
336 | 341 | @given(duration=timedeltas())
|
337 | 342 | def test_timedelta(self, *, duration: dt.timedelta) -> None:
|
|
0 commit comments