예제 #1
0
def test_add():
    a = Array(Value("int"))
    a.add(1)
    a.add(2)

    assert a.add(2) == a
    assert a[0] == 1
    assert a[1] == 2
예제 #2
0
def test_set():
    a = Array(Value("str"))
    a.set("abc")
    assert a.value == ["a", "b", "c"]

    a = Array(Value("int"))
    a.set([1, 2, 3])
    assert a.value == [1, 2, 3]
예제 #3
0
def test_getitem_without_base_type():
    a = Array(Value("int"))
    a.add(1)
    a.add("2")

    assert a[0] == 1
    assert a[1] == 2
예제 #4
0
def test_getitem_with_base_type():
    a = Array(Value("int"), strict=True)
    a.add(1)
    a.add("2")

    assert a[0] is 1
    assert a[1] == 2
예제 #5
0
class Cont2(Container):
    body = {
        "a": Value("int", meta={"edit": True}),
        "b": Value("int", meta={"edit": False}),
        "c": Value("int", meta={"edit": True})
    }


_body = {
    "v1": Value("int"),
    "v2": Value("float"),
    "v3": Value("bool"),
    "v4": Value("str", required=True),
    "a1": Any(),
    "a2": Any(),
    "r1": Array(Value("int")),
    "d1": Dictionary(),
    "c1": Cont()
}


class C(Container):
    body = _body


@pytest.fixture
def cont():
    c1 = C()
    c1["v1"] = 1
    c1["v2"] = 2
    c1["v3"] = 2
예제 #6
0
def test_get_value_only_valid():
    a = Array(Value("int"), strict=False)
    a.add(1)
    a.add("2.a")

    assert a.get() == [1]
예제 #7
0
def test_type():
    a = Array(Value("int"))

    assert a.type == "array"
예제 #8
0
def test_empty_array_value():
    a = Array(Value("int"))

    assert a.value is None
예제 #9
0
def test_is_list():
    a = Array(Value("int"))

    assert isinstance(a._value, list)