示例#1
0
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),
    )

    fn1 = NamedTemporaryFile().name
    fn2 = NamedTemporaryFile().name
    p = sort("foo")
    q = p.pipe(duplicates("foo"))
    q.pipe(topickle(fn1))
    q.pipe("remainder", topickle(fn2))
    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(fn1))

    exremainder = (("foo", "bar", "baz"), ("A", 1, 2), ("E", None))
    ieq(exremainder, frompickle(fn2))

    # test with compound key
    p = sort(key=("foo", "bar"))
    q = p.pipe(duplicates(key=("foo", "bar")))
    q.pipe(topickle(fn1))
    q.pipe("remainder", topickle(fn2))
    p.push(table)

    expectation = (("foo", "bar", "baz"), ("B", "2", "3.4"), ("B", "2", 42))
    ieq(expectation, frompickle(fn1))

    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(fn2))
示例#2
0
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))

    fn1 = NamedTemporaryFile().name
    fn2 = NamedTemporaryFile().name
    p = sort('foo')
    q = p.pipe(duplicates('foo'))
    q.pipe(topickle(fn1))
    q.pipe('remainder', topickle(fn2))
    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(fn1))

    exremainder = (('foo', 'bar', 'baz'),
                   ('A', 1, 2), 
                   ('E', None))
    ieq(exremainder, frompickle(fn2))
    
    # test with compound key
    p = sort(key=('foo', 'bar'))
    q = p.pipe(duplicates(key=('foo', 'bar')))
    q.pipe(topickle(fn1))
    q.pipe('remainder', topickle(fn2))
    p.push(table)
    
    expectation = (('foo', 'bar', 'baz'),
                   ('B', '2', '3.4'),
                   ('B', '2', 42))
    ieq(expectation, frompickle(fn1))

    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(fn2))
示例#3
0
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),
    )

    fn1 = NamedTemporaryFile().name
    p = sort("foo")
    p | duplicates("foo") | topickle(fn1)
    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(fn1))
示例#4
0
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))

    fn1 = NamedTemporaryFile().name
    p = sort('foo')
    p | duplicates('foo') | topickle(fn1)
    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(fn1))