def test_recordlookup(): t1 = (('foo', 'bar'), ('a', 1), ('b', 2), ('b', 3)) lkp = recordlookup(t1, 'foo') eq_(['a'], [r.foo for r in lkp['a']]) eq_(['b', 'b'], [r.foo for r in lkp['b']]) eq_([1], [r.bar for r in lkp['a']]) eq_([2, 3], [r.bar for r in lkp['b']]) # key only lkp = recordlookup(cut(t1, 'foo'), 'foo') eq_(['a'], [r.foo for r in lkp['a']]) eq_(['b', 'b'], [r.foo for r in lkp['b']])
def test_recordlookup(): """Test the recordlookup function.""" t1 = (('foo', 'bar'), ('a', 1), ('b', 2), ('b', 3)) actual = recordlookup(t1, 'foo') expect = { 'a': [{ 'foo': 'a', 'bar': 1 }], 'b': [{ 'foo': 'b', 'bar': 2 }, { 'foo': 'b', 'bar': 3 }] } eq_(expect, actual) t2 = (('foo', 'bar', 'baz'), ('a', 1, True), ('b', 2, False), ('b', 3, True), ('b', 3, False)) # test compound key actual = recordlookup(t2, ('foo', 'bar')) expect = { ('a', 1): [{ 'foo': 'a', 'bar': 1, 'baz': True }], ('b', 2): [{ 'foo': 'b', 'bar': 2, 'baz': False }], ('b', 3): [{ 'foo': 'b', 'bar': 3, 'baz': True }, { 'foo': 'b', 'bar': 3, 'baz': False }] } eq_(expect, actual)
def test_recordlookup(): """Test the recordlookup function.""" t1 = (('foo', 'bar'), ('a', 1), ('b', 2), ('b', 3)) lkp = recordlookup(t1, 'foo') eq_([1], [r.bar for r in lkp['a']]) eq_([2, 3], [r.bar for r in lkp['b']])
def test_recordlookup(): """Test the recordlookup function.""" t1 = (("foo", "bar"), ("a", 1), ("b", 2), ("b", 3)) lkp = recordlookup(t1, "foo") eq_([1], [r.bar for r in lkp["a"]]) eq_([2, 3], [r.bar for r in lkp["b"]])
def test_recordlookup(): """Test the recordlookup function.""" t1 = (('foo', 'bar'), ('a', 1), ('b', 2), ('b', 3)) actual = recordlookup(t1, 'foo') expect = {'a': [{'foo': 'a', 'bar': 1}], 'b': [{'foo': 'b', 'bar': 2}, {'foo': 'b', 'bar': 3}]} eq_(expect, actual) t2 = (('foo', 'bar', 'baz'), ('a', 1, True), ('b', 2, False), ('b', 3, True), ('b', 3, False)) # test compound key actual = recordlookup(t2, ('foo', 'bar')) expect = {('a', 1): [{'foo': 'a', 'bar': 1, 'baz': True}], ('b', 2): [{'foo': 'b', 'bar': 2, 'baz': False}], ('b', 3): [{'foo': 'b', 'bar': 3, 'baz': True}, {'foo': 'b', 'bar': 3, 'baz': False}]} eq_(expect, actual)