diff options
author | Matt Clay <matt@mystile.com> | 2023-08-09 21:24:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-09 21:24:10 +0200 |
commit | d0699cb44a35a90588f53692e075b354e3ff96e4 (patch) | |
tree | ecdaa780ace772afac1f6883622b429627c81669 /test/units/module_utils | |
parent | Remove unreachable code in password lookup test (#81482) (diff) | |
download | ansible-d0699cb44a35a90588f53692e075b354e3ff96e4.tar.xz ansible-d0699cb44a35a90588f53692e075b354e3ff96e4.zip |
Add unit tests for module_utils.compat.datetime (#81483)
Diffstat (limited to 'test/units/module_utils')
-rw-r--r-- | test/units/module_utils/compat/__init__.py | 0 | ||||
-rw-r--r-- | test/units/module_utils/compat/test_datetime.py | 34 |
2 files changed, 34 insertions, 0 deletions
diff --git a/test/units/module_utils/compat/__init__.py b/test/units/module_utils/compat/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/units/module_utils/compat/__init__.py diff --git a/test/units/module_utils/compat/test_datetime.py b/test/units/module_utils/compat/test_datetime.py new file mode 100644 index 0000000000..66a0ad0ba7 --- /dev/null +++ b/test/units/module_utils/compat/test_datetime.py @@ -0,0 +1,34 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import datetime + +from ansible.module_utils.compat.datetime import utcnow, utcfromtimestamp, UTC +from ansible.module_utils.six import PY3 + + +def test_utc(): + assert UTC.tzname(None) == 'UTC' + assert UTC.utcoffset(None) == datetime.timedelta(0) + + if PY3: + assert UTC.dst(None) is None + else: + assert UTC.dst(None) == datetime.timedelta(0) + + +def test_utcnow(): + assert utcnow().tzinfo is UTC + + +def test_utcfometimestamp_zero(): + dt = utcfromtimestamp(0) + + assert dt.tzinfo is UTC + assert dt.year == 1970 + assert dt.month == 1 + assert dt.day == 1 + assert dt.hour == 0 + assert dt.minute == 0 + assert dt.second == 0 + assert dt.microsecond == 0 |