示例#1
0
文件: test_io.py 项目: brutimus/petl
def test_tosqlite3_appendsqlite3_connection():

    conn = sqlite3.connect(':memory:')    

    # exercise function
    table = (('foo', 'bar'),
             ('a', 1),
             ('b', 2),
             ('c', 2))
    tosqlite3(table, conn, 'foobar', create=True)
    
    # check what it did
    actual = conn.execute('select * from foobar')
    expect = (('a', 1),
              ('b', 2),
              ('c', 2))
    ieq(expect, actual)
    
    # check appending
    table2 = (('foo', 'bar'),
              ('d', 7),
              ('e', 9),
              ('f', 1))
    appendsqlite3(table2, conn, 'foobar') 

    # check what it did
    actual = conn.execute('select * from foobar')
    expect = (('a', 1),
              ('b', 2),
              ('c', 2),
              ('d', 7),
              ('e', 9),
              ('f', 1))
    ieq(expect, actual)
示例#2
0
def test_tosqlite3_appendsqlite3_connection():

    conn = sqlite3.connect(':memory:')

    # exercise function
    table = (('foo', 'bar'), ('a', 1), ('b', 2), ('c', 2))
    tosqlite3(table, conn, 'foobar', create=True)

    # check what it did
    actual = conn.execute('select * from foobar')
    expect = (('a', 1), ('b', 2), ('c', 2))
    ieq(expect, actual)

    # check appending
    table2 = (('foo', 'bar'), ('d', 7), ('e', 9), ('f', 1))
    appendsqlite3(table2, conn, 'foobar')

    # check what it did
    actual = conn.execute('select * from foobar')
    expect = (('a', 1), ('b', 2), ('c', 2), ('d', 7), ('e', 9), ('f', 1))
    ieq(expect, actual)
示例#3
0
文件: test_io.py 项目: deytao/petl
def test_tosqlite3_appendsqlite3_connection():

    conn = sqlite3.connect(":memory:")

    # exercise function
    table = (("foo", "bar"), ("a", 1), ("b", 2), ("c", 2))
    tosqlite3(table, conn, "foobar", create=True)

    # check what it did
    actual = conn.execute("select * from foobar")
    expect = (("a", 1), ("b", 2), ("c", 2))
    ieq(expect, actual)

    # check appending
    table2 = (("foo", "bar"), ("d", 7), ("e", 9), ("f", 1))
    appendsqlite3(table2, conn, "foobar")

    # check what it did
    actual = conn.execute("select * from foobar")
    expect = (("a", 1), ("b", 2), ("c", 2), ("d", 7), ("e", 9), ("f", 1))
    ieq(expect, actual)
示例#4
0
def test_tosqlite3_appendsqlite3():
    """Test the tosqlite3 and appendsqlite3 functions."""

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

    # check what it did
    conn = sqlite3.connect(f.name)
    actual = conn.execute('select * from foobar')
    expect = (('a', 1), ('b', 2), ('c', 2))
    ieq(expect, actual)

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

    # check what it did
    conn = sqlite3.connect(f.name)
    actual = conn.execute('select * from foobar')
    expect = (('a', 1), ('b', 2), ('c', 2), ('d', 7), ('e', 9), ('f', 1))
    ieq(expect, actual)
示例#5
0
文件: test_io.py 项目: deytao/petl
def test_tosqlite3_appendsqlite3():
    """Test the tosqlite3 and appendsqlite3 functions."""

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

    # check what it did
    conn = sqlite3.connect(f.name)
    actual = conn.execute("select * from foobar")
    expect = (("a", 1), ("b", 2), ("c", 2))
    ieq(expect, actual)

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

    # check what it did
    conn = sqlite3.connect(f.name)
    actual = conn.execute("select * from foobar")
    expect = (("a", 1), ("b", 2), ("c", 2), ("d", 7), ("e", 9), ("f", 1))
    ieq(expect, actual)
示例#6
0
文件: test_io.py 项目: brutimus/petl
def test_tosqlite3_appendsqlite3():
    """Test the tosqlite3 and appendsqlite3 functions."""
    
    # exercise function
    table = (('foo', 'bar'),
             ('a', 1),
             ('b', 2),
             ('c', 2))
    f = NamedTemporaryFile(delete=False)
    tosqlite3(table, f.name, 'foobar', create=True)
    
    # check what it did
    conn = sqlite3.connect(f.name)
    actual = conn.execute('select * from foobar')
    expect = (('a', 1),
              ('b', 2),
              ('c', 2))
    ieq(expect, actual)
    
    # check appending
    table2 = (('foo', 'bar'),
              ('d', 7),
              ('e', 9),
              ('f', 1))
    appendsqlite3(table2, f.name, 'foobar') 

    # check what it did
    conn = sqlite3.connect(f.name)
    actual = conn.execute('select * from foobar')
    expect = (('a', 1),
              ('b', 2),
              ('c', 2),
              ('d', 7),
              ('e', 9),
              ('f', 1))
    ieq(expect, actual)
示例#7
0
文件: examples.py 项目: datamade/petl
tosqlite3(table, 'test.db', 'foobar')
# look what it did
from petl import fromsqlite3
look(fromsqlite3('test.db', 'select * from foobar'))


# appendsqlite3

moredata = [['foo', 'bar'],
            ['d', 7],
            ['e', 9],
            ['f', 1]]

from petl import appendsqlite3, look
look(moredata)
appendsqlite3(moredata, 'test.db', 'foobar') 
# look what it did
from petl import look, fromsqlite3
look(fromsqlite3('test.db', 'select * from foobar'))


# tojson

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

from petl import tojson, look
look(table)
tojson(table, 'example.json')
示例#8
0
tosqlite3(table, 'test.db', 'foobar')
# look what it did
from petl import fromsqlite3
look(fromsqlite3('test.db', 'select * from foobar'))


# appendsqlite3

moredata = [['foo', 'bar'],
            ['d', 7],
            ['e', 9],
            ['f', 1]]

from petl import appendsqlite3, look
look(moredata)
appendsqlite3(moredata, 'test.db', 'foobar') 
# look what it did
from petl import look, fromsqlite3
look(fromsqlite3('test.db', 'select * from foobar'))


# tojson

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

from petl import tojson, look
look(table)
tojson(table, 'example.json')