Ejemplo n.º 1
0
def test_dynamic_dump_action(action_type, value):
    """In 2.4 when an action is passed, the action is returned with a dumped value"""
    typedef = DynamicType()
    action = action_type.new_action(value)
    v = typedef._dump(action, context=None)
    assert isinstance(v, actions.Action)
    assert v.type is action_type
    assert isinstance(v.value, dict)
Ejemplo n.º 2
0
def test_dynamic_path_returns_self():
    """
    Because the type of a dynamic map/list's type is unknown when building a condition,
    the __getitem__ operation should always return the same DynamicType instance for
    arbitrary nesting.
    """
    dt = DynamicType()
    node = dt
    for key in ["foo", "bar", 4, "baz", 2, 3]:
        node = node[key]
        assert node is dt
Ejemplo n.º 3
0
def test_dynamic_dynamo_operations_raise():
    """
    DynamicType's dynamo_load, dynamo_dump operations can never work, since the outer
    context is required to look up the correct type.  These should always raise."""
    dt = DynamicType()

    with pytest.raises(NotImplementedError):
        dt.dynamo_load("foo", context=None)
    with pytest.raises(NotImplementedError):
        dt.dynamo_dump("foo", context=None)
Ejemplo n.º 4
0
def test_dynamic_unknown_set_backing_type(value):
    with pytest.raises(ValueError):
        DynamicType.backing_type_for({value})
Ejemplo n.º 5
0
def test_dynamic_backing_types(value, type):
    assert DynamicType.backing_type_for(value) == type
Ejemplo n.º 6
0
def test_dynamic_extract_backing_type():
    """DynamicType looks at the key of a dict"""
    assert DynamicType.extract_backing_type({"foo": {"bar": "baz"}}) == "foo"
Ejemplo n.º 7
0
def test_dynamic_dump_none():
    """DynamicType doesn't delegate when dumping None, since there isn't type information"""
    dt = DynamicType()
    assert dt._dump(None) is None
Ejemplo n.º 8
0
def test_dynamic_load_dump_symmetric(wire, local):
    dt = DynamicType()
    assert dt._dump(local, context=None) == wire
    assert dt._load(wire, context=None) == local
Ejemplo n.º 9
0
def test_dynamic_supports_operation():
    """DynamicType needs to support at least the build-in bloop operations"""
    dt = DynamicType()
    for operation in OPERATION_SUPPORT_BY_OP.keys():
        assert dt.supports_operation(operation)