|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from red_utils.ext import time_utils |
| 4 | +from red_utils.ext.time_utils import arrow_utils |
| 5 | + |
| 6 | +import arrow |
| 7 | +import pendulum |
| 8 | + |
| 9 | +from pytest import mark, xfail |
| 10 | + |
| 11 | +@mark.time_utils |
| 12 | +def test_arrow_ts_str(ts_str: str): |
| 13 | + assert ts_str is not None, "ts_str must not be None" |
| 14 | + assert isinstance(ts_str, str), f"ts_str must be of type str, not ({type(ts_str)})" |
| 15 | + |
| 16 | + _ts = arrow.get(ts_str) |
| 17 | + assert isinstance(_ts, arrow.Arrow), "_ts must be of type Arrow" |
| 18 | + |
| 19 | + |
| 20 | +@mark.time_utils |
| 21 | +def test_arrow_shift(arrow_now: arrow.Arrow): |
| 22 | + assert isinstance(arrow_now, arrow.Arrow), "arrow_now must be of type arrow.Arrow" |
| 23 | + |
| 24 | + shifted = arrow_now.shift(weekday=1) |
| 25 | + |
| 26 | + assert ( |
| 27 | + arrow_now < shifted |
| 28 | + ), f"arrow_now ({arrow_now}) must be earlier than date ({shifted})" |
| 29 | + |
| 30 | + |
| 31 | +@mark.time_utils |
| 32 | +def test_pendulum_ts(pendulum_now): |
| 33 | + assert pendulum_now is not None, "ts_str must not be None" |
| 34 | + assert isinstance( |
| 35 | + pendulum_now, pendulum.DateTime |
| 36 | + ), f"pendulum_now must be of type pendulum.DateTime, not {type(pendulum_now)}" |
| 37 | + |
| 38 | + |
| 39 | +@mark.time_utils |
| 40 | +def test_pendulum_24h_ts(): |
| 41 | + ts = time_utils.get_ts(as_str=True, str_fmt=time_utils.TIME_FMT_24H) |
| 42 | + assert ts is not None, "ts must not be None" |
| 43 | + assert isinstance(ts, str), f"ts must be of type str, not ({type(ts)})" |
| 44 | + |
| 45 | + |
| 46 | +@mark.time_utils |
| 47 | +def test_pendulum_get_ts(): |
| 48 | + ts = time_utils.get_ts() |
| 49 | + assert ts is not None, "ts must not be None" |
| 50 | + assert isinstance( |
| 51 | + ts, pendulum.DateTime |
| 52 | + ), f"ts must be of type pendulum.DateTime, not ({type(ts)})" |
| 53 | + |
| 54 | + |
| 55 | +@mark.time_utils |
| 56 | +def test_pendulum_safestr(): |
| 57 | + ts = time_utils.get_ts(as_str=True, safe_str=True) |
| 58 | + assert ts is not None, "ts must not be None" |
| 59 | + assert isinstance(ts, str), f"ts must be of type str, not ({type(ts)})" |
| 60 | + |
| 61 | + |
| 62 | +@mark.time_utils |
| 63 | +def test_pendulum_char_replace(): |
| 64 | + ts = time_utils.get_ts( |
| 65 | + as_str=True, safe_str=True, char_replace_map=[{"search": "-", "replace": "^"}] |
| 66 | + ) |
| 67 | + assert ts is not None, "ts must not be None" |
| 68 | + assert isinstance(ts, str), f"ts must be of type str, not ({type(ts)})" |
| 69 | + assert ( |
| 70 | + "^" in ts |
| 71 | + ), f"Timestamp missing expected '^' character. Timestamp string: {ts}" |
0 commit comments