예제 #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),
    )

    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))
예제 #2
0
파일: test_push.py 프로젝트: greeness/petl
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))
예제 #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),
    )

    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))
예제 #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))

    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))
예제 #5
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))

    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))
예제 #6
0
파일: test_push.py 프로젝트: greeness/petl
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))