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']
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,))) == []
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, ))) == []