Skip to content

Commit 751720f

Browse files
committed
Fix error of Duration deepcopy not including weeks
1 parent e00608b commit 751720f

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/pendulum/duration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ def __deepcopy__(self, _: dict[int, Self]) -> Self:
467467
hours=self.hours,
468468
years=self.years,
469469
months=self.months,
470+
weeks=self.weeks,
470471
)
471472

472473

tests/duration/test_behavior.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from copy import deepcopy
66
from datetime import timedelta
77

8+
import pytest
9+
810
import pendulum
911

1012
from tests.conftest import assert_duration
@@ -24,9 +26,15 @@ def test_comparison_to_timedelta() -> None:
2426
assert duration < timedelta(days=4)
2527

2628

27-
def test_deepcopy() -> None:
28-
duration = pendulum.duration(months=1)
29+
@pytest.mark.parametrize(
30+
"duration, expected",
31+
[
32+
(pendulum.duration(months=1), {"months": 1}),
33+
(pendulum.Duration(days=9), {"weeks": 1, "days": 2}),
34+
],
35+
)
36+
def test_deepcopy(duration, expected) -> None:
2937
copied_duration = deepcopy(duration)
3038

3139
assert copied_duration == duration
32-
assert_duration(copied_duration, months=1)
40+
assert_duration(copied_duration, **expected)

0 commit comments

Comments
 (0)