Example #1
0
def test_inverse_map_exact():
    m = InverseMap()

    animal = MapKey('animal')
    elephant = MapKey('elephant', parents=[animal])

    m.register(animal, 'Animal')

    m.exact_getitem(animal) == 'Animal'
    with pytest.raises(KeyError):
        m.exact_getitem(elephant)
    assert m.exact_get(animal) == 'Animal'
    assert m.exact_get(elephant) is None
    assert m.exact_get(elephant, 'default') == 'default'
Example #2
0
def test_inverse_map_registration_order():
    m = InverseMap()

    animal = MapKey('animal')
    elephant = MapKey('elephant', parents=[animal])
    african_elephant = MapKey('african elephant', parents=[elephant])

    m.register(elephant, 'Elephant')
    m.register(animal, 'Animal')

    assert list(m.all(animal)) == ['Animal', 'Elephant']
    assert list(m.all(elephant)) == ['Elephant']
    assert list(m.all(african_elephant)) == []
Example #3
0
def test_inverse_map_two_descendants():
    m = InverseMap()

    animal = MapKey('animal')
    elephant = MapKey('elephant', parents=[animal])
    rhino = MapKey('rhino', parents=[animal])

    m.register(elephant, 'Elephant')
    m.register(rhino, 'Rhino')

    assert list(m.all(elephant)) == ['Elephant']
    assert list(m.all(rhino)) == ['Rhino']

    # we get out the descendants in declaration order
    assert list(m.all(animal)) == ['Elephant', 'Rhino']
Example #4
0
def test_inverse_map_registration_order():
    m = InverseMap()

    animal = MapKey('animal')
    elephant = MapKey('elephant', parents=[animal])
    african_elephant = MapKey('african elephant', parents=[elephant])

    m.register(elephant, 'Elephant')
    m.register(animal, 'Animal')

    assert list(m.all(animal)) == ['Animal', 'Elephant']
    assert list(m.all(elephant)) == ['Elephant']
    assert list(m.all(african_elephant)) == []
Example #5
0
def test_inverse_map_two_descendants():
    m = InverseMap()

    animal = MapKey('animal')
    elephant = MapKey('elephant', parents=[animal])
    rhino = MapKey('rhino', parents=[animal])

    m.register(elephant, 'Elephant')
    m.register(rhino, 'Rhino')

    assert list(m.all(elephant)) == ['Elephant']
    assert list(m.all(rhino)) == ['Rhino']

    # we get out the descendants in declaration order
    assert list(m.all(animal)) == ['Elephant', 'Rhino']
Example #6
0
def test_inverse_map_sub2():
    m = InverseMap()

    animal = MapKey('animal')
    elephant = MapKey('elephant', parents=[animal])
    african_elephant = MapKey('african elephant', parents=[elephant])

    m.register(african_elephant, 'African Elephant')

    assert list(m.all(animal)) == ['African Elephant']
    assert list(m.all(elephant)) == ['African Elephant']
    assert list(m.all(african_elephant)) == ['African Elephant']
Example #7
0
def test_inverse_map_sub2():
    m = InverseMap()

    animal = MapKey('animal')
    elephant = MapKey('elephant', parents=[animal])
    african_elephant = MapKey('african elephant', parents=[elephant])

    m.register(african_elephant, 'African Elephant')

    assert list(m.all(animal)) == ['African Elephant']
    assert list(m.all(elephant)) == ['African Elephant']
    assert list(m.all(african_elephant)) == ['African Elephant']
Example #8
0
def test_inverse_map_empty():
    m = InverseMap()

    animal = MapKey('animal')

    assert list(m.all(animal)) == []
Example #9
0
def test_inverse_map_empty():
    m = InverseMap()

    animal = MapKey('animal')

    assert list(m.all(animal)) == []
Example #10
0
def test_inverse_map_exact():
    m = InverseMap()

    animal = MapKey('animal')
    elephant = MapKey('elephant', parents=[animal])

    m.register(animal, 'Animal')

    m.exact_getitem(animal) == 'Animal'
    with pytest.raises(KeyError):
        m.exact_getitem(elephant)
    assert m.exact_get(animal) == 'Animal'
    assert m.exact_get(elephant) is None
    assert m.exact_get(elephant, 'default') == 'default'