11 ctypes._dlopen(
'libDBEngine.so', ctypes.RTLD_GLOBAL)
13 data_path =
"dbe_test_data"
19 shutil.rmtree(data_path)
20 except FileNotFoundError:
23 with pytest.raises(RuntimeError)
as excinfo:
24 engine = dbe.PyDbEngine(data=
'/' + data_path, calcite_port=9091)
25 assert "Permission denied" in str(excinfo.value)
30 engine = dbe.PyDbEngine(data=data_path, calcite_port=9091)
31 assert bool(engine.closed) ==
False
37 engine.executeDDL(
"drop table if exists test")
38 engine.executeDDL(
"create table test (x int not null, w tinyint, y int, z text)")
39 assert engine.get_tables() == [
'test']
43 with pytest.raises(RuntimeError)
as excinfo:
44 engine.executeDDL(
"create table test (x int not null, w tinyint, y int, z text)")
45 assert "already exists" in str(excinfo.value)
49 engine.executeDML(
"insert into test values(55,5,3,'la-la-la')")
50 engine.executeDML(
"insert into test values(66,6,1, 'aa')")
51 engine.executeDML(
"insert into test values(77,7,0,'bb')")
52 dframe = engine.select_df(
"select * from test")
53 dforig = pandas.DataFrame({
'x': [55,66,77],
'w': [5,6,7],
'y': [3,1,0],
'z': [
'la-la-la',
'aa',
'bb']})
54 dforig = dforig.astype(dtype= {
"x":
"int32",
"w":
"int8",
"y":
"int32",
"z":
"category"})
55 assert dframe.equals(dforig)
59 with pytest.raises(RuntimeError)
as excinfo:
60 cursor = engine.executeDML(
"selectTT * from test")
61 assert "SQL Error" in str(excinfo.value)
65 with pytest.raises(RuntimeError)
as excinfo:
66 cursor = engine.executeDML(
"SELECT x / (x - x) FROM test")
67 assert "Division by zero" in str(excinfo.value)
71 with pytest.raises(RuntimeError)
as excinfo:
72 engine = dbe.PyDbEngine()
73 assert "already initialized" in str(excinfo.value)
76 if __name__ ==
"__main__":
77 pytest.main([
"-v", __file__])
def test_failed_DML
Check wrong DML statement.
def test_success_DDL
Check DDL statement.
def test_success_DML
Check right DML statement.
def test_failed_DDL
Check creating a duplicate table.
def test_success_init
Check init with right parameters.
def test_zero_division
Check zero division exception.
def test_failed_init
Check init with wrong parameter.
def test_double_init
Check double init exception.