Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/pendulum/duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ def __deepcopy__(self, _: dict[int, Self]) -> Self:
hours=self.hours,
years=self.years,
months=self.months,
weeks=self.weeks,
)


Expand Down
14 changes: 11 additions & 3 deletions tests/duration/test_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from copy import deepcopy
from datetime import timedelta

import pytest

import pendulum

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


def test_deepcopy() -> None:
duration = pendulum.duration(months=1)
@pytest.mark.parametrize(
"duration, expected",
[
(pendulum.duration(months=1), {"months": 1}),
(pendulum.Duration(days=9), {"weeks": 1, "days": 2}),
],
)
def test_deepcopy(duration, expected) -> None:
copied_duration = deepcopy(duration)

assert copied_duration == duration
assert_duration(copied_duration, months=1)
assert_duration(copied_duration, **expected)