Beispiel #1
0
def test_multimap_empty_key():
    m = MultiMap()
    assert list(MultiMapKey().ancestors) == [MultiMapKey()]

    m[MultiMapKey()] = u'Value for the empty'
    assert m[MultiMapKey()] == u'Value for the empty'
    assert list(m.all(MultiMapKey())) == [u'Value for the empty']
Beispiel #2
0
def test_multimap_empty_key():
    m = MultiMap()
    assert list(MultiMapKey().ancestors) == [MultiMapKey()]

    m[MultiMapKey()] = u'Value for the empty'
    assert m[MultiMapKey()] == u'Value for the empty'
    assert list(m.all(MultiMapKey())) == [u'Value for the empty']
Beispiel #3
0
def test_multimap_get():
    m = MultiMap()

    alpha = MapKey('alpha')

    one = MapKey('one')

    m[MultiMapKey(alpha, one)] = u'Value for alpha, one'

    assert m.get(MultiMapKey(alpha, one)) == u'Value for alpha, one'

    assert m.get(MultiMapKey(one, alpha)) is None
    assert m.get(MultiMapKey(one, alpha), 'default') == 'default'
Beispiel #4
0
def test_multimap_get():
    m = MultiMap()

    alpha = MapKey('alpha')

    one = MapKey('one')

    m[MultiMapKey(alpha, one)] = u'Value for alpha, one'

    assert m.get(MultiMapKey(alpha, one)) == u'Value for alpha, one'

    assert m.get(MultiMapKey(one, alpha)) is None
    assert m.get(MultiMapKey(one, alpha), 'default') == 'default'
Beispiel #5
0
def test_multimap_with_fallback():
    m = MultiMap()

    alpha = MapKey('alpha')
    beta = MapKey('beta', [alpha])
    gamma = MapKey('gamma', [beta])

    one = MapKey('one')
    two = MapKey('two', [one])
    three = MapKey('three', [two])

    m[MultiMapKey(alpha, three)] = u'Value for alpha, three'
    m[MultiMapKey(beta, two)] = u'Value for beta, two'

    # fallback
    m[MultiMapKey(alpha, one)] = u'Value for alpha, one'

    # this gets the more specific interface
    assert m[MultiMapKey(alpha, three)] == u'Value for alpha, three'
    assert m[MultiMapKey(beta, two)] == u'Value for beta, two'

    assert m[MultiMapKey(gamma, two)] == u'Value for beta, two'
    assert m[MultiMapKey(beta, three)] == u'Value for beta, two'
    assert m[MultiMapKey(gamma, three)] == u'Value for beta, two'

    # this uses the fallback
    assert m[MultiMapKey(alpha, one)] == u'Value for alpha, one'
    assert m[MultiMapKey(alpha, two)] == u'Value for alpha, one'
    assert m[MultiMapKey(beta, one)] == u'Value for alpha, one'
Beispiel #6
0
def test_multimap():
    m = MultiMap()

    alpha = MapKey('alpha')
    beta = MapKey('beta', [alpha])
    gamma = MapKey('gamma', [beta])

    one = MapKey('one')
    two = MapKey('two', [one])
    three = MapKey('three', [two])

    m[MultiMapKey(alpha, three)] = u'Value for alpha, three'
    m[MultiMapKey(beta, two)] = u'Value for beta, two'

    assert m[MultiMapKey(alpha, three)] == u'Value for alpha, three'
    assert m[MultiMapKey(beta, two)] == u'Value for beta, two'

    assert m[MultiMapKey(gamma, two)] == u'Value for beta, two'
    assert m[MultiMapKey(beta, three)] == u'Value for beta, two'
    assert m[MultiMapKey(gamma, three)] == u'Value for beta, two'

    with pytest.raises(KeyError):
        m[MultiMapKey(alpha, one)]
    with pytest.raises(KeyError):
        m[MultiMapKey(alpha, two)]
    with pytest.raises(KeyError):
        m[MultiMapKey(beta, one)]
