def test_fromsqlite3_withargs(): # initial data data = (('a', 1), ('b', 2), ('c', 2.0)) connection = sqlite3.connect(':memory:') c = connection.cursor() c.execute('create table foobar (foo, bar)') for row in data: c.execute('insert into foobar values (?, ?)', row) connection.commit() c.close() # test the function actual = fromsqlite3( connection, 'select * from foobar where bar > ? and bar < ?', (1, 3) ) expect = (('foo', 'bar'), ('b', 2), ('c', 2.0)) ieq(expect, actual) ieq(expect, actual) # verify can iterate twice
def test_fromsqlite3(): """Test the fromsqlite3 function.""" # initial data f = NamedTemporaryFile(delete=False) data = (('a', 1), ('b', 2), ('c', 2.0)) connection = sqlite3.connect(f.name) c = connection.cursor() c.execute('create table foobar (foo, bar)') for row in data: c.execute('insert into foobar values (?, ?)', row) connection.commit() c.close() connection.close() # test the function actual = fromsqlite3(f.name, 'select * from foobar') expect = (('foo', 'bar'), ('a', 1), ('b', 2), ('c', 2.0)) ieq(expect, actual, cast=tuple) ieq(expect, actual, cast=tuple) # verify can iterate twice
def test_fromsqlite3_withargs(): # initial data data = (('a', 1), ('b', 2), ('c', 2.0)) connection = sqlite3.connect(':memory:') c = connection.cursor() c.execute('create table foobar (foo, bar)') for row in data: c.execute('insert into foobar values (?, ?)', row) connection.commit() c.close() # test the function actual = fromsqlite3(connection, 'select * from foobar where bar > ? and bar < ?', (1, 3)) expect = (('foo', 'bar'), ('b', 2), ('c', 2.0)) ieq(expect, actual) ieq(expect, actual) # verify can iterate twice
def test_fromsqlite3_connection(): """Test the fromsqlite3 function.""" # initial data data = (('a', 1), ('b', 2), ('c', 2.0)) connection = sqlite3.connect(':memory:') c = connection.cursor() c.execute('create table foobar (foo, bar)') for row in data: c.execute('insert into foobar values (?, ?)', row) connection.commit() c.close() # test the function actual = fromsqlite3(connection, 'select * from foobar') expect = (('foo', 'bar'), ('a', 1), ('b', 2), ('c', 2.0)) ieq(expect, actual, cast=tuple) ieq(expect, actual, cast=tuple) # verify can iterate twice