OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tests.test_integration.TestIntegration Class Reference

Public Member Functions

def test_connect_binary
 
def test_connect_http
 
def test_connect_uri
 
def test_connect_uri_and_others_raises
 
def test_invalid_sql
 
def test_nonexistant_table
 
def test_connection_execute
 
def test_select_sets_description
 
def test_select_parametrized
 
def test_executemany_parametrized
 
def test_executemany_parametrized_insert
 
def test_fetchone
 
def test_fetchmany
 
def test_select_dates
 

Detailed Description

Definition at line 21 of file test_integration.py.

Member Function Documentation

def tests.test_integration.TestIntegration.test_connect_binary (   self)

Definition at line 22 of file test_integration.py.

References heavydb.connection.connect().

22 
23  def test_connect_binary(self):
24  con = connect(
25  user="admin",
26  password='HyperInteractive',
27  host=heavydb_host,
28  port=6274,
29  protocol='binary',
30  dbname='heavyai',
31  )
32  assert con is not None

+ Here is the call graph for this function:

def tests.test_integration.TestIntegration.test_connect_http (   self)

Definition at line 33 of file test_integration.py.

References heavydb.connection.connect().

33 
34  def test_connect_http(self):
35  con = connect(
36  user="admin",
37  password='HyperInteractive',
38  host=heavydb_host,
39  port=6278,
40  protocol='http',
41  dbname='heavyai',
42  )
43  assert con is not None

+ Here is the call graph for this function:

def tests.test_integration.TestIntegration.test_connect_uri (   self)

Definition at line 44 of file test_integration.py.

References heavydb.connection.connect().

44 
45  def test_connect_uri(self):
46  uri = (
47  'heavydb://admin:HyperInteractive@{0}:6274/heavyai?'
48  'protocol=binary'.format(heavydb_host)
49  )
50  con = connect(uri=uri)
51  assert con._user == 'admin'
52  assert con._password == 'HyperInteractive'
53  assert con._host == heavydb_host
54  assert con._port == 6274
55  assert con._dbname == 'heavyai'
56  assert con._protocol == 'binary'

+ Here is the call graph for this function:

def tests.test_integration.TestIntegration.test_connect_uri_and_others_raises (   self)

Definition at line 57 of file test_integration.py.

References heavydb.connection.connect().

57 
59  uri = (
60  'heavydb://admin:HyperInteractive@{0}:6274/heavyai?'
61  'protocol=binary'.format(heavydb_host)
62  )
63  with pytest.raises(TypeError):
64  connect(username='heavyai', uri=uri)

+ Here is the call graph for this function:

def tests.test_integration.TestIntegration.test_connection_execute (   self,
  con 
)

Definition at line 75 of file test_integration.py.

75 
76  def test_connection_execute(self, con):
77  result = con.execute("drop table if exists FOO;")
78  result = con.execute("create table FOO (a int);")
79  assert isinstance(result, Cursor)
80  con.execute("drop table if exists FOO;")
def tests.test_integration.TestIntegration.test_executemany_parametrized (   self,
  con 
)

Definition at line 134 of file test_integration.py.

135  def test_executemany_parametrized(self, con):
136 
137  c = con.cursor()
138  c.execute('drop table if exists stocks;')
139  create = (
140  'create table stocks (date_ text, trans text, symbol text, '
141  'qty int, price float, vol float);'
142  )
143  c.execute(create)
144  i1 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14,1.1);" # noqa
145  i2 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','GOOG',100,12.14,1.2);" # noqa
146 
147  c.execute(i1)
148  c.execute(i2)
149 
150  parameters = [{'symbol': 'GOOG'}, {'symbol': "RHAT"}]
151  expected = [[('GOOG', 100)], [('RHAT', 100)]]
152  query = 'select symbol, qty from stocks where symbol = :symbol'
153  c = con.cursor()
154  result = c.executemany(query, parameters)
155  assert result == expected
156  c.execute('drop table if exists stocks;')
def tests.test_integration.TestIntegration.test_executemany_parametrized_insert (   self,
  con 
)

Definition at line 157 of file test_integration.py.

159 
160  c = con.cursor()
161  c.execute('drop table if exists stocks;')
162  create = (
163  'create table stocks (date_ text, trans text, symbol text, '
164  'qty int, price float, vol float);'
165  )
166  c.execute(create)
167  i1 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14,1.1);" # noqa
168  i2 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','GOOG',100,12.14,1.2);" # noqa
169 
170  c.execute(i1)
171  c.execute(i2)
172 
173  c = con.cursor()
174  c.execute("drop table if exists stocks2;")
175  # Create table
176  c.execute('CREATE TABLE stocks2 (symbol text, qty int);')
177  params = [{"symbol": "GOOG", "qty": 10}, {"symbol": "AAPL", "qty": 20}]
178  query = "INSERT INTO stocks2 VALUES (:symbol, :qty);"
179  result = c.executemany(query, params)
180  assert result == [[], []] # TODO: not sure if this is standard
181  c.execute("drop table stocks2;")
182  c.execute('drop table if exists stocks;')
def tests.test_integration.TestIntegration.test_fetchmany (   self,
  con 
)

Definition at line 204 of file test_integration.py.

