Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest failing in test_tool.py #273

Open
scottj97 opened this issue Oct 25, 2021 · 2 comments
Open

pytest failing in test_tool.py #273

scottj97 opened this issue Oct 25, 2021 · 2 comments

Comments

@scottj97
Copy link
Contributor

With Python 3.8.9, beginning with 3d64330 (#263), pytest is failing 4 tests from tests/test_tool.py, all like so:

____________________________________________________________________ TestHOCONConverter.test_convert_from_file _____________________________________________________________________

self = <test_tool.TestHOCONConverter object at 0x7f641c840d90>

    def test_convert_from_file(self):
>       self._test_convert_from_file(TestHOCONConverter.CONFIG_STRING, TestHOCONConverter.EXPECTED_JSON, 'json')

tests/test_tool.py:165: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/test_tool.py:158: in _test_convert_from_file
    HOCONConverter.convert_from_file(fdin.name, fdout.name, format)
pyhocon/converter.py:271: in convert_from_file
    res = cls.convert(config, output_format, indent, compact)
pyhocon/converter.py:250: in convert
    return converters[output_format](config, compact, indent)
pyhocon/converter.py:43: in to_json
    new_value = cls.to_json(item, compact, indent, level + 1)
pyhocon/converter.py:65: in to_json
    lines += cls._timedelta_to_str(config)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <class 'pyhocon.converter.HOCONConverter'>, config = datetime.timedelta(days=4)

    @classmethod
    def _timedelta_to_str(cls, config):
>       if isinstance(config, relativedelta):
E       TypeError: isinstance() arg 2 must be a type or tuple of types

pyhocon/converter.py:301: TypeError
============================================================================= short test summary info ==============================================================================
FAILED tests/test_tool.py::TestHOCONConverter::test_to_json - TypeError: isinstance() arg 2 must be a type or tuple of types
FAILED tests/test_tool.py::TestHOCONConverter::test_to_yaml - TypeError: isinstance() arg 2 must be a type or tuple of types
FAILED tests/test_tool.py::TestHOCONConverter::test_to_properties - TypeError: isinstance() arg 2 must be a type or tuple of types
FAILED tests/test_tool.py::TestHOCONConverter::test_convert_from_file - TypeError: isinstance() arg 2 must be a type or tuple of types
=============================================================== 4 failed, 231 passed, 1 xfailed, 2 warnings in 1.44s ===============================================================

cc @gabis-precog

@scottj97
Copy link
Contributor Author

Note that I do not have the dateutil module installed.

@scottj97
Copy link
Contributor Author

This change seems to resolve the issue, though I'm not sure it's the right way to fix it:

diff --git a/pyhocon/converter.py b/pyhocon/converter.py
index 52f38cf..c84a6e0 100644
--- a/pyhocon/converter.py
+++ b/pyhocon/converter.py
@@ -298,7 +298,7 @@ class HOCONConverter(object):
 
     @classmethod
     def _timedelta_to_str(cls, config):
-        if isinstance(config, relativedelta):
+        if relativedelta is not None and isinstance(config, relativedelta):
             time_delta = cls._relative_delta_to_timedelta(config)
         else:
             time_delta = config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant