pyhocon icon indicating copy to clipboard operation
pyhocon copied to clipboard

pytest failing in test_tool.py

Open scottj97 opened this issue 4 years ago • 2 comments

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 avatar Oct 25 '21 19:10 scottj97

Note that I do not have the dateutil module installed.

scottj97 avatar Oct 25 '21 19:10 scottj97

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

scottj97 avatar Oct 25 '21 19:10 scottj97