def test_searchcomplement(): table1 = (('foo', 'bar', 'baz'), ('orange', 12, 'oranges are nice fruit'), ('mango', 42, 'I like them'), ('banana', 74, 'lovely too'), ('cucumber', 41, 'better than mango')) # search any field table2 = searchcomplement(table1, '.g.') expect2 = (('foo', 'bar', 'baz'), ('banana', 74, 'lovely too')) ieq(expect2, table2) ieq(expect2, table2) # search a specific field table3 = searchcomplement(table1, 'foo', '.g.') expect3 = (('foo', 'bar', 'baz'), ('banana', 74, 'lovely too'), ('cucumber', 41, 'better than mango')) ieq(expect3, table3) ieq(expect3, table3) # search any field, using complement table2 = search(table1, '.g.', complement=True) expect2 = (('foo', 'bar', 'baz'), ('banana', 74, 'lovely too')) ieq(expect2, table2) ieq(expect2, table2) # search a specific field, using complement table3 = search(table1, 'foo', '.g.', complement=True) expect3 = (('foo', 'bar', 'baz'), ('banana', 74, 'lovely too'), ('cucumber', 41, 'better than mango')) ieq(expect3, table3) ieq(expect3, table3)
def test_search_unicode(): tbl = ((u'name', u'id'), (u'Արամ Խաչատրյան', 1), (u'Johann Strauß', 2), (u'Вагиф Сәмәдоғлу', 3), (u'章子怡', 4)) actual = search(tbl, u'.Խա.') expect = ((u'name', u'id'), (u'Արամ Խաչատրյան', 1)) ieq(expect, actual) ieq(expect, actual)
def test_search_2(): # test ported from selectre table = (('foo', 'bar', 'baz'), ('aa', 4, 9.3), ('aaa', 2, 88.2), ('b', 1, 23.3), ('ccc', 8, 42.0), ('bb', 7, 100.9), ('c', 2)) actual = search(table, 'foo', '[ab]{2}') expect = (('foo', 'bar', 'baz'), ('aa', 4, 9.3), ('aaa', 2, 88.2), ('bb', 7, 100.9)) ieq(expect, actual) ieq(expect, actual)