205  def test_fetchmany(self, con):
206 
207  c = con.cursor()
208  c.execute('drop table if exists stocks;')
209  create = (
210  'create table stocks (date_ text, trans text, symbol text, '
211  'qty int, price float, vol float);'
212  )
213  c.execute(create)
214  i1 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14,1.1);" # noqa
215  i2 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','GOOG',100,12.14,1.2);" # noqa
216 
217  c.execute(i1)
218  c.execute(i2)
219 
220  c.execute("select symbol, qty from stocks")
221  result = c.fetchmany()
222  expected = [('RHAT', 100)]
223  assert result == expected
224 
225  c.execute("select symbol, qty from stocks")
226  result = c.fetchmany(size=10)
227  expected = [('RHAT', 100), ('GOOG', 100)]
228  assert result == expected
229  c.execute('drop table if exists stocks;')
def tests.test_integration.TestIntegration.test_fetchone (   self,
  con 
)

Definition at line 183 of file test_integration.py.

184  def test_fetchone(self, con):
185 
186  c = con.cursor()
187  c.execute('drop table if exists stocks;')
188  create = (
189  'create table stocks (date_ text, trans text, symbol text, '
190  'qty int, price float, vol float);'
191  )
192  c.execute(create)
193  i1 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14,1.1);" # noqa
194  i2 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','GOOG',100,12.14,1.2);" # noqa
195 
196  c.execute(i1)
197  c.execute(i2)
198 
199  c.execute("select symbol, qty from stocks")
200  result = c.fetchone()
201  expected = ('RHAT', 100)
202  assert result == expected
203  c.execute('drop table if exists stocks;')
def tests.test_integration.TestIntegration.test_invalid_sql (   self,
  con 
)

Definition at line 65 of file test_integration.py.

65 
66  def test_invalid_sql(self, con):
67  with pytest.raises(ProgrammingError) as r:
68  con.cursor().execute("this is invalid;")
69  r.match("SQL Error:")
def tests.test_integration.TestIntegration.test_nonexistant_table (   self,
  con 
)

Definition at line 70 of file test_integration.py.

70 
71  def test_nonexistant_table(self, con):
72  with pytest.raises(DatabaseError) as r:
73  con.cursor().execute("select it from fake_table;")
74  r.match("Table 'FAKE_TABLE' does not exist|Object 'fake_table' not")
def tests.test_integration.TestIntegration.test_select_dates (   self,
  con 
)

Definition at line 230 of file test_integration.py.

231  def test_select_dates(self, con):
232 
233  c = con.cursor()
234  c.execute('drop table if exists dates;')
235  c.execute(
236  'create table dates (date_ DATE, datetime_ TIMESTAMP, '
237  'time_ TIME);'
238  )
239  i1 = (
240  "INSERT INTO dates VALUES ('2006-01-05','2006-01-01T12:00:00',"
241  "'12:00:00');"
242  )
243  i2 = (
244  "INSERT INTO dates VALUES ('1901-12-14','1901-12-13T20:45:53',"
245  "'23:59:00');"
246  )
247  c.execute(i1)
248  c.execute(i2)
249 
250  result = list(c.execute("select * from dates"))
251  expected = [
252  (
253  datetime.date(2006, 1, 5),
254  datetime.datetime(2006, 1, 1, 12),
255  datetime.time(12),
256  ),
257  (
258  datetime.date(1901, 12, 14),
259  datetime.datetime(1901, 12, 13, 20, 45, 53),
260  datetime.time(23, 59),
261  ),
262  ]
263  assert result == expected
264  c.execute('drop table if exists dates;')
265 
def tests.test_integration.TestIntegration.test_select_parametrized (   self,
  con 
)

Definition at line 108 of file test_integration.py.

109  def test_select_parametrized(self, con):
110 
111  c = con.cursor()
112  c.execute('drop table if exists stocks;')
113  create = (
114  'create table stocks (date_ text, trans text, symbol text, '
115  'qty int, price float, vol float);'
116  )
117  c.execute(create)
118  i1 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14,1.1);" # noqa
119  i2 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','GOOG',100,12.14,1.2);" # noqa
120 
121  c.execute(i1)
122  c.execute(i2)
123 
124  c.execute(
125  'select symbol, qty from stocks where symbol = :symbol',
126  {'symbol': 'GOOG'},
127  )
128  result = list(c)
129  expected = [
130  ('GOOG', 100),
131  ] # noqa
132  assert result == expected
133  c.execute('drop table if exists stocks;')
def tests.test_integration.TestIntegration.test_select_sets_description (   self,
  con 
)

Definition at line 81 of file test_integration.py.

References heavydb._parsers.Description.

81 
82  def test_select_sets_description(self, con):
83 
84  c = con.cursor()
85  c.execute('drop table if exists stocks;')
86  create = (
87  'create table stocks (date_ text, trans text, symbol text, '
88  'qty int, price float, vol float);'
89  )
90  c.execute(create)
91  i1 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14,1.1);" # noqa
92  i2 = "INSERT INTO stocks VALUES ('2006-01-05','BUY','GOOG',100,12.14,1.2);" # noqa
93 
94  c.execute(i1)
95  c.execute(i2)
96 
97  c.execute("select * from stocks")
98  expected = [
99  Description('date_', 6, None, None, None, None, True),
100  Description('trans', 6, None, None, None, None, True),
101  Description('symbol', 6, None, None, None, None, True),
102  Description('qty', 1, None, None, None, None, True),
103  Description('price', 3, None, None, None, None, True),
104  Description('vol', 3, None, None, None, None, True),
105  ]
106  assert c.description == expected
107  c.execute('drop table if exists stocks;')
tuple Description
Definition: _parsers.py:11

The documentation for this class was generated from the following file: