diff --git a/UnleashClient/constraints/Constraint.py b/UnleashClient/constraints/Constraint.py index 764fad28..90054ca9 100644 --- a/UnleashClient/constraints/Constraint.py +++ b/UnleashClient/constraints/Constraint.py @@ -1,10 +1,10 @@ # pylint: disable=invalid-name, too-few-public-methods, use-a-generator from datetime import datetime from enum import Enum -from typing import Optional, Union +from typing import Any, Optional, Union import semver -from dateutil.parser import ParserError, parse +from dateutil.parser import parse from UnleashClient.utils import LOGGER, get_identifier @@ -123,13 +123,22 @@ def check_date_operators(self, context_value: Union[datetime, str]) -> bool: return_value = False parsing_exception = False + DateUtilParserError: Any + + try: + from dateutil.parser import ParserError + + DateUtilParserError = ParserError + except ImportError: + DateUtilParserError = ValueError + try: parsed_date = parse(self.value) if isinstance(context_value, str): context_date = parse(context_value) else: context_date = context_value - except ParserError: + except DateUtilParserError: LOGGER.error(f"Unable to parse date: {self.value}") parsing_exception = True diff --git a/tests/unit_tests/test_features.py b/tests/unit_tests/test_features.py index a3b55703..2c8bffd5 100644 --- a/tests/unit_tests/test_features.py +++ b/tests/unit_tests/test_features.py @@ -88,7 +88,7 @@ def test_create_feature_exception(test_feature): def test_select_variation_novariation(test_feature): selected_variant = test_feature.get_variant() - assert type(selected_variant) == dict + assert isinstance(selected_variant, dict) assert selected_variant["name"] == "disabled"