Esempio n. 1
0
def test_diff():

    tablea = (("foo", "bar", "baz"), ("A", 1, True), ("B", 2, False), ("C", 7, False), ("C", 9, True))

    tableb = (("x", "y", "z"), ("A", 9, False), ("B", 2, False), ("B", 3, True), ("C", 9, True))

    aminusb = (("foo", "bar", "baz"), ("A", 1, True), ("C", 7, False))

    bminusa = (("foo", "bar", "baz"), ("A", 9, False), ("B", 3, True))

    both = (("foo", "bar", "baz"), ("B", 2, False), ("C", 9, True))

    fn1 = NamedTemporaryFile().name
    fn2 = NamedTemporaryFile().name
    fn3 = NamedTemporaryFile().name
    p = diff()
    p.pipe("+", topickle(fn1))
    p.pipe("-", topickle(fn2))
    p.pipe(topickle(fn3))
    p.push(tablea, tableb)

    added, subtracted, common = (frompickle(fn1), frompickle(fn2), frompickle(fn3))
    ieq(bminusa, added)
    ieq(aminusb, subtracted)
    ieq(both, common)
Esempio n. 2
0
def test_unique():

    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(unique('foo'))
    q.pipe(topickle(fn1))
    q.pipe('remainder', topickle(fn2))
    p.push(table)

    expectation = (('foo', 'bar', 'baz'),
                   ('A', 1, 2), 
                   ('E', None))
    ieq(expectation, frompickle(fn1))

    exremainder = (('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(exremainder, frompickle(fn2))
Esempio n. 3
0
def test_unique():

    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(unique("foo"))
    q.pipe(topickle(fn1))
    q.pipe("remainder", topickle(fn2))
    p.push(table)

    expectation = (("foo", "bar", "baz"), ("A", 1, 2), ("E", None))
    ieq(expectation, frompickle(fn1))

    exremainder = (
        ("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(exremainder, frompickle(fn2))
Esempio n. 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))
Esempio n. 5
0
def test_topickle_pipe():

    t = [('fruit', 'city', 'sales'),
         ('orange', 'London', 12),
         ('banana', 'London', 42),
         ('orange', 'Paris', 31),
         ('banana', 'Amsterdam', 74),
         ('kiwi', 'Berlin', 55)]

    fn1 = NamedTemporaryFile().name
    fn2 = NamedTemporaryFile().name
    p = topickle(fn1)
    p.pipe(topickle(fn2))
    p.push(t)

    ieq(t, frompickle(fn1))
    ieq(t, frompickle(fn2))
Esempio n. 6
0
def test_topickle_pipe():

    t = [
        ("fruit", "city", "sales"),
        ("orange", "London", 12),
        ("banana", "London", 42),
        ("orange", "Paris", 31),
        ("banana", "Amsterdam", 74),
        ("kiwi", "Berlin", 55),
    ]

    fn1 = NamedTemporaryFile().name
    fn2 = NamedTemporaryFile().name
    p = topickle(fn1)
    p.pipe(topickle(fn2))
    p.push(t)

    ieq(t, frompickle(fn1))
    ieq(t, frompickle(fn2))
Esempio n. 7
0
def test_sort():
    table = (("foo", "bar"), ("C", "2"), ("A", "9"), ("A", "6"), ("F", "1"), ("D", "10"))

    fn = NamedTemporaryFile().name
    p = sort("foo")
    p.pipe(topickle(fn))
    p.push(table)

    expectation = (("foo", "bar"), ("A", "9"), ("A", "6"), ("C", "2"), ("D", "10"), ("F", "1"))
    ieq(expectation, frompickle(fn))
Esempio n. 8
0
def test_sort_buffered():
    table = (("foo", "bar"), ("C", "2"), ("A", "9"), ("A", "6"), ("F", "1"), ("D", "10"))

    fn = NamedTemporaryFile().name
    p = sort("foo", buffersize=2)
    p.pipe(topickle(fn))
    p.push(table)

    expectation = (("foo", "bar"), ("A", "9"), ("A", "6"), ("C", "2"), ("D", "10"), ("F", "1"))
    actual = frompickle(fn)
    ieq(expectation, actual)
Esempio n. 9
0
def test_diff():

    tablea = (('foo', 'bar', 'baz'),
              ('A', 1, True),
              ('B', 2, False),
              ('C', 7, False),
              ('C', 9, True))
    
    tableb = (('x', 'y', 'z'),
              ('A', 9, False),
              ('B', 2, False),
              ('B', 3, True),
              ('C', 9, True))
    
    aminusb = (('foo', 'bar', 'baz'),
               ('A', 1, True),
               ('C', 7, False))
    
    bminusa = (('foo', 'bar', 'baz'),
               ('A', 9, False),
               ('B', 3, True))

    both = (('foo', 'bar', 'baz'),
            ('B', 2, False),
            ('C', 9, True))

    fn1 = NamedTemporaryFile().name
    fn2 = NamedTemporaryFile().name
    fn3 = NamedTemporaryFile().name
    p = diff()
    p.pipe('+', topickle(fn1))
    p.pipe('-', topickle(fn2))
    p.pipe(topickle(fn3))
    p.push(tablea, tableb)

    added, subtracted, common = (frompickle(fn1), frompickle(fn2),
                                 frompickle(fn3))
    ieq(bminusa, added)
    ieq(aminusb, subtracted)
    ieq(both, common)
Esempio n. 10
0
def test_sort():
    table = (('foo', 'bar'),
             ('C', '2'),
             ('A', '9'),
             ('A', '6'),
             ('F', '1'),
             ('D', '10'))
    
    fn = NamedTemporaryFile().name
    p = sort('foo')
    p.pipe(topickle(fn))
    p.push(table)

    expectation = (('foo', 'bar'),
                   ('A', '9'),
                   ('A', '6'),
                   ('C', '2'),
                   ('D', '10'),
                   ('F', '1'))
    ieq(expectation, frompickle(fn))
Esempio n. 11
0
def test_sort_buffered():
    table = (('foo', 'bar'),
             ('C', '2'),
             ('A', '9'),
             ('A', '6'),
             ('F', '1'),
             ('D', '10'))
    
    fn = NamedTemporaryFile().name
    p = sort('foo', buffersize=2)
    p.pipe(topickle(fn))
    p.push(table)

    expectation = (('foo', 'bar'),
                   ('A', '9'),
                   ('A', '6'),
                   ('C', '2'),
                   ('D', '10'),
                   ('F', '1'))
    actual = frompickle(fn)
    ieq(expectation, actual)
Esempio n. 12
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))