diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-01-05 10:38:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-01-05 10:39:17 +0000 |
commit | d6d80a17444c90259c5bfdacb84c61e6bfece655 (patch) | |
tree | 157bff98bd572acf0b64cd5d478b0bdac87a37ae /tests/time/test_add.py | |
parent | Releasing debian version 2.1.2-4. (diff) | |
download | pendulum-d6d80a17444c90259c5bfdacb84c61e6bfece655.tar.xz pendulum-d6d80a17444c90259c5bfdacb84c61e6bfece655.zip |
Merging upstream version 3.0.0~a1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/time/test_add.py')
-rw-r--r-- | tests/time/test_add.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/time/test_add.py b/tests/time/test_add.py new file mode 100644 index 0000000..7075ebe --- /dev/null +++ b/tests/time/test_add.py @@ -0,0 +1,78 @@ +from __future__ import annotations + +from datetime import timedelta + +import pytest + +import pendulum + + +def test_add_hours_positive(): + assert pendulum.time(12, 34, 56).add(hours=1).hour == 13 + + +def test_add_hours_zero(): + assert pendulum.time(12, 34, 56).add(hours=0).hour == 12 + + +def test_add_hours_negative(): + assert pendulum.time(12, 34, 56).add(hours=-1).hour == 11 + + +def test_add_minutes_positive(): + assert pendulum.time(12, 34, 56).add(minutes=1).minute == 35 + + +def test_add_minutes_zero(): + assert pendulum.time(12, 34, 56).add(minutes=0).minute == 34 + + +def test_add_minutes_negative(): + assert pendulum.time(12, 34, 56).add(minutes=-1).minute == 33 + + +def test_add_seconds_positive(): + assert pendulum.time(12, 34, 56).add(seconds=1).second == 57 + + +def test_add_seconds_zero(): + assert pendulum.time(12, 34, 56).add(seconds=0).second == 56 + + +def test_add_seconds_negative(): + assert pendulum.time(12, 34, 56).add(seconds=-1).second == 55 + + +def test_add_timedelta(): + delta = timedelta(seconds=45, microseconds=123456) + d = pendulum.time(3, 12, 15, 654321) + + d = d.add_timedelta(delta) + assert d.minute == 13 + assert d.second == 0 + assert d.microsecond == 777777 + + d = pendulum.time(3, 12, 15, 654321) + + d = d + delta + assert d.minute == 13 + assert d.second == 0 + assert d.microsecond == 777777 + + +def test_add_timedelta_with_days(): + delta = timedelta(days=3, seconds=45, microseconds=123456) + d = pendulum.time(3, 12, 15, 654321) + + with pytest.raises(TypeError): + d.add_timedelta(delta) + + +def test_addition_invalid_type(): + d = pendulum.time(3, 12, 15, 654321) + + with pytest.raises(TypeError): + d + 3 + + with pytest.raises(TypeError): + 3 + d |