示例#1
0
    def __eq__(self, other):
        if isinstance(other, LocationScore):
            other = other.to_dict(api_compatible=False)

        if isinstance(other, dict):
            dict_form = self.to_dict(api_compatible=False)
            if checkers.are_dicts_equivalent(dict_form, other):
                return True

            dict_form = self.to_dict(api_compatible=True)
            if checkers.are_dicts_equivalent(dict_form, other):
                return True

        return False
示例#2
0
def test_LocationScore_from_json(obj, api_compatible, error):
    if obj:
        if obj.get('updated', None) is not None:
            obj['updated'] = obj.get('updated').isoformat()
        elif 'walk' in obj and obj.get('walk', {}).get('updated',
                                                       None) is not None:
            obj['walk']['updated'] = obj['walk']['updated'].isoformat()

        obj = json.dumps(obj)

    if not error:
        result = LocationScore.from_json(obj, api_compatible=api_compatible)
    else:
        with pytest.raises(error):
            result = LocationScore.from_json(obj,
                                             api_compatible=api_compatible)

    if not error:
        assert isinstance(result, LocationScore) is True

        serialized_result = result.to_dict(api_compatible=api_compatible)

        roundtrip_result = LocationScore.from_json(
            serialized_result, api_compatible=api_compatible)
        roundtrip_serialization = roundtrip_result.to_dict(
            api_compatible=api_compatible)

        if serialized_result.get('updated',
                                 None) != roundtrip_serialization.get(
                                     'updated', None):
            serialized_result['updated'] = 123
            roundtrip_serialization['updated'] = 123

        assert checkers.are_dicts_equivalent(roundtrip_serialization,
                                             serialized_result) is True
示例#3
0
def test_LocationScore_from_dict(obj, api_compatible, error):
    if not error:
        result = LocationScore.from_dict(obj, api_compatible=api_compatible)
    else:
        with pytest.raises(error):
            result = LocationScore.from_dict(obj,
                                             api_compatible=api_compatible)

    if not error:
        assert isinstance(result, LocationScore) is True

        serialized_result = result.to_dict(api_compatible=api_compatible)
        print(serialized_result)

        roundtrip_result = LocationScore.from_dict(
            serialized_result, api_compatible=api_compatible)
        roundtrip_serialization = roundtrip_result.to_dict(
            api_compatible=api_compatible)

        if serialized_result.get('updated',
                                 None) != roundtrip_serialization.get(
                                     'updated', None):
            serialized_result['updated'] = 123
            roundtrip_serialization['updated'] = 123

        assert checkers.are_dicts_equivalent(roundtrip_serialization,
                                             serialized_result) is True
示例#4
0
def test_parse_yaml(input_value, deserialize_function, expected_result, error):
    if not error:
        result = parse_yaml(input_value,
                            deserialize_function=deserialize_function)

        assert isinstance(result, dict)
        assert checkers.are_dicts_equivalent(result, expected_result)
    else:
        with pytest.raises(error):
            result = parse_yaml(input_value)
示例#5
0
def test_model_set_attribute_serialization_config(request,
                                                  model_complex,
                                                  model_complex_meta,
                                                  original_hybrid_config,
                                                  use_meta,
                                                  test_index,
                                                  attribute,
                                                  params,
                                                  expected_result_params):
    if not use_meta:
        model = model_complex
    else:
        model = model_complex_meta

    target = model[test_index]

    target.set_attribute_serialization_config(attribute, **params)

    result = target.get_attribute_serialization_config(attribute)
    assert result.supports_csv == expected_result_params.get('supports_csv')
    assert result.csv_sequence == expected_result_params.get('csv_sequence')
    assert result.supports_json == expected_result_params.get('supports_json')
    assert result.supports_yaml == expected_result_params.get('supports_yaml')
    assert result.supports_dict == expected_result_params.get('supports_dict')
    assert checkers.are_dicts_equivalent(result.on_deserialize,
                                         expected_result_params.get('on_deserialize'))
    assert checkers.are_dicts_equivalent(result.on_serialize,
                                         expected_result_params.get('on_serialize'))

    target.set_attribute_serialization_config(attribute,
                                              config = original_hybrid_config,
                                              supports_csv = True,
                                              supports_json = True,
                                              supports_yaml = True,
                                              supports_dict = True,
                                              csv_sequence = False,
                                              on_serialize = False,
                                              on_deserialize = False)

    assert target.get_attribute_serialization_config(attribute).supports_csv == \
        (True, True)
示例#6
0
def test_parse_csv(input_value, kwargs, expected_result, error):
    if not error:
        if kwargs:
            result = parse_csv(input_value, **kwargs)
        else:
            result = parse_csv(input_value)

        print(result)

        assert isinstance(result, dict)
        assert checkers.are_dicts_equivalent(result, expected_result)
    else:
        with pytest.raises(error):
            if kwargs:
                result = parse_csv(input_value, **kwargs)
            else:
                result = parse_csv(input_value)
示例#7
0
def test_iterable__to_dict(input_value, format, max_nesting, current_nesting,
                           expected_result, warning, error):
    if not error:
        result = iterable__to_dict(input_value,
                                   format,
                                   max_nesting=max_nesting,
                                   current_nesting=current_nesting)

        if isinstance(result, dict):
            assert checkers.are_dicts_equivalent(result, expected_result)
        else:
            assert result == expected_result
    else:
        with pytest.raises(error):
            result = iterable__to_dict(input_value,
                                       format,
                                       max_nesting=max_nesting,
                                       current_nesting=current_nesting)
示例#8
0
def test_LocationScore_to_dict(arguments, api_compatible, expected_result,
                               error):
    if arguments and not error:
        obj = LocationScore(**arguments)
    elif not arguments and not error:
        obj = LocationScore()

    if not error:
        result = obj.to_dict(api_compatible=api_compatible)
    else:
        with pytest.raises(error):
            result = obj.to_dict(api_compatible=api_compatible)

    if not error:
        assert result is not None
        print('result:')
        print(result)
        print('expected:')
        print(expected_result)
        if result.get('updated', None) != expected_result.get('updated', None):
            result['updated'] = 123
            expected_result['updated'] = 123

        assert checkers.are_dicts_equivalent(result, expected_result) is True