diff options
Diffstat (limited to 'tests/utils_tests')
| -rw-r--r-- | tests/utils_tests/test_dateformat.py | 6 | ||||
| -rw-r--r-- | tests/utils_tests/test_feedgenerator.py | 2 | ||||
| -rw-r--r-- | tests/utils_tests/test_http.py | 38 | ||||
| -rw-r--r-- | tests/utils_tests/test_timesince.py | 2 | ||||
| -rw-r--r-- | tests/utils_tests/test_timezone.py | 2 |
5 files changed, 25 insertions, 25 deletions
diff --git a/tests/utils_tests/test_dateformat.py b/tests/utils_tests/test_dateformat.py index dc330a710b..9604b0cef4 100644 --- a/tests/utils_tests/test_dateformat.py +++ b/tests/utils_tests/test_dateformat.py @@ -1,4 +1,4 @@ -from datetime import date, datetime, time, timezone, tzinfo +from datetime import UTC, date, datetime, time, tzinfo from django.test import SimpleTestCase, override_settings from django.test.utils import TZ_SUPPORT, requires_tz_support @@ -63,7 +63,7 @@ class DateFormatTests(SimpleTestCase): ) def test_epoch(self): - udt = datetime(1970, 1, 1, tzinfo=timezone.utc) + udt = datetime(1970, 1, 1, tzinfo=UTC) self.assertEqual(format(udt, "U"), "0") def test_empty_format(self): @@ -208,7 +208,7 @@ class DateFormatTests(SimpleTestCase): @requires_tz_support def test_e_format_with_named_time_zone(self): - dt = datetime(1970, 1, 1, tzinfo=timezone.utc) + dt = datetime(1970, 1, 1, tzinfo=UTC) self.assertEqual(dateformat.format(dt, "e"), "UTC") @requires_tz_support diff --git a/tests/utils_tests/test_feedgenerator.py b/tests/utils_tests/test_feedgenerator.py index e5ceafb8fa..28a1afc96e 100644 --- a/tests/utils_tests/test_feedgenerator.py +++ b/tests/utils_tests/test_feedgenerator.py @@ -148,7 +148,7 @@ class FeedgeneratorTests(SimpleTestCase): rss_feed = feedgenerator.Rss201rev2Feed("title", "link", "description") self.assertEqual( rss_feed.latest_post_date().tzinfo, - datetime.timezone.utc, + datetime.UTC, ) def test_stylesheet_keeps_lazy_urls(self): diff --git a/tests/utils_tests/test_http.py b/tests/utils_tests/test_http.py index c04f0a03d7..d18fb63c0c 100644 --- a/tests/utils_tests/test_http.py +++ b/tests/utils_tests/test_http.py @@ -1,6 +1,6 @@ import platform import unittest -from datetime import datetime, timezone +from datetime import UTC, datetime from unittest import mock from django.test import SimpleTestCase @@ -329,61 +329,61 @@ class HttpDateProcessingTests(unittest.TestCase): def test_parsing_rfc1123(self): parsed = parse_http_date("Sun, 06 Nov 1994 08:49:37 GMT") self.assertEqual( - datetime.fromtimestamp(parsed, timezone.utc), - datetime(1994, 11, 6, 8, 49, 37, tzinfo=timezone.utc), + datetime.fromtimestamp(parsed, UTC), + datetime(1994, 11, 6, 8, 49, 37, tzinfo=UTC), ) @unittest.skipIf(platform.architecture()[0] == "32bit", "The Year 2038 problem.") @mock.patch("django.utils.http.datetime") def test_parsing_rfc850(self, mocked_datetime): mocked_datetime.side_effect = datetime - now_1 = datetime(2019, 11, 6, 8, 49, 37, tzinfo=timezone.utc) - now_2 = datetime(2020, 11, 6, 8, 49, 37, tzinfo=timezone.utc) - now_3 = datetime(2048, 11, 6, 8, 49, 37, tzinfo=timezone.utc) + now_1 = datetime(2019, 11, 6, 8, 49, 37, tzinfo=UTC) + now_2 = datetime(2020, 11, 6, 8, 49, 37, tzinfo=UTC) + now_3 = datetime(2048, 11, 6, 8, 49, 37, tzinfo=UTC) tests = ( ( now_1, "Tuesday, 31-Dec-69 08:49:37 GMT", - datetime(2069, 12, 31, 8, 49, 37, tzinfo=timezone.utc), + datetime(2069, 12, 31, 8, 49, 37, tzinfo=UTC), ), ( now_1, "Tuesday, 10-Nov-70 08:49:37 GMT", - datetime(1970, 11, 10, 8, 49, 37, tzinfo=timezone.utc), + datetime(1970, 11, 10, 8, 49, 37, tzinfo=UTC), ), ( now_1, "Sunday, 06-Nov-94 08:49:37 GMT", - datetime(1994, 11, 6, 8, 49, 37, tzinfo=timezone.utc), + datetime(1994, 11, 6, 8, 49, 37, tzinfo=UTC), ), ( now_2, "Wednesday, 31-Dec-70 08:49:37 GMT", - datetime(2070, 12, 31, 8, 49, 37, tzinfo=timezone.utc), + datetime(2070, 12, 31, 8, 49, 37, tzinfo=UTC), ), ( now_2, "Friday, 31-Dec-71 08:49:37 GMT", - datetime(1971, 12, 31, 8, 49, 37, tzinfo=timezone.utc), + datetime(1971, 12, 31, 8, 49, 37, tzinfo=UTC), ), ( now_3, "Sunday, 31-Dec-00 08:49:37 GMT", - datetime(2000, 12, 31, 8, 49, 37, tzinfo=timezone.utc), + datetime(2000, 12, 31, 8, 49, 37, tzinfo=UTC), ), ( now_3, "Friday, 31-Dec-99 08:49:37 GMT", - datetime(1999, 12, 31, 8, 49, 37, tzinfo=timezone.utc), + datetime(1999, 12, 31, 8, 49, 37, tzinfo=UTC), ), ) for now, rfc850str, expected_date in tests: with self.subTest(rfc850str=rfc850str): mocked_datetime.now.return_value = now parsed = parse_http_date(rfc850str) - mocked_datetime.now.assert_called_once_with(tz=timezone.utc) + mocked_datetime.now.assert_called_once_with(tz=UTC) self.assertEqual( - datetime.fromtimestamp(parsed, timezone.utc), + datetime.fromtimestamp(parsed, UTC), expected_date, ) mocked_datetime.reset_mock() @@ -391,8 +391,8 @@ class HttpDateProcessingTests(unittest.TestCase): def test_parsing_asctime(self): parsed = parse_http_date("Sun Nov 6 08:49:37 1994") self.assertEqual( - datetime.fromtimestamp(parsed, timezone.utc), - datetime(1994, 11, 6, 8, 49, 37, tzinfo=timezone.utc), + datetime.fromtimestamp(parsed, UTC), + datetime(1994, 11, 6, 8, 49, 37, tzinfo=UTC), ) def test_parsing_asctime_nonascii_digits(self): @@ -405,8 +405,8 @@ class HttpDateProcessingTests(unittest.TestCase): def test_parsing_year_less_than_70(self): parsed = parse_http_date("Sun Nov 6 08:49:37 0037") self.assertEqual( - datetime.fromtimestamp(parsed, timezone.utc), - datetime(2037, 11, 6, 8, 49, 37, tzinfo=timezone.utc), + datetime.fromtimestamp(parsed, UTC), + datetime(2037, 11, 6, 8, 49, 37, tzinfo=UTC), ) diff --git a/tests/utils_tests/test_timesince.py b/tests/utils_tests/test_timesince.py index 0727e65af4..fdcfa4b281 100644 --- a/tests/utils_tests/test_timesince.py +++ b/tests/utils_tests/test_timesince.py @@ -264,7 +264,7 @@ class TimesinceTests(TestCase): datetime.datetime(2023, 4, 14, 1, 30, 30), zoneinfo.ZoneInfo(key="Asia/Kathmandu"), # UTC+05:45 ) - now_utc = now_with_zoneinfo.astimezone(datetime.timezone.utc) + now_utc = now_with_zoneinfo.astimezone(datetime.UTC) tests = [ (now_with_zoneinfo, "0\xa0minutes"), (now_with_zoneinfo - self.onemicrosecond, "0\xa0minutes"), diff --git a/tests/utils_tests/test_timezone.py b/tests/utils_tests/test_timezone.py index 43bb2bc7a3..01e47aa08a 100644 --- a/tests/utils_tests/test_timezone.py +++ b/tests/utils_tests/test_timezone.py @@ -8,7 +8,7 @@ from django.utils import timezone PARIS_ZI = zoneinfo.ZoneInfo("Europe/Paris") EAT = timezone.get_fixed_timezone(180) # Africa/Nairobi ICT = timezone.get_fixed_timezone(420) # Asia/Bangkok -UTC = datetime.timezone.utc +UTC = datetime.UTC class TimezoneTests(SimpleTestCase): |
