Skip to content

Commit f807483

Browse files
committed
Add regression coverage for utcfromtimestamp behavior
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.
1 parent 068dd42 commit f807483

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

tests/datetime/test_behavior.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,34 @@ def test_utcfromtimestamp():
108108
assert p == dt
109109

110110

111+
def test_utcfromtimestamp_known_value():
112+
p = pendulum.DateTime.utcfromtimestamp(1577836800)
113+
114+
assert p.year == 2020
115+
assert p.month == 1
116+
assert p.day == 1
117+
assert p.hour == 0
118+
assert p.minute == 0
119+
assert p.second == 0
120+
assert p.microsecond == 0
121+
122+
123+
def test_utcfromtimestamp_preserves_microseconds():
124+
p = pendulum.DateTime.utcfromtimestamp(1577836800.123456)
125+
126+
assert p.year == 2020
127+
assert p.month == 1
128+
assert p.day == 1
129+
assert p.microsecond == 123456
130+
131+
132+
def test_utcfromtimestamp_returns_naive_pendulum_datetime():
133+
p = pendulum.DateTime.utcfromtimestamp(1577836800)
134+
135+
assert isinstance(p, pendulum.DateTime)
136+
assert p.tzinfo is None
137+
138+
111139
def test_fromordinal():
112140
assert datetime.fromordinal(730120) == pendulum.DateTime.fromordinal(730120)
113141

0 commit comments

Comments
 (0)