summaryrefslogtreecommitdiffstats
path: root/test/units
diff options
context:
space:
mode:
authorSloane Hertel <19572925+s-hertel@users.noreply.github.com>2023-07-26 23:26:33 +0200
committerGitHub <noreply@github.com>2023-07-26 23:26:33 +0200
commit4c41562270df66620b6169b790ba603151035076 (patch)
tree47eec82a68580c4e6925340c4df5e4672aa9517f /test/units
parentpep8: fix sanity for 3.12 (#81348) (diff)
downloadansible-4c41562270df66620b6169b790ba603151035076.tar.xz
ansible-4c41562270df66620b6169b790ba603151035076.zip
remove deprecated datetime.datetime methods (#81323)
* Remove datetime.datetime.utcfromtimestamp and datetime.datetime.uctnow from controller code since they are deprecated in Python 3.12. * Update target side code to use new utcfromtimestamp and utcnow utils in ansible.module_utils.compat.datetime that return aware datetime objects on Python 2.7 and 3. Co-authored-by: Matt Clay <matt@mystile.com>
Diffstat (limited to 'test/units')
-rw-r--r--test/units/module_utils/facts/test_date_time.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/test/units/module_utils/facts/test_date_time.py b/test/units/module_utils/facts/test_date_time.py
index 6abc36a7ec..6cc05f97a6 100644
--- a/test/units/module_utils/facts/test_date_time.py
+++ b/test/units/module_utils/facts/test_date_time.py
@@ -10,28 +10,27 @@ import datetime
import string
import time
+from ansible.module_utils.compat.datetime import UTC
from ansible.module_utils.facts.system import date_time
EPOCH_TS = 1594449296.123456
DT = datetime.datetime(2020, 7, 11, 12, 34, 56, 124356)
-DT_UTC = datetime.datetime(2020, 7, 11, 2, 34, 56, 124356)
+UTC_DT = datetime.datetime(2020, 7, 11, 2, 34, 56, 124356)
@pytest.fixture
def fake_now(monkeypatch):
"""
- Patch `datetime.datetime.fromtimestamp()`, `datetime.datetime.utcfromtimestamp()`,
+ Patch `datetime.datetime.fromtimestamp()`,
and `time.time()` to return deterministic values.
"""
class FakeNow:
@classmethod
- def fromtimestamp(cls, timestamp):
- return DT
-
- @classmethod
- def utcfromtimestamp(cls, timestamp):
- return DT_UTC
+ def fromtimestamp(cls, timestamp, tz=None):
+ if tz == UTC:
+ return UTC_DT.replace(tzinfo=tz)
+ return DT.replace(tzinfo=tz)
def _time():
return EPOCH_TS