2 Tests that rely on a server running
10 from omnisci
import connect, ProgrammingError, DatabaseError
18 TOmniSciException.__hash__ =
lambda x: id(x)
19 omniscihost = os.environ.get(
'OMNISCI_HOST',
'localhost')
22 @pytest.mark.usefixtures(
"omnisci_server")
27 password=
'HyperInteractive',
33 assert con
is not None
38 password=
'HyperInteractive',
44 assert con
is not None
48 'omnisci://admin:HyperInteractive@{0}:6274/omnisci?'
49 'protocol=binary'.format(omniscihost)
52 assert con._user ==
'admin'
53 assert con._password ==
'HyperInteractive'
54 assert con._host == omniscihost
55 assert con._port == 6274
56 assert con._dbname ==
'omnisci'
57 assert con._protocol ==
'binary'
61 'omnisci://admin:HyperInteractive@{0}:6274/omnisci?'
62 'protocol=binary'.format(omniscihost)
64 with pytest.raises(TypeError):
65 connect(username=
'omnisci', uri=uri)
68 with pytest.raises(ProgrammingError)
as r:
69 con.cursor().execute(
"this is invalid;")
70 r.match(
"Exception: Parse failed:")
73 with pytest.raises(DatabaseError)
as r:
74 con.cursor().execute(
"select it from fake_table;")
75 r.match(
"Table 'FAKE_TABLE' does not exist|Object 'fake_table' not")
78 result = con.execute(
"drop table if exists FOO;")
79 result = con.execute(
"create table FOO (a int);")
80 assert isinstance(result, Cursor)
81 con.execute(
"drop table if exists FOO;")
86 c.execute(
'drop table if exists stocks;')
88 'create table stocks (date_ text, trans text, symbol text, '
89 'qty int, price float, vol float);'
92 i1 =
"INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14,1.1);"
93 i2 =
"INSERT INTO stocks VALUES ('2006-01-05','BUY','GOOG',100,12.14,1.2);"
98 c.execute(
"select * from stocks")
100 Description(
'date_', 6,
None,
None,
None,
None,
True),
101 Description(
'trans', 6,
None,
None,
None,
None,
True),
102 Description(
'symbol', 6,
None,
None,
None,
None,
True),
103 Description(
'qty', 1,
None,
None,
None,
None,
True),
104 Description(
'price', 3,
None,
None,
None,
None,
True),
105 Description(
'vol', 3,
None,
None,
None,
None,
True),
107 assert c.description == expected
108 c.execute(
'drop table if exists stocks;')
113 c.execute(
'drop table if exists stocks;')
115 'create table stocks (date_ text, trans text, symbol text, '
116 'qty int, price float, vol float);'
119 i1 =
"INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14,1.1);"
120 i2 =
"INSERT INTO stocks VALUES ('2006-01-05','BUY','GOOG',100,12.14,1.2);"
126 'select symbol, qty from stocks where symbol = :symbol',
133 assert result == expected
134 c.execute(
'drop table if exists stocks;')
139 c.execute(
'drop table if exists stocks;')
141 'create table stocks (date_ text, trans text, symbol text, '
142 'qty int, price float, vol float);'
145 i1 =
"INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14,1.1);"
146 i2 =
"INSERT INTO stocks VALUES ('2006-01-05','BUY','GOOG',100,12.14,1.2);"
151 parameters = [{
'symbol':
'GOOG'}, {
'symbol':
"RHAT"}]
152 expected = [[(
'GOOG', 100)], [(
'RHAT', 100)]]
153 query =
'select symbol, qty from stocks where symbol = :symbol'
155 result = c.executemany(query, parameters)
156 assert result == expected
157 c.execute(
'drop table if exists stocks;')
162 c.execute(
'drop table if exists stocks;')
164 'create table stocks (date_ text, trans text, symbol text, '
165 'qty int, price float, vol float);'
168 i1 =
"INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14,1.1);"
169 i2 =
"INSERT INTO stocks VALUES ('2006-01-05','BUY','GOOG',100,12.14,1.2);"
175 c.execute(
"drop table if exists stocks2;")
177 c.execute(
'CREATE TABLE stocks2 (symbol text, qty int);')
178 params = [{
"symbol":
"GOOG",
"qty": 10}, {
"symbol":
"AAPL",
"qty": 20}]
179 query =
"INSERT INTO stocks2 VALUES (:symbol, :qty);"
180 result = c.executemany(query, params)
181 assert result == [[], []]
182 c.execute(
"drop table stocks2;")
183 c.execute(
'drop table if exists stocks;')
188 c.execute(
'drop table if exists stocks;')
190 'create table stocks (date_ text, trans text, symbol text, '
191 'qty int, price float, vol float);'
194 i1 =
"INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14,1.1);"
195 i2 =
"INSERT INTO stocks VALUES ('2006-01-05','BUY','GOOG',100,12.14,1.2);"
200 c.execute(
"select symbol, qty from stocks")
201 result = c.fetchone()
202 expected = (
'RHAT', 100)
203 assert result == expected
204 c.execute(
'drop table if exists stocks;')
209 c.execute(
'drop table if exists stocks;')
211 'create table stocks (date_ text, trans text, symbol text, '
212 'qty int, price float, vol float);'
215 i1 =
"INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14,1.1);"
216 i2 =
"INSERT INTO stocks VALUES ('2006-01-05','BUY','GOOG',100,12.14,1.2);"
221 c.execute(
"select symbol, qty from stocks")
222 result = c.fetchmany()
223 expected = [(
'RHAT', 100)]
224 assert result == expected
226 c.execute(
"select symbol, qty from stocks")
227 result = c.fetchmany(size=10)
228 expected = [(
'RHAT', 100), (
'GOOG', 100)]
229 assert result == expected
230 c.execute(
'drop table if exists stocks;')
235 c.execute(
'drop table if exists dates;')
237 'create table dates (date_ DATE, datetime_ TIMESTAMP, '
241 "INSERT INTO dates VALUES ('2006-01-05','2006-01-01T12:00:00',"
245 "INSERT INTO dates VALUES ('1901-12-14','1901-12-13T20:45:53',"
251 result = list(c.execute(
"select * from dates"))
254 datetime.date(2006, 1, 5),
255 datetime.datetime(2006, 1, 1, 12),
259 datetime.date(1901, 12, 14),
260 datetime.datetime(1901, 12, 13, 20, 45, 53),
261 datetime.time(23, 59),
264 assert result == expected
265 c.execute(
'drop table if exists dates;')
273 c.execute(
'drop table if exists stocks;')
275 'create table stocks (date_ text, trans text, symbol text, '
276 'qty int, price float, vol float);'
280 q =
"select * from stocks"
281 results = con._client.sql_validate(con._session, q)
282 col_names = sorted([r.col_name
for r
in results])
283 col_types = [r.col_type
for r
in results]
285 expected_col_names = [
357 assert col_types == expected_types
358 assert col_names == expected_col_names
def test_nonexistant_table
def test_select_sets_description
def test_connection_execute
def test_executemany_parametrized
def test_select_parametrized
def test_executemany_parametrized_insert
def test_connect_uri_and_others_raises