Beispiel #1
0
def test_topickle_appendpickle():
    """Test the topickle and appendpickle functions."""

    # exercise function
    table = (('foo', 'bar'), ('a', 1), ('b', 2), ('c', 2))
    f = NamedTemporaryFile(delete=False)
    topickle(table, f.name)

    def picklereader(fl):
        try:
            while True:
                yield pickle.load(fl)
        except EOFError:
            pass

    # check what it did
    with open(f.name, 'rb') as o:
        actual = picklereader(o)
        ieq(table, actual)

    # check appending
    table2 = (('foo', 'bar'), ('d', 7), ('e', 9), ('f', 1))
    appendpickle(table2, f.name)

    # check what it did
    with open(f.name, 'rb') as o:
        actual = picklereader(o)
        expect = (('foo', 'bar'), ('a', 1), ('b', 2), ('c', 2), ('d', 7),
                  ('e', 9), ('f', 1))
        ieq(expect, actual)
Beispiel #2
0
def test_topickle_appendpickle():
    """Test the topickle and appendpickle functions."""

    # exercise function
    table = (("foo", "bar"), ("a", 1), ("b", 2), ("c", 2))
    f = NamedTemporaryFile(delete=False)
    topickle(table, f.name)

    def picklereader(file):
        try:
            while True:
                yield pickle.load(file)
        except EOFError:
            pass

    # check what it did
    with open(f.name, "rb") as o:
        actual = picklereader(o)
        ieq(table, actual)

    # check appending
    table2 = (("foo", "bar"), ("d", 7), ("e", 9), ("f", 1))
    appendpickle(table2, f.name)

    # check what it did
    with open(f.name, "rb") as o:
        actual = picklereader(o)
        expect = (("foo", "bar"), ("a", 1), ("b", 2), ("c", 2), ("d", 7), ("e", 9), ("f", 1))
        ieq(expect, actual)
Beispiel #3
0
def test_topickle_appendpickle():
    """Test the topickle and appendpickle functions."""
    
    # exercise function
    table = (('foo', 'bar'),
             ('a', 1),
             ('b', 2),
             ('c', 2))
    f = NamedTemporaryFile(delete=False)
    topickle(table, f.name)
    
    def picklereader(fl):
        try:
            while True:
                yield pickle.load(fl)
        except EOFError:
            pass

    # check what it did
    with open(f.name, 'rb') as o:
        actual = picklereader(o)
        ieq(table, actual)
    
    # check appending
    table2 = (('foo', 'bar'),
              ('d', 7),
              ('e', 9),
              ('f', 1))
    appendpickle(table2, f.name) 

    # check what it did
    with open(f.name, 'rb') as o:
        actual = picklereader(o)
        expect = (('foo', 'bar'),
                  ('a', 1),
                  ('b', 2),
                  ('c', 2),
                  ('d', 7),
                  ('e', 9),
                  ('f', 1))
        ieq(expect, actual)
Beispiel #4
0
# appendpickle

table = [['foo', 'bar'],
         ['d', 7],
         ['e', 42],
         ['f', 12]]

from petl import look, frompickle
# inspect an existing pickle file
testdat = frompickle('test.dat')
look(testdat)
# append some data
from petl import appendpickle
look(table)
appendpickle(table, 'test.dat')
# look what it did
look(testdat)


# tosqlite3

table = [['foo', 'bar'],
         ['a', 1],
         ['b', 2],
         ['c', 2]]

from petl import tosqlite3, look
look(table)
# by default, if the table does not already exist, it will be created
tosqlite3(table, 'test.db', 'foobar')
Beispiel #5
0
# appendpickle

table = [['foo', 'bar'],
         ['d', 7],
         ['e', 42],
         ['f', 12]]

from petl import look, frompickle
# inspect an existing pickle file
testdat = frompickle('test.dat')
look(testdat)
# append some data
from petl import appendpickle
look(table)
appendpickle(table, 'test.dat')
# look what it did
look(testdat)


# tosqlite3

table = [['foo', 'bar'],
         ['a', 1],
         ['b', 2],
         ['c', 2]]

from petl import tosqlite3, look
look(table)
# by default, if the table does not already exist, it will be created
tosqlite3(table, 'test.db', 'foobar')
Beispiel #6
0
def topickle(data, target, append, **kwargs):
    kwargs = filter_keys(kwargs, ("protocol", "write_header"))
    if append:
        return etl.appendpickle(data, target, **kwargs)
    else:
        return etl.topickle(data, target, **kwargs)