[Bug 1875997] Review Request: python-jsons - Python library for (de)serializing objects to/from JSON

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



https://bugzilla.redhat.com/show_bug.cgi?id=1875997



--- Comment #1 from Andy Mender <andymenderunix@xxxxxxxxx> ---
> Koji scratch build:
> fails due to missing dependency

Yes, the following needs to be added next to the existing BuildRequires:
BuildRequires:  python3dist(typish)

Tested in COPR:
https://copr.fedorainfracloud.org/coprs/andymenderunix/metrics2mqtt-and-dependencies/build/1650399/

There is quite a lot of tests failing, however. I'll look into it.

=================================== FAILURES
===================================
____________ TestSpecificVersions.test_dump_dataclass_with_optional
____________

args = (<tests.test_specific_versions.TestSpecificVersions
testMethod=test_dump_dataclass_with_optional>,)
kwargs = {}

    @skipUnless(dont_skip, reason=reason)
    def _wrapper(*args, **kwargs):
>       return decorated(*args, **kwargs)

tests/test_specific_versions.py:31: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/test_specific_versions.py:88: in test_dump_dataclass_with_optional
    self.assertDictEqual(expected, dumped)
E   AssertionError: {'x': [42, None, 123]} != {}
E   - {'x': [42, None, 123]}
E   + {}
______________ TestSpecificVersions.test_namedtuple_with_optional
______________

args = (<tests.test_specific_versions.TestSpecificVersions
testMethod=test_namedtuple_with_optional>,)
kwargs = {}

    @skipUnless(dont_skip, reason=reason)
    def _wrapper(*args, **kwargs):
>       return decorated(*args, **kwargs)

tests/test_specific_versions.py:31: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests/test_specific_versions.py:74: in test_namedtuple_with_optional
    jsons.load({'arg': None}, NamedTupleWithOptional))
jsons/_load_impl.py:98: in load
    return _do_load(json_obj, deserializer, cls, initial, **kwargs_)
jsons/_load_impl.py:110: in _do_load
    result = deserializer(json_obj, cls, **kwargs)
jsons/deserializers/default_tuple.py:23: in default_tuple_deserializer
    return default_namedtuple_deserializer(obj, cls,
key_transformer=key_transformer, **kwargs)
jsons/deserializers/default_tuple.py:80: in default_namedtuple_deserializer
    loaded_field = load(field, cls_, key_transformer=key_transformer, **kwargs)
jsons/_load_impl.py:75: in load
    _check_for_none(json_obj, cls)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

json_obj = None, cls = typing.Optional[str]

    def _check_for_none(json_obj: object, cls: type):
        # Check if the json_obj is None and whether or not that is fine.
        if json_obj is None and not can_match_with_none(cls):
            cls_name = get_class_name(cls).lower()
>           raise DeserializationError(
                message='NoneType cannot be deserialized into
{}'.format(cls_name),
                source=json_obj,
                target=cls)
E           jsons.exceptions.DeserializationError: NoneType cannot be
deserialized into optional

jsons/_load_impl.py:213: DeserializationError
_________________________ TestUnion.test_load_optional
_________________________

self = <tests.test_union.TestUnion testMethod=test_load_optional>

    def test_load_optional(self):
        class TestOptionalInt:
            def __init__(self, value: Optional[int]):
                self.value = value

        # This seems fine.
>       loaded1 = jsons.load({'value': 42}, cls=TestOptionalInt)

tests/test_union.py:102: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
jsons/_load_impl.py:98: in load
    return _do_load(json_obj, deserializer, cls, initial, **kwargs_)
jsons/_load_impl.py:110: in _do_load
    result = deserializer(json_obj, cls, **kwargs)
jsons/deserializers/default_object.py:39: in default_object_deserializer
    constructor_args = _get_constructor_args(obj, cls, **kwargs)
