summaryrefslogtreecommitdiffstats
path: root/tests/date/test_add.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-05 10:38:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-05 10:38:34 +0000
commite3bdad36cc3a1a00c1e6772ca1c1898085ab73e0 (patch)
tree34512072a667ae716fd262e7b37e733e60fe4d89 /tests/date/test_add.py
parentAdding upstream version 2.1.2. (diff)
downloadpendulum-upstream/3.0.0_a1.tar.xz
pendulum-upstream/3.0.0_a1.zip
Adding upstream version 3.0.0~a1.upstream/3.0.0_a1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/date/test_add.py')
-rw-r--r--tests/date/test_add.py88
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/date/test_add.py b/tests/date/test_add.py
new file mode 100644
index 0000000..a435f46
--- /dev/null
+++ b/tests/date/test_add.py
@@ -0,0 +1,88 @@
+from __future__ import annotations
+
+from datetime import timedelta
+
+import pytest
+
+import pendulum
+
+from tests.conftest import assert_date
+
+
+def test_add_years_positive():
+ assert pendulum.date(1975, 1, 1).add(years=1).year == 1976
+
+
+def test_add_years_zero():
+ assert pendulum.date(1975, 1, 1).add(years=0).year == 1975
+
+
+def test_add_years_negative():
+ assert pendulum.date(1975, 1, 1).add(years=-1).year == 1974
+
+
+def test_add_months_positive():
+ assert pendulum.date(1975, 12, 1).add(months=1).month == 1
+
+
+def test_add_months_zero():
+ assert pendulum.date(1975, 12, 1).add(months=0).month == 12
+
+
+def test_add_months_negative():
+ assert pendulum.date(1975, 12, 1).add(months=-1).month == 11
+
+
+def test_add_month_with_overflow():
+ assert pendulum.Date(2012, 1, 31).add(months=1).month == 2
+
+
+def test_add_days_positive():
+ assert pendulum.Date(1975, 5, 31).add(days=1).day == 1
+
+
+def test_add_days_zero():
+ assert pendulum.Date(1975, 5, 31).add(days=0).day == 31
+
+
+def test_add_days_negative():
+ assert pendulum.Date(1975, 5, 31).add(days=-1).day == 30
+
+
+def test_add_weeks_positive():
+ assert pendulum.Date(1975, 5, 21).add(weeks=1).day == 28
+
+
+def test_add_weeks_zero():
+ assert pendulum.Date(1975, 5, 21).add(weeks=0).day == 21
+
+
+def test_add_weeks_negative():
+ assert pendulum.Date(1975, 5, 21).add(weeks=-1).day == 14
+
+
+def test_add_timedelta():
+ delta = timedelta(days=18)
+ d = pendulum.date(2015, 3, 14)
+
+ new = d + delta
+ assert isinstance(new, pendulum.Date)
+ assert_date(new, 2015, 4, 1)
+
+
+def test_add_duration():
+ duration = pendulum.duration(years=2, months=3, days=18)
+ d = pendulum.Date(2015, 3, 14)
+
+ new = d + duration
+ assert_date(new, 2017, 7, 2)
+
+
+def test_addition_invalid_type():
+ d = pendulum.date(2015, 3, 14)
+
+ with pytest.raises(TypeError):
+ d + 3
+
+ with pytest.raises(TypeError):
+ 3 + d