Beispiel #7
0
def test_multimap_arity_1():
    m = MultiMap()

    alpha = MapKey('alpha')
    beta = MapKey('beta', [alpha])

    m[MultiMapKey(alpha)] = u'Value for alpha'
    m[MultiMapKey(beta)] = u'Value for beta'

    assert m[MultiMapKey(alpha)] == u'Value for alpha'
    assert m[MultiMapKey(beta)] == u'Value for beta'
Beispiel #8
0
def test_multimap_all():
    m = MultiMap()

    alpha = MapKey('alpha')
    beta = MapKey('beta', [alpha])
    gamma = MapKey('gamma', [beta])

    one = MapKey('one')
    two = MapKey('two', [one])
    three = MapKey('three', [two])

    m[MultiMapKey(alpha, three)] = u'Value for alpha, three'
    m[MultiMapKey(beta, two)] = u'Value for beta, two'
    m[MultiMapKey(alpha, one)] = u'Value for alpha, one'

    # this gets the more specific interface
    assert list(m.all(MultiMapKey(alpha, three))) == [
        u'Value for alpha, three', u'Value for alpha, one'
    ]
    assert list(m.all(MultiMapKey(
        beta, two))) == [u'Value for beta, two', u'Value for alpha, one']
    assert list(m.all(MultiMapKey(
        gamma, two))) == [u'Value for beta, two', u'Value for alpha, one']
    assert list(m.all(MultiMapKey(beta, three))) == [
        u'Value for beta, two', u'Value for alpha, three',
        u'Value for alpha, one'
    ]
    assert list(m.all(MultiMapKey(gamma, three))) == [
        u'Value for beta, two', u'Value for alpha, three',
        u'Value for alpha, one'
    ]

    # this uses the fallback only
    assert list(m.all(MultiMapKey(alpha, one))) == [u'Value for alpha, one']
    assert list(m.all(MultiMapKey(alpha, two))) == [u'Value for alpha, one']
    assert list(m.all(MultiMapKey(beta, one))) == [u'Value for alpha, one']

    # we get nothing at all
    frub = MapKey('frub')
    assert list(m.all(MultiMapKey(frub, ))) == []
Beispiel #9
0
def test_multimap_all():
    m = MultiMap()

    alpha = MapKey('alpha')
    beta = MapKey('beta', [alpha])
    gamma = MapKey('gamma', [beta])

    one = MapKey('one')
    two = MapKey('two', [one])
    three = MapKey('three', [two])

    m[MultiMapKey(alpha, three)] = u'Value for alpha, three'
    m[MultiMapKey(beta, two)] = u'Value for beta, two'
    m[MultiMapKey(alpha, one)] = u'Value for alpha, one'

    # this gets the more specific interface
    assert list(m.all(MultiMapKey(alpha, three))) == [
        u'Value for alpha, three',
        u'Value for alpha, one']
    assert list(m.all(MultiMapKey(beta, two))) == [
        u'Value for beta, two',
        u'Value for alpha, one']
    assert list(m.all(MultiMapKey(gamma, two))) == [
        u'Value for beta, two',
        u'Value for alpha, one']
    assert list(m.all(MultiMapKey(beta, three))) == [
        u'Value for beta, two',
        u'Value for alpha, three',
        u'Value for alpha, one']
    assert list(m.all(MultiMapKey(gamma, three))) == [
        u'Value for beta, two',
        u'Value for alpha, three',
        u'Value for alpha, one']

    # this uses the fallback only
    assert list(m.all(MultiMapKey(alpha, one))) == [u'Value for alpha, one']
    assert list(m.all(MultiMapKey(alpha, two))) == [u'Value for alpha, one']
    assert list(m.all(MultiMapKey(beta, one))) == [u'Value for alpha, one']

    # we get nothing at all
    frub = MapKey('frub')
    assert list(m.all(MultiMapKey(frub,))) == []