jsons/deserializers/default_object.py:63: in _get_constructor_args
    key, value = _get_value_for_attr(obj=obj,
jsons/deserializers/default_object.py:93: in _get_value_for_attr
    result = sig_key, _get_value_from_obj(obj, cls, sig, sig_key,
jsons/deserializers/default_object.py:134: in _get_value_from_obj
    value = load(obj[sig_key], cls_, meta_hints=new_hints, **kwargs)
jsons/_load_impl.py:98: in load
    return _do_load(json_obj, deserializer, cls, initial, **kwargs_)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

json_obj = 42, deserializer = None, cls = typing.Optional[int], initial = False
kwargs = {'_initial': False, 'attr_getters': None, 'fork_inst': <class
'jsons._common_impl.StateHolder'>, 'meta_hints': {}, ...}
cls_name = 'typing.Optional'

    def _do_load(json_obj: object,
                 deserializer: callable,
                 cls: type,
                 initial: bool,
                 **kwargs):
        cls_name = get_class_name(cls, fully_qualified=True)
        if deserializer is None:
>           raise DeserializationError('No deserializer for type "{}"'.format(cls_name), json_obj, cls)
E           jsons.exceptions.DeserializationError: No deserializer for type
"typing.Optional"

jsons/_load_impl.py:108: DeserializationError
__________________________ TestUnion.test_load_union
___________________________

self = <tests.test_union.TestUnion testMethod=test_load_union>

    def test_load_union(self):
        class A:
            def __init__(self, x):
                self.x = x

        class B:
            def __init__(self, x: Optional[int]):
                self.x = x

        class C:
            def __init__(self, x: Union[datetime.datetime, A]):
                self.x = x

        # Test loading with None value without type hint.
        self.assertEqual(None, jsons.load({'x': None}, A).x)

        # Test Optional with a value.
>       self.assertEqual(1, jsons.load({'x': 1}, B).x)

tests/test_union.py:63: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
jsons/_load_impl.py:98: in load
    return _do_load(json_obj, deserializer, cls, initial, **kwargs_)
jsons/_load_impl.py:110: in _do_load
    result = deserializer(json_obj, cls, **kwargs)
jsons/deserializers/default_object.py:39: in default_object_deserializer
    constructor_args = _get_constructor_args(obj, cls, **kwargs)
jsons/deserializers/default_object.py:63: in _get_constructor_args
    key, value = _get_value_for_attr(obj=obj,
jsons/deserializers/default_object.py:93: in _get_value_for_attr
    result = sig_key, _get_value_from_obj(obj, cls, sig, sig_key,
jsons/deserializers/default_object.py:134: in _get_value_from_obj
    value = load(obj[sig_key], cls_, meta_hints=new_hints, **kwargs)
jsons/_load_impl.py:98: in load
    return _do_load(json_obj, deserializer, cls, initial, **kwargs_)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

json_obj = 1, deserializer = None, cls = typing.Optional[int], initial = False
kwargs = {'_initial': False, 'attr_getters': None, 'fork_inst': <class
'jsons._common_impl.StateHolder'>, 'meta_hints': {}, ...}
cls_name = 'typing.Optional'

    def _do_load(json_obj: object,
                 deserializer: callable,
                 cls: type,
                 initial: bool,
                 **kwargs):
        cls_name = get_class_name(cls, fully_qualified=True)
        if deserializer is None:
>           raise DeserializationError('No deserializer for type "{}"'.format(cls_name), json_obj, cls)
E           jsons.exceptions.DeserializationError: No deserializer for type
"typing.Optional"

jsons/_load_impl.py:108: DeserializationError
__________________ TestVarious.test_load_recursive_structure
___________________

self = <tests.test_various.TestVarious
testMethod=test_load_recursive_structure>

    def test_load_recursive_structure(self):
        source = {
            'value': 10,
            'next': {
                'value': 20,
                'next': {
                    'value': 30,
                    'next': None
                }
            }
        }
>       loaded = jsons.load(source, Node)

tests/test_various.py:53: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
jsons/_load_impl.py:98: in load
    return _do_load(json_obj, deserializer, cls, initial, **kwargs_)
jsons/_load_impl.py:110: in _do_load
    result = deserializer(json_obj, cls, **kwargs)
jsons/deserializers/default_object.py:39: in default_object_deserializer
    constructor_args = _get_constructor_args(obj, cls, **kwargs)
jsons/deserializers/default_object.py:63: in _get_constructor_args
    key, value = _get_value_for_attr(obj=obj,
jsons/deserializers/default_object.py:93: in _get_value_for_attr
    result = sig_key, _get_value_from_obj(obj, cls, sig, sig_key,
jsons/deserializers/default_object.py:134: in _get_value_from_obj
    value = load(obj[sig_key], cls_, meta_hints=new_hints, **kwargs)
jsons/_load_impl.py:98: in load
    return _do_load(json_obj, deserializer, cls, initial, **kwargs_)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

json_obj = {'next': {'next': None, 'value': 30}, 'value': 20}
deserializer = None, cls = typing.Optional[tests.test_various.Node]
initial = False
kwargs = {'_initial': False, 'attr_getters': None, 'fork_inst': <class
'jsons._common_impl.StateHolder'>, 'meta_hints': {}, ...}
cls_name = 'typing.Optional'

    def _do_load(json_obj: object,
                 deserializer: callable,
                 cls: type,
                 initial: bool,
                 **kwargs):
        cls_name = get_class_name(cls, fully_qualified=True)
        if deserializer is None:
>           raise DeserializationError('No deserializer for type "{}"'.format(cls_name), json_obj, cls)
E           jsons.exceptions.DeserializationError: No deserializer for type
"typing.Optional"

jsons/_load_impl.py:108: DeserializationError


-- 
You are receiving this mail because:
You are on the CC list for the bug.
You are always notified about changes to this product and component
_______________________________________________
package-review mailing list -- package-review@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to package-review-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/package-review@xxxxxxxxxxxxxxxxxxxxxxx




[Index of Archives]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite Conditions]     [KDE Users]

  Powered by Linux