コード例 #1
0
def test_fieldwalker_clean_result_1():
    doc = {"a": 5, "b": 8}

    fieldwalker = FieldWalker(doc)

    with fieldwalker:
        fieldwalker.go("b").get()
        fieldwalker.go("a").get()

        assert fieldwalker.value == [5]
コード例 #2
0
def test_fieldwalker_value_set_8():
    doc = {}

    fieldwalker = FieldWalker(doc)
    with fieldwalker:
        fieldwalker.go("a.b")
        fieldwalker.set(1)
        fieldwalker.go("a")
        with pytest.raises(FieldWriteError):
            fieldwalker.set(2)
コード例 #3
0
def test_fieldwalker_value_set_5():
    doc = {}

    fieldwalker = FieldWalker(doc)
    with fieldwalker:
        fieldwalker.go("a.b")
        fieldwalker.set(10)
        fieldwalker.go("c")
        fieldwalker.set(99)
        assert doc == {}
    assert doc == {"a": {"b": 10}, "c": 99}
コード例 #4
0
def test_fieldwalker_value_set_7():
    doc = {"a": [{"b": 0}, {"b": 1}]}
    path = "a.b"
    value = 10

    fieldwalker = FieldWalker(doc)
    with fieldwalker.go(path):
        with pytest.raises(FieldWriteError):
            fieldwalker.set(value)
コード例 #5
0
def test_fieldwalker_value_set_6():
    doc = {"a": [1]}
    path = "a.2.b"
    value = 20

    fieldwalker = FieldWalker(doc)
    with fieldwalker.go(path):
        fieldwalker.set(value)
    assert doc == {"a": [1, None, {"b": 20}]}
コード例 #6
0
def test_fieldwalker_value_set_3():
    doc = {"a": [1, 2, 3]}
    path = "a.1"
    value = 20

    fieldwalker = FieldWalker(doc)
    with fieldwalker.go(path):
        fieldwalker.set(value)
    assert doc == {"a": [1, 20, 3]}
コード例 #7
0
def test_fieldwalker_value_set_2():
    doc = {"a": {"b": 1}}
    path = "a.b"
    value = 10

    fieldwalker = FieldWalker(doc)
    with fieldwalker.go(path):
        fieldwalker.set(value)
    assert doc == {"a": {"b": 10}}
コード例 #8
0
def test_fieldwalker_value_set_9():
    doc = {"a": [{"b": 0}, {"b": 1}]}
    path = "a.1.b"
    value = 10

    fieldwalker = FieldWalker(doc)
    with fieldwalker.go(path):
        fieldwalker.set(value)
        fieldwalker.commit()
    assert fieldwalker.doc == {"a": [{"b": 0}, {"b": 10}]}
コード例 #9
0
def test_fieldwalker_value_set_4():
    doc = {"a": [1, 2, 3]}
    path = "a.5"
    value = 9

    fieldwalker = FieldWalker(doc)
    with fieldwalker.go(path):
        fieldwalker.set(value)
        assert doc == {"a": [1, 2, 3]}
    assert doc == {"a": [1, 2, 3, None, None, 9]}
コード例 #10
0
def test_fieldwalker_value_set_1():
    # single value
    doc = {"a": 1}
    path = "a"
    value = 10

    fieldwalker = FieldWalker(doc)
    with fieldwalker.go(path):
        fieldwalker.set(value)
    assert doc == {"a": 10}