diff --git a/oslo_utils/tests/test_timeutils.py b/oslo_utils/tests/test_timeutils.py index 9466849a..98194f1d 100644 --- a/oslo_utils/tests/test_timeutils.py +++ b/oslo_utils/tests/test_timeutils.py @@ -13,7 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import calendar import datetime import logging import time @@ -48,18 +47,6 @@ class TimeUtilsTest(test_base.BaseTestCase): 6, 14, 0) self.addCleanup(timeutils.clear_time_override) - def test_isotime(self): - with mock.patch('datetime.datetime') as datetime_mock: - datetime_mock.utcnow.return_value = self.skynet_self_aware_time - dt = timeutils.isotime() - self.assertEqual(dt, self.skynet_self_aware_time_str) - - def test_isotimei_micro_second_precision(self): - with mock.patch('datetime.datetime') as datetime_mock: - datetime_mock.utcnow.return_value = self.skynet_self_aware_ms_time - dt = timeutils.isotime(subsecond=True) - self.assertEqual(dt, self.skynet_self_aware_time_ms_str) - def test_parse_isotime(self): expect = timeutils.parse_isotime(self.skynet_self_aware_time_str) skynet_self_aware_time_utc = self.skynet_self_aware_time.replace( @@ -72,40 +59,24 @@ class TimeUtilsTest(test_base.BaseTestCase): tzinfo=iso8601.iso8601.UTC) self.assertEqual(skynet_self_aware_time_ms_utc, expect) - def test_strtime(self): - expect = timeutils.strtime(self.skynet_self_aware_time_perfect) - self.assertEqual(self.skynet_self_aware_time_perfect_str, expect) - def test_parse_strtime(self): perfect_time_format = self.skynet_self_aware_time_perfect_str expect = timeutils.parse_strtime(perfect_time_format) self.assertEqual(self.skynet_self_aware_time_perfect, expect) - def test_strtime_and_back(self): - orig_t = datetime.datetime(1997, 8, 29, 6, 14, 0) - s = timeutils.strtime(orig_t) - t = timeutils.parse_strtime(s) - self.assertEqual(orig_t, t) - @mock.patch('datetime.datetime', wraps=datetime.datetime) def _test_is_older_than(self, fn, datetime_mock): datetime_mock.utcnow.return_value = self.skynet_self_aware_time - expect_true = timeutils.is_older_than(fn(self.one_minute_before), - 59) + expect_true = timeutils.is_older_than(fn(self.one_minute_before), 59) self.assertTrue(expect_true) - expect_false = timeutils.is_older_than(fn(self.one_minute_before), - 60) + expect_false = timeutils.is_older_than(fn(self.one_minute_before), 60) self.assertFalse(expect_false) - expect_false = timeutils.is_older_than(fn(self.one_minute_before), - 61) + expect_false = timeutils.is_older_than(fn(self.one_minute_before), 61) self.assertFalse(expect_false) def test_is_older_than_datetime(self): self._test_is_older_than(lambda x: x) - def test_is_older_than_str(self): - self._test_is_older_than(timeutils.strtime) - def test_is_older_than_aware(self): """Tests sending is_older_than an 'aware' datetime.""" self._test_is_older_than(lambda x: x.replace( @@ -132,9 +103,6 @@ class TimeUtilsTest(test_base.BaseTestCase): def test_is_newer_than_datetime(self): self._test_is_newer_than(lambda x: x) - def test_is_newer_than_str(self): - self._test_is_newer_than(timeutils.strtime) - def test_is_newer_than_aware(self): """Tests sending is_newer_than an 'aware' datetime.""" self._test_is_newer_than(lambda x: x.replace( @@ -227,18 +195,6 @@ class TimeUtilsTest(test_base.BaseTestCase): self.assertAlmostEquals(604859.123456, timeutils.delta_seconds(before, after)) - def test_iso8601_from_timestamp(self): - utcnow = timeutils.utcnow() - iso = timeutils.isotime(utcnow) - ts = calendar.timegm(utcnow.timetuple()) - self.assertEqual(iso, timeutils.iso8601_from_timestamp(ts)) - - def test_iso8601_from_timestamp_ms(self): - ts = timeutils.utcnow_ts(microsecond=True) - utcnow = datetime.datetime.utcfromtimestamp(ts) - iso = timeutils.isotime(utcnow, subsecond=True) - self.assertEqual(iso, timeutils.iso8601_from_timestamp(ts, True)) - def test_is_soon(self): expires = timeutils.utcnow() + datetime.timedelta(minutes=5) self.assertFalse(timeutils.is_soon(expires, 120)) @@ -313,30 +269,6 @@ class TestIso8601Time(test_base.BaseTestCase): self.assertTrue(east < zulu) self.assertTrue(zulu < west) - def test_zulu_roundtrip(self): - time_str = '2012-02-14T20:53:07Z' - zulu = timeutils.parse_isotime(time_str) - self.assertEqual(zulu.tzinfo, iso8601.iso8601.UTC) - self.assertEqual(timeutils.isotime(zulu), time_str) - - def test_east_roundtrip(self): - time_str = '2012-02-14T20:53:07-07:00' - east = timeutils.parse_isotime(time_str) - self.assertEqual(east.tzinfo.tzname(None), '-07:00') - self.assertEqual(timeutils.isotime(east), time_str) - - def test_west_roundtrip(self): - time_str = '2012-02-14T20:53:07+11:30' - west = timeutils.parse_isotime(time_str) - self.assertEqual(west.tzinfo.tzname(None), '+11:30') - self.assertEqual(timeutils.isotime(west), time_str) - - def test_now_roundtrip(self): - time_str = timeutils.isotime() - now = timeutils.parse_isotime(time_str) - self.assertEqual(now.tzinfo, iso8601.iso8601.UTC) - self.assertEqual(timeutils.isotime(now), time_str) - def test_zulu_normalize(self): time_str = '2012-02-14T20:53:07Z' zulu = timeutils.parse_isotime(time_str) diff --git a/oslo_utils/timeutils.py b/oslo_utils/timeutils.py index cb12e0b6..390be530 100644 --- a/oslo_utils/timeutils.py +++ b/oslo_utils/timeutils.py @@ -23,7 +23,6 @@ import functools import logging import time -from debtcollector import removals import iso8601 import pytz @@ -39,28 +38,6 @@ _MAX_DATETIME_SEC = 59 now = time.monotonic -@removals.remove( - message="use datetime.datetime.isoformat()", - version="1.6", - removal_version="?", - ) -def isotime(at=None, subsecond=False): - """Stringify time in ISO 8601 format. - - .. deprecated:: 1.5.0 - Use :func:`utcnow` and :func:`datetime.datetime.isoformat` instead. - """ - if not at: - at = utcnow() - st = at.strftime(_ISO8601_TIME_FORMAT - if not subsecond - else _ISO8601_TIME_FORMAT_SUBSECOND) - tz = at.tzinfo.tzname(None) if at.tzinfo else 'UTC' - # Need to handle either iso8601 or python UTC format - st += ('Z' if tz in ('UTC', 'UTC+00:00') else tz) - return st - - def parse_isotime(timestr): """Parse time from ISO 8601 format.""" try: @@ -71,29 +48,6 @@ def parse_isotime(timestr): raise ValueError(str(e)) -@removals.remove( - message="use either datetime.datetime.isoformat() " - "or datetime.datetime.strftime() instead", - version="1.6", - removal_version="?", - ) -def strtime(at=None, fmt=PERFECT_TIME_FORMAT): - """Returns formatted utcnow. - - .. deprecated:: 1.5.0 - Use :func:`utcnow()`, :func:`datetime.datetime.isoformat` - or :func:`datetime.strftime` instead: - - * ``strtime()`` => ``utcnow().isoformat()`` - * ``strtime(fmt=...)`` => ``utcnow().strftime(fmt)`` - * ``strtime(at)`` => ``at.isoformat()`` - * ``strtime(at, fmt)`` => ``at.strftime(fmt)`` - """ - if not at: - at = utcnow() - return at.strftime(fmt) - - def parse_strtime(timestr, fmt=PERFECT_TIME_FORMAT): """Turn a formatted time back into a datetime.""" return datetime.datetime.strptime(timestr, fmt) @@ -180,24 +134,6 @@ def utcnow(with_timezone=False): return datetime.datetime.utcnow() -@removals.remove( - message="use datetime.datetime.utcfromtimestamp().isoformat()", - version="1.6", - removal_version="?", - ) -def iso8601_from_timestamp(timestamp, microsecond=False): - """Returns an iso8601 formatted date from timestamp. - - .. versionchanged:: 1.3 - Added optional *microsecond* parameter. - - .. deprecated:: 1.5.0 - Use :func:`datetime.datetime.utcfromtimestamp` and - :func:`datetime.datetime.isoformat` instead. - """ - return isotime(datetime.datetime.utcfromtimestamp(timestamp), microsecond) - - utcnow.override_time = None diff --git a/releasenotes/notes/remove-timeutils-deprecated-helpers-5de68c21dd281529.yaml b/releasenotes/notes/remove-timeutils-deprecated-helpers-5de68c21dd281529.yaml new file mode 100644 index 00000000..697a28fb --- /dev/null +++ b/releasenotes/notes/remove-timeutils-deprecated-helpers-5de68c21dd281529.yaml @@ -0,0 +1,7 @@ +--- +upgrade: + - | + The ``isotime``, ``strtime`` and ``iso8601_from_timestamp`` helpers have + been removed from ``oslo_utils.timeutils``. These are all available in the + stdlib in Python 3. +