Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

GH-103944: Remove last use of utcfromtimestamp #103995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 3, 2023
Merged
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
35 changes: 20 additions & 15 deletions 35 Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

See https://www.zope.dev/Members/fdrake/DateTimeWiki/TestCases
"""
import io
import itertools
import bisect
import copy
import decimal
import sys
import io
import itertools
import os
import pickle
import random
import re
import struct
import sys
import unittest
import warnings

from array import array

Expand Down Expand Up @@ -47,11 +48,12 @@
for proto in range(pickle.HIGHEST_PROTOCOL + 1)]
assert len(pickle_choices) == pickle.HIGHEST_PROTOCOL + 1

EPOCH_NAIVE = datetime(1970, 1, 1, 0, 0) # For calculating transitions

# An arbitrary collection of objects of non-datetime types, for testing
# mixed-type comparisons.
OTHERSTUFF = (10, 34.5, "abc", {}, [], ())


# XXX Copied from test_float.
INF = float("inf")
NAN = float("nan")
Expand Down Expand Up @@ -2622,9 +2624,10 @@ def test_utcfromtimestamp_limits(self):
for test_name, ts in test_cases:
with self.subTest(test_name, ts=ts):
with self.assertRaises((ValueError, OverflowError)):
# converting a Python int to C time_t can raise a
# OverflowError, especially on 32-bit platforms.
self.theclass.utcfromtimestamp(ts)
with self.assertWarns(DeprecationWarning):
# converting a Python int to C time_t can raise a
# OverflowError, especially on 32-bit platforms.
self.theclass.utcfromtimestamp(ts)

def test_insane_fromtimestamp(self):
# It's possible that some platform maps time_t to double,
Expand All @@ -2641,8 +2644,9 @@ def test_insane_utcfromtimestamp(self):
# exempt such platforms (provided they return reasonable
# results!).
for insane in -1e200, 1e200:
self.assertRaises(OverflowError, self.theclass.utcfromtimestamp,
insane)
with self.assertWarns(DeprecationWarning):
self.assertRaises(OverflowError, self.theclass.utcfromtimestamp,
insane)

@unittest.skipIf(sys.platform == "win32", "Windows doesn't accept negative timestamps")
def test_negative_float_fromtimestamp(self):
Expand Down Expand Up @@ -3001,7 +3005,7 @@ def __new__(cls, *args, **kwargs):
for name, meth_name, kwargs in test_cases:
with self.subTest(name):
constr = getattr(DateTimeSubclass, meth_name)
if constr == "utcnow":
if meth_name == "utcnow":
with self.assertWarns(DeprecationWarning):
dt = constr(**kwargs)
else:
Expand Down Expand Up @@ -4729,8 +4733,10 @@ def test_tzinfo_utcfromtimestamp(self):
# Try with and without naming the keyword; for whatever reason,
# utcfromtimestamp() doesn't accept a tzinfo argument.
off42 = FixedOffset(42, "42")
self.assertRaises(TypeError, meth, ts, off42)
self.assertRaises(TypeError, meth, ts, tzinfo=off42)
with warnings.catch_warnings(category=DeprecationWarning):
warnings.simplefilter("ignore", category=DeprecationWarning)
self.assertRaises(TypeError, meth, ts, off42)
self.assertRaises(TypeError, meth, ts, tzinfo=off42)

def test_tzinfo_timetuple(self):
# TestDateTime tested most of this. datetime adds a twist to the
Expand Down Expand Up @@ -6098,15 +6104,14 @@ def stats(cls, start_year=1):
def transitions(self):
for (_, prev_ti), (t, ti) in pairs(zip(self.ut, self.ti)):
shift = ti[0] - prev_ti[0]
# TODO: Remove this use of utcfromtimestamp
yield datetime.utcfromtimestamp(t), shift
yield (EPOCH_NAIVE + timedelta(seconds=t)), shift

def nondst_folds(self):
"""Find all folds with the same value of isdst on both sides of the transition."""
for (_, prev_ti), (t, ti) in pairs(zip(self.ut, self.ti)):
shift = ti[0] - prev_ti[0]
if shift < ZERO and ti[1] == prev_ti[1]:
yield datetime.utcfromtimestamp(t), -shift, prev_ti[2], ti[2]
yield _utcfromtimestamp(datetime, t,), -shift, prev_ti[2], ti[2]

@classmethod
def print_all_nondst_folds(cls, same_abbr=False, start_year=1):
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.