コード例 #1
0
ファイル: test_io.py プロジェクト: pombredanne/petl
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)
コード例 #2
0
ファイル: test_io.py プロジェクト: deytao/petl
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)
コード例 #3
0
ファイル: test_sources.py プロジェクト: Mgutjahr/petl
def test_stdoutsource_unicode():

    tbl = [('foo', 'bar'),
           (u'Արամ Խաչատրյան', 1),
           (u'Johann Strauß', 2)]
    etl.tocsv(tbl, StdoutSource(), encoding='utf-8')
    etl.tohtml(tbl, StdoutSource(), encoding='utf-8')
    etl.topickle(tbl, StdoutSource())
コード例 #4
0
ファイル: test_io.py プロジェクト: pombredanne/petl
def test_issue_231():

    table = [['foo', 'bar'], ['a', '1'], ['b', '2']]
    t = cut(table, 'foo')
    totsv(t, 'tmp/issue_231.tsv')
    u = fromtsv('tmp/issue_231.tsv')
    ieq(t, u)
    tocsv(t, 'tmp/issue_231.csv')
    u = fromcsv('tmp/issue_231.csv')
    ieq(t, u)
    topickle(t, 'tmp/issue_231.pickle')
    u = frompickle('tmp/issue_231.pickle')
    ieq(t, u)
コード例 #5
0
ファイル: test_io.py プロジェクト: brutimus/petl
def test_issue_231():

    table = [['foo', 'bar'], ['a', '1'], ['b', '2']]
    t = cut(table, 'foo')
    totsv(t, 'tmp/issue_231.tsv')
    u = fromtsv('tmp/issue_231.tsv')
    ieq(t, u)
    tocsv(t, 'tmp/issue_231.csv')
    u = fromcsv('tmp/issue_231.csv')
    ieq(t, u)
    topickle(t, 'tmp/issue_231.pickle')
    u = frompickle('tmp/issue_231.pickle')
    ieq(t, u)
コード例 #6
0
ファイル: test_io.py プロジェクト: brutimus/petl
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)
コード例 #7
0
ファイル: examples.py プロジェクト: datamade/petl
from petl import appendcsv 
appendcsv(table, 'test.csv', delimiter='\t')
# look what it did
look(testcsv)


# topickle

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

from petl import topickle, look
look(table)
topickle(table, 'test.dat')
# look what it did
from petl import frompickle
look(frompickle('test.dat'))


# appendpickle

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

from petl import look, frompickle
# inspect an existing pickle file
testdat = frompickle('test.dat')
コード例 #8
0
ファイル: examples.py プロジェクト: aklimchak/petl
from petl import appendcsv 
appendcsv(table, 'test.csv', delimiter='\t')
# look what it did
look(testcsv)


# topickle

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

from petl import topickle, look
look(table)
topickle(table, 'test.dat')
# look what it did
from petl import frompickle
look(frompickle('test.dat'))


# appendpickle

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

from petl import look, frompickle
# inspect an existing pickle file
testdat = frompickle('test.dat')
コード例 #9
0
def test_stdoutsource_unicode():

    tbl = [('foo', 'bar'), (u'Արամ Խաչատրյան', 1), (u'Johann Strauß', 2)]
    etl.tocsv(tbl, StdoutSource(), encoding='utf-8')
    etl.tohtml(tbl, StdoutSource(), encoding='utf-8')
    etl.topickle(tbl, StdoutSource())
コード例 #10
0
def test_stdoutsource():

    tbl = [('foo', 'bar'), ('a', 1), ('b', 2)]
    etl.tocsv(tbl, StdoutSource(), encoding='ascii')
    etl.tohtml(tbl, StdoutSource(), encoding='ascii')
    etl.topickle(tbl, StdoutSource())
コード例 #11
0
ファイル: test_sources.py プロジェクト: Mgutjahr/petl
def test_stdoutsource():

    tbl = [('foo', 'bar'), ('a', 1), ('b', 2)]
    etl.tocsv(tbl, StdoutSource(), encoding='ascii')
    etl.tohtml(tbl, StdoutSource(), encoding='ascii')
    etl.topickle(tbl, StdoutSource())
コード例 #12
0
ファイル: virtdb.py プロジェクト: SergeVL/petlsql
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)
コード例 #13
0
ファイル: pickle.py プロジェクト: trb116/pythonanalyzer
from __future__ import division, print_function, absolute_import

# frompickle()
##############

import petl as etl
import pickle
# set up a file to demonstrate with
with open('example.p', 'wb') as f:
    pickle.dump(['foo', 'bar'], f)
    pickle.dump(['a', 1], f)
    pickle.dump(['b', 2], f)
    pickle.dump(['c', 2.5], f)

# demonstrate the use of frompickle()
table1 = etl.frompickle('example.p')
table1

# topickle()
############

import petl as etl
table1 = [['foo', 'bar'], ['a', 1], ['b', 2], ['c', 2]]
etl.topickle(table1, 'example.p')
# look what it did
table2 = etl.frompickle('example.p')
table2
コード例 #14
0
ファイル: pickle.py プロジェクト: DeanWay/petl
##############

import petl as etl
import pickle
# set up a file to demonstrate with
with open('example.p', 'wb') as f:
    pickle.dump(['foo', 'bar'], f)
    pickle.dump(['a', 1], f)
    pickle.dump(['b', 2], f)
    pickle.dump(['c', 2.5], f)

# demonstrate the use of frompickle()
table1 = etl.frompickle('example.p')
table1


# topickle()
############

import petl as etl
table1 = [['foo', 'bar'],
          ['a', 1],
          ['b', 2],
          ['c', 2]]
etl.topickle(table1, 'example.p')
# look what it did
table2 = etl.frompickle('example.p')
table2