1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 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
|