def test_duplicates(): table = ( ("foo", "bar", "baz"), ("A", 1, 2), ("B", "2", "3.4"), ("D", "xyz", 9.0), ("B", u"3", u"7.8", True), ("B", "2", 42), ("E", None), ("D", 4, 12.3), ) f1 = NamedTemporaryFile(delete=False) f2 = NamedTemporaryFile(delete=False) p = sort("foo") q = p.pipe(duplicates("foo")) q.pipe(topickle(f1.name)) q.pipe("remainder", topickle(f2.name)) p.push(table) expectation = ( ("foo", "bar", "baz"), ("B", "2", "3.4"), ("B", u"3", u"7.8", True), ("B", "2", 42), ("D", "xyz", 9.0), ("D", 4, 12.3), ) ieq(expectation, frompickle(f1.name)) exremainder = (("foo", "bar", "baz"), ("A", 1, 2), ("E", None)) ieq(exremainder, frompickle(f2.name)) # test with compound key p = sort(key=("foo", "bar")) q = p.pipe(duplicates(key=("foo", "bar"))) q.pipe(topickle(f1.name)) q.pipe("remainder", topickle(f2.name)) p.push(table) expectation = (("foo", "bar", "baz"), ("B", "2", "3.4"), ("B", "2", 42)) ieq(expectation, frompickle(f1.name)) exremainder = ( ("foo", "bar", "baz"), ("A", 1, 2), ("B", u"3", u"7.8", True), ("D", 4, 12.3), ("D", "xyz", 9.0), ("E", None), ) ieq(exremainder, frompickle(f2.name))
def test_duplicates(): table = (('foo', 'bar', 'baz'), ('A', 1, 2), ('B', '2', '3.4'), ('D', 'xyz', 9.0), ('B', u'3', u'7.8', True), ('B', '2', 42), ('E', None), ('D', 4, 12.3)) f1 = NamedTemporaryFile(delete=False) f2 = NamedTemporaryFile(delete=False) p = sort('foo') q = p.pipe(duplicates('foo')) q.pipe(topickle(f1.name)) q.pipe('remainder', topickle(f2.name)) p.push(table) expectation = (('foo', 'bar', 'baz'), ('B', '2', '3.4'), ('B', u'3', u'7.8', True), ('B', '2', 42), ('D', 'xyz', 9.0), ('D', 4, 12.3)) iassertequal(expectation, frompickle(f1.name)) exremainder = (('foo', 'bar', 'baz'), ('A', 1, 2), ('E', None)) iassertequal(exremainder, frompickle(f2.name)) # test with compound key p = sort(key=('foo', 'bar')) q = p.pipe(duplicates(key=('foo', 'bar'))) q.pipe(topickle(f1.name)) q.pipe('remainder', topickle(f2.name)) p.push(table) expectation = (('foo', 'bar', 'baz'), ('B', '2', '3.4'), ('B', '2', 42)) iassertequal(expectation, frompickle(f1.name)) exremainder = (('foo', 'bar', 'baz'), ('A', 1, 2), ('B', u'3', u'7.8', True), ('D', 4, 12.3), ('D', 'xyz', 9.0), ('E', None)) iassertequal(exremainder, frompickle(f2.name))
def test_operator_overload(): table = ( ("foo", "bar", "baz"), ("A", 1, 2), ("B", "2", "3.4"), ("D", "xyz", 9.0), ("B", u"3", u"7.8", True), ("B", "2", 42), ("E", None), ("D", 4, 12.3), ) f1 = NamedTemporaryFile(delete=False) p = sort("foo") p | duplicates("foo") | topickle(f1.name) p.push(table) expectation = ( ("foo", "bar", "baz"), ("B", "2", "3.4"), ("B", u"3", u"7.8", True), ("B", "2", 42), ("D", "xyz", 9.0), ("D", 4, 12.3), ) ieq(expectation, frompickle(f1.name))
def test_operator_overload(): table = (('foo', 'bar', 'baz'), ('A', 1, 2), ('B', '2', '3.4'), ('D', 'xyz', 9.0), ('B', u'3', u'7.8', True), ('B', '2', 42), ('E', None), ('D', 4, 12.3)) f1 = NamedTemporaryFile(delete=False) p = sort('foo') p | duplicates('foo') | topickle(f1.name) p.push(table) expectation = (('foo', 'bar', 'baz'), ('B', '2', '3.4'), ('B', u'3', u'7.8', True), ('B', '2', 42), ('D', 'xyz', 9.0), ('D', 4, 12.3)) ieq(expectation, frompickle(f1.name))
def test_duplicates(): table = (('foo', 'bar', 'baz'), ('A', 1, 2), ('B', '2', '3.4'), ('D', 'xyz', 9.0), ('B', u'3', u'7.8', True), ('B', '2', 42), ('E', None), ('D', 4, 12.3)) f1 = NamedTemporaryFile(delete=False) f2 = NamedTemporaryFile(delete=False) p = sort('foo') q = p.pipe(duplicates('foo')) q.pipe(topickle(f1.name)) q.pipe('remainder', topickle(f2.name)) p.push(table) expectation = (('foo', 'bar', 'baz'), ('B', '2', '3.4'), ('B', u'3', u'7.8', True), ('B', '2', 42), ('D', 'xyz', 9.0), ('D', 4, 12.3)) ieq(expectation, frompickle(f1.name)) exremainder = (('foo', 'bar', 'baz'), ('A', 1, 2), ('E', None)) ieq(exremainder, frompickle(f2.name)) # test with compound key p = sort(key=('foo', 'bar')) q = p.pipe(duplicates(key=('foo', 'bar'))) q.pipe(topickle(f1.name)) q.pipe('remainder', topickle(f2.name)) p.push(table) expectation = (('foo', 'bar', 'baz'), ('B', '2', '3.4'), ('B', '2', 42)) ieq(expectation, frompickle(f1.name)) exremainder = (('foo', 'bar', 'baz'), ('A', 1, 2), ('B', u'3', u'7.8', True), ('D', 4, 12.3), ('D', 'xyz', 9.0), ('E', None)) ieq(exremainder, frompickle(f2.name))
def test_operator_overload(): table = (('foo', 'bar', 'baz'), ('A', 1, 2), ('B', '2', '3.4'), ('D', 'xyz', 9.0), ('B', u'3', u'7.8', True), ('B', '2', 42), ('E', None), ('D', 4, 12.3)) f1 = NamedTemporaryFile(delete=False) p = sort('foo') p | duplicates('foo') | topickle(f1.name) p.push(table) expectation = (('foo', 'bar', 'baz'), ('B', '2', '3.4'), ('B', u'3', u'7.8', True), ('B', '2', 42), ('D', 'xyz', 9.0), ('D', 4, 12.3)) iassertequal(expectation, frompickle(f1.name))