The existing test_utcfromtimestamp only exercises t=0, which incidentally
gives back a value where every field happens to be zero. That makes it
weak against regressions in field handling, microsecond preservation,
and return-type semantics.
Add three focused tests that lock those down without changing or
removing any existing behavior:
- test_utcfromtimestamp_known_value: asserts that a specific non-zero
Unix timestamp (1577836800 = 2020-01-01T00:00:00 UTC) produces the
expected year/month/day/hour/minute/second/microsecond values.
- test_utcfromtimestamp_preserves_microseconds: asserts that a fractional
timestamp passes its microseconds through to the resulting DateTime,
protecting the precision contract of the method.
- test_utcfromtimestamp_returns_naive_pendulum_datetime: asserts that
the returned object is a pendulum.DateTime instance and is naive
(tzinfo is None), which is the documented behavior the method has had
before and after the deprecation cleanup in this PR.
All three tests are additions; no existing test is modified or removed.
Full suite: 1833 passed, 5 skipped (was 1830 passed) with
-W error::DeprecationWarning.
Pull Request Check List
Summary
Python 3.12 deprecated datetime.utcnow() and datetime.utcfromtimestamp(); both are scheduled for removal in a future Python version. This PR replaces all internal uses with the non-deprecated, behavior-preserving equivalents:
Why
Running the existing test suite on Python 3.12+ currently emits 4 DeprecationWarnings coming from Pendulum's own code:
These APIs are scheduled for removal in a future Python version, so addressing them now avoids a hard break later.
What changed
The stdlib timezone is imported as datetime_timezone to avoid clashing with pendulum.timezone already imported in those test modules.
Behavior
The public API of pendulum.DateTime.utcfromtimestamp is unchanged — it still returns a DateTime constructed from a naive UTC datetime.
Verification
All 1830 tests pass with DeprecationWarning promoted to errors — confirming the warnings are gone and no regression was introduced.