예제 #1
0
def test_filter():
    a = ElementTypeContainer({1: {"key": "Living_room"}, 2: {"key": "Kids_room"}})
    assert len(a) == 2
    a.filter([1])

    assert a[1] == {"key": "Living_room"}
    assert len(a) == 1
    with pytest.raises(KeyError):
        assert a[2] == {"key": "Kids_room"}
예제 #2
0
def test_repr():
    a = ElementTypeContainer({
        1: {
            'key': 'Living_room'
        },
        3: {
            'key': 'Kids_room'
        }
    })

    assert a.__repr__(
    ) == "{1: {'key': 'Living_room'}, 3: {'key': 'Kids_room'}}"
    assert a.__str__(
    ) == "{1: {'key': 'Living_room'}, 3: {'key': 'Kids_room'}}"
예제 #3
0
def test_filter():
    a = ElementTypeContainer({
        1: {
            'key': 'Living_room'
        },
        2: {
            'key': 'Kids_room'
        }
    })
    assert len(a) == 2
    a.filter([1])

    assert a[1] == {'key': 'Living_room'}
    assert len(a) == 1
    with pytest.raises(KeyError):
        assert a[2] == {'key': 'Kids_room'}
예제 #4
0
def test_set():
    a = ElementTypeContainer({1: {"key": "El 1"}, 2: {"key": "El 2"}})

    a["El 1"]["test"] = "one"
    assert a[1]["test"] == "one"

    a[1]["test"] = "two"
    assert a["El 1"]["test"] == "two"
예제 #5
0
def test_get_by_key():
    a = ElementTypeContainer({1: {"key": "El 1"}, 2: {"key": "El 2"}})

    assert a["El 1"]["key"] == "El 1"

    assert a["1"]["key"] == "El 1"

    assert a[1]["key"] == "El 1"
예제 #6
0
def test_hole():
    a = ElementTypeContainer({1: {"key": "Living_room"}, 3: {"key": "Kids_room"}})

    assert 1 in a
    assert 3 in a

    assert "Kids_room" in a
    assert "Living_room" in a
예제 #7
0
def test_get():
    d = datetime.now()
    a = ElementTypeContainer(date=dict(time=d))

    assert a["date"]["time"] == d

    with pytest.raises(KeyError):
        a["date"]["not_found"]
예제 #8
0
def test_delete():
    a = ElementTypeContainer({1: {"key": "El 1"}, 2: {"key": "El 2"}})

    del a["El 1"]

    assert a["El 2"]["key"] == "El 2"
    with pytest.raises(KeyError):
        a["El 1"]
예제 #9
0
def test_filter():
    a = ElementTypeContainer({1: {"key": "El 1"}, 2: {"key": "El 2"}})

    a.filter(["El 1", "El 2"])

    assert len(a) == 2

    a.filter(["El 1"])  # drops El 2

    assert len(a) == 1

    a.filter([1])

    assert len(a) == 1

    a.filter([2])  # 2 does not exist

    assert len(a) == 0
예제 #10
0
def test_text_index_updates():
    a = ElementTypeContainer({1: {"key": "El 1"}, 2: {"key": "El 2"}})
    assert len(a.key_index) == 2

    a[3] = {"key": "El 3"}
    assert len(a.key_index) == 3

    a.filter([1, 3])

    assert len(a.key_index) == 2

    assert a["El 1"]["key"] == "El 1"
    assert a["El 3"]["key"] == "El 3"
    with pytest.raises(KeyError):
        a[2]

    del a["El 1"]
    assert len(a.key_index) == 1

    with pytest.raises(KeyError):
        a[1]
예제 #11
0
def test_del():
    a = ElementTypeContainer({
        1: {
            'key': 'Living_room'
        },
        3: {
            'key': 'Kids_room'
        }
    })

    del a['Kids_room']

    assert a == {1: {'key': 'Living_room'}}
예제 #12
0
def test_get_index():
    a = ElementTypeContainer({1: {"key": "El 1"}, 2: {"key": "El 2"}})

    assert a.get_index("El 1") == 1
    assert a.get_index(1) == 1

    b = ElementTypeContainer({
        "test": {
            "key": "El 1"
        },
        "other": {
            "key": "El 2"
        }
    })

    assert b.get_index("other") == "other"
    assert b.get_index("test") == "test"
예제 #13
0
def test_hole():
    a = ElementTypeContainer({
        1: {
            'key': 'Living_room'
        },
        3: {
            'key': 'Kids_room'
        }
    })

    assert 1 in a
    assert 3 in a

    assert 'Kids_room' in a
    assert 'Living_room' in a
예제 #14
0
def test_update():
    a = ElementTypeContainer({1: {"key": "Living_room"}})

    a.deep_merge({3: {"key": "Kids_room"}})
    a.deep_merge({1: {"label": "Living room"}})

    assert a == {
        1: {"key": "Living_room", "label": "Living room"},
        3: {"key": "Kids_room"},
    }
예제 #15
0
def test_select():
    a = ElementTypeContainer(
        {1: {"key": "Living_room", "id": 1}, 3: {"key": "Kids_room", "id": 3}}
    )

    assert a.select("all") == [1, 3]
    assert a.select("0") == [1, 3]

    assert a.select("Living_room") == [1]

    assert a.select("1") == [1]
예제 #16
0
def test_update():
    a = ElementTypeContainer({1: {'key': 'Living_room'}})

    a.deep_merge({3: {'key': 'Kids_room'}})
    a.deep_merge({1: {'label': 'Living room'}})

    assert a == {
        1: {
            'key': 'Living_room',
            'label': 'Living room'
        },
        3: {
            'key': 'Kids_room'
        }
    }
예제 #17
0
def test_select():
    a = ElementTypeContainer({
        1: {
            'key': 'Living_room',
            'id': 1
        },
        3: {
            'key': 'Kids_room',
            'id': 3
        }
    })

    assert a.select('all') == [1, 3]
    assert a.select('0') == [1, 3]

    assert a.select('Living_room') == [1]

    assert a.select('1') == [1]
예제 #18
0
def test_set_by_string_key():
    a = ElementTypeContainer({1: {'key': 'Living_room', 'val': 25}})
    a['1'] = {'key': 'Living_room', 'val': 17}

    assert a['Living_room'] == {'key': 'Living_room', 'val': 17}
예제 #19
0
def test_del():
    a = ElementTypeContainer({1: {"key": "Living_room"}, 3: {"key": "Kids_room"}})

    del a["Kids_room"]

    assert a == {1: {"key": "Living_room"}}
예제 #20
0
def test_get_by_key():
    a = ElementTypeContainer({1: {"key": "Living_room", "val": 25}})

    assert a["Living_room"] == {"key": "Living_room", "val": 25}
예제 #21
0
def test_get_by_key():
    a = ElementTypeContainer({1: {'key': 'Living_room', 'val': 25}})

    assert a['Living_room'] == {'key': 'Living_room', 'val': 25}
예제 #22
0
def test_set_by_string_key():
    a = ElementTypeContainer({1: {"key": "Living_room", "val": 25}})
    a["1"] = {"key": "Living_room", "val": 17}

    assert a["Living_room"] == {"key": "Living_room", "val": 17}
예제 #23
0
def test_deep_merge():
    a = ElementTypeContainer({1: {"key": "Living_room", "val": 25}})
    a.deep_merge({1: {"beer": 10}})

    assert a[1] == {"key": "Living_room", "val": 25, "beer": 10}
예제 #24
0
def test_deep_merge():
    a = ElementTypeContainer({1: {'key': 'Living_room', 'val': 25}})
    a.deep_merge({1: {'beer': 10}})

    assert a[1] == {'key': 'Living_room', 'val': 25, 'beer': 10}
예제 #25
0
def test_select():
    a = ElementTypeContainer({1: {"key": "El 1"}, 2: {"key": "El 2"}})

    assert len(a.select("all")) == 2
    assert a.select("all") == [1, 2]
    assert len(a.select("0")) == 2
    assert a.select("0") == [1, 2]

    assert len(a.select("2")) == 1
    assert a.select("2") == [2]
    assert len(a.select("El 2")) == 1
    assert a.select("El 2") == [2]

    assert len(a.select([1, 2])) == 2
    assert a.select([1, 2]) == [1, 2]
    assert a.select(["El 1", "El 2"]) == [1, 2]
예제 #26
0
def test_contains():
    a = ElementTypeContainer({1: {"key": "El 1"}, 2: {"key": "El 2"}})
    assert "El 1" in a
    assert 1 in a