Esempio n. 1
0
def test_tagged_dictionary_views_work():
    x = TaggedDict()
    y = x.view("animals")
    z = y.view("insects")

    z["0"] = "butterfly"
    z["1"] = "bee"
    assert len(z) == 2

    z1 = y.view("mammals")
    z1["0"] = "dog"

    w = x.view("things")
    w["0"] = "chair"

    assert len(z) == 2
    assert len(z1) == 1
    assert len(y) == 3

    assert len(w) == 1

    assert len(x) == 4

    assert set(x.values()) == {"chair", "dog", "bee", "butterfly"}
    assert set(x[()]) == {"chair", "dog", "bee", "butterfly"}
Esempio n. 2
0
def test_tagged_dictionary_views_add_method_unique_handles():
    x = TaggedDict()
    y = x.view("animals")

    h1 = y.add("dog")
    h2 = y.add("cat")

    assert h1 != h2
Esempio n. 3
0
def test_tagged_dictionary_views_can_remove_by_value():
    x = TaggedDict()
    y = x.view("animals")

    h1 = y.add("dog")

    y.remove("dog")
    assert not y

    with pytest.raises(ValueError):
        y.remove("dog")
Esempio n. 4
0
def test_tagged_dictionary_views_add_method():
    x = TaggedDict()
    y = x.view("animals")

    h = y.add("dog")

    assert h
    assert y[()] == ["dog"]
    assert x[()] == ["dog"]

    assert h in x
    del x[h]
    assert not x
Esempio n. 5
0
def test_tagged_dictionary_views_added_tag_reflects_on_other_tags():
    x = TaggedDict()
    y = x.view("animals")
    z = y.view("insects")
    z1 = y.view("mammals")

    assert not y

    z["mammals"] = "spyderman"

    assert y
    assert len(y) == 1
    assert len(z) == 1

    assert x["insects", "mammals"] == ["spyderman"]
Esempio n. 6
0
def test_tagged_dictionary_can_delete_simple_items():
    x = TaggedDict()
    x["simple"] = "simple"
    del x["simple"]

    with pytest.raises(KeyError):
        x["simple"]
Esempio n. 7
0
def test_tagged_dictionary_can_delete_itens_by_any_tag():
    x = TaggedDict()
    x["first", "second"] = "element"
    del x["first"]
    assert not x

    x["first", "second"] = "element"
    del x["second"]
    assert not x

    x["first", "second"] = "element"
    del x["second", "first"]
    assert not x

    x["first", "second"] = "element"
    with pytest.raises(KeyError):
        x["simple", "second", "third"]

    assert x
Esempio n. 8
0
def test_tagged_dictionary_can_contain_items_with_2_tags():
    x = TaggedDict()
    x["first", "second"] = "element"

    assert x["first"] == ["element"]
    assert x["second"] == ["element"]
Esempio n. 9
0
def test_tagged_dictionary_can_contain_simple_items():
    x = TaggedDict()
    x["simple"] = "simple"

    assert x["simple"] == ["simple"]
Esempio n. 10
0
def test_tagged_dictionary_is_created():
    x = TaggedDict()
    assert not x