diff options
author | Matt Clay <matt@mystile.com> | 2022-07-28 05:28:19 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-28 05:28:19 +0300 |
commit | b86a18bd273499f5d10e581821a47571690660e1 (patch) | |
tree | 7bede0a5c322af66243b3d4d71801780baaacd57 | |
parent | 1368bfa34821df099fde36c6e655d92d40bf24f5 (diff) |
Remove unit test pytz requirement. (#78368)
-rw-r--r-- | test/units/module_utils/common/text/converters/test_json_encode_fallback.py | 23 | ||||
-rw-r--r-- | test/units/parsing/test_ajson.py | 7 | ||||
-rw-r--r-- | test/units/requirements.txt | 1 |
3 files changed, 21 insertions, 10 deletions
diff --git a/test/units/module_utils/common/text/converters/test_json_encode_fallback.py b/test/units/module_utils/common/text/converters/test_json_encode_fallback.py index 8cf33529a2d..022f38f4665 100644 --- a/test/units/module_utils/common/text/converters/test_json_encode_fallback.py +++ b/test/units/module_utils/common/text/converters/test_json_encode_fallback.py @@ -7,21 +7,34 @@ __metaclass__ = type import pytest -from datetime import datetime - -from pytz import timezone as tz +from datetime import datetime, timedelta, tzinfo from ansible.module_utils.common.text.converters import _json_encode_fallback +class timezone(tzinfo): + """Simple timezone implementation for use until we drop Python 2.7 support.""" + def __init__(self, offset): + self._offset = offset + + def utcoffset(self, dt): + return self._offset + + def dst(self, dt): + return timedelta(0) + + def tzname(self, dt): + return None + + @pytest.mark.parametrize( 'test_input,expected', [ (set([1]), [1]), (datetime(2019, 5, 14, 13, 39, 38, 569047), '2019-05-14T13:39:38.569047'), (datetime(2019, 5, 14, 13, 47, 16, 923866), '2019-05-14T13:47:16.923866'), - (datetime(2019, 6, 15, 14, 45, tzinfo=tz('UTC')), '2019-06-15T14:45:00+00:00'), - (datetime(2019, 6, 15, 14, 45, tzinfo=tz('Europe/Helsinki')), '2019-06-15T14:45:00+01:40'), + (datetime(2019, 6, 15, 14, 45, tzinfo=timezone(timedelta(0))), '2019-06-15T14:45:00+00:00'), + (datetime(2019, 6, 15, 14, 45, tzinfo=timezone(timedelta(hours=1, minutes=40))), '2019-06-15T14:45:00+01:40'), ] ) def test_json_encode_fallback(test_input, expected): diff --git a/test/units/parsing/test_ajson.py b/test/units/parsing/test_ajson.py index 55e758e2db1..1b9a76b4ceb 100644 --- a/test/units/parsing/test_ajson.py +++ b/test/units/parsing/test_ajson.py @@ -11,8 +11,7 @@ import json import pytest from collections.abc import Mapping -from datetime import date, datetime -from pytz import timezone as tz +from datetime import date, datetime, timezone, timedelta from ansible.parsing.ajson import AnsibleJSONEncoder, AnsibleJSONDecoder from ansible.parsing.yaml.objects import AnsibleVaultEncryptedUnicode @@ -127,8 +126,8 @@ class TestAnsibleJSONEncoder: (datetime(2019, 5, 14, 13, 47, 16, 923866), '2019-05-14T13:47:16.923866'), (date(2019, 5, 14), '2019-05-14'), (date(2020, 5, 14), '2020-05-14'), - (datetime(2019, 6, 15, 14, 45, tzinfo=tz('UTC')), '2019-06-15T14:45:00+00:00'), - (datetime(2019, 6, 15, 14, 45, tzinfo=tz('Europe/Helsinki')), '2019-06-15T14:45:00+01:40'), + (datetime(2019, 6, 15, 14, 45, tzinfo=timezone.utc), '2019-06-15T14:45:00+00:00'), + (datetime(2019, 6, 15, 14, 45, tzinfo=timezone(timedelta(hours=1, minutes=40))), '2019-06-15T14:45:00+01:40'), ] ) def test_date_datetime(self, ansible_json_encoder, test_input, expected): diff --git a/test/units/requirements.txt b/test/units/requirements.txt index 9ed7268fab7..76f3baa35e3 100644 --- a/test/units/requirements.txt +++ b/test/units/requirements.txt @@ -1,6 +1,5 @@ bcrypt ; python_version >= '3.8' # controller only passlib ; python_version >= '3.8' # controller only pexpect ; python_version >= '3.8' # controller only -pytz pywinrm ; python_version >= '3.8' # controller only unittest2 ; python_version < '2.7' |