def test_errors(self): global dbfarm monetdblite.shutdown() if PY26: return # select before init with self.assertRaises(monetdblite.DatabaseError): monetdblite.sql('select * from tables') # init with weird argument with self.assertRaises(Exception): monetdblite.init(33) # init in unwritable directory with self.assertRaises(monetdblite.DatabaseError): monetdblite.init('/unwritabledir') # proper init monetdblite.init(dbfarm) # select from non-existent table with self.assertRaises(monetdblite.DatabaseError): monetdblite.sql('select * from nonexistenttable') # invalid connection object with self.assertRaises(monetdblite.DatabaseError): monetdblite.sql('select * from tables', client=33) # invalid colnames with self.assertRaises(monetdblite.DatabaseError): monetdblite.create('pylite08', {33: []}) # empty colnames with self.assertRaises(monetdblite.DatabaseError): monetdblite.create('pylite08', {'': []}) # dictionary with invalid keys d = dict() d[33] = 44 with self.assertRaises(monetdblite.DatabaseError): monetdblite.create('pylite08', d) monetdblite.sql('DROP TABLE pylite08') monetdblite.create('pylite08', dict(a=[], b=[], c=[])) # FIXME: segfault # missing dict key in insert #with self.assertRaises(monetdblite.DatabaseError): # monetdblite.insert('pylite08', dict(a=33,b=44)) # too few columns in insert try: import pandas with self.assertRaises(monetdblite.DatabaseError): monetdblite.insert('pylite08', [[33], [44]]) except: return
def test_unwriteable_dir(self): # init in unwritable directory os.mkdir('/tmp/unwriteabledir') os.chmod('/tmp/unwriteabledir', 0o555) with pytest.raises(monetdblite.DatabaseError): monetdblite.init('/tmp/unwriteabledir') monetdblite.shutdown() os.chmod('/tmp/unwriteabledir', 0o755) shutil.rmtree('/tmp/unwriteabledir')
def test_relative_initialization(self): tmpdir = tempfile.mkdtemp() cwd = os.getcwd() os.chdir(tmpdir) try: mdbl.init("./relative_path") except Exception: mdbl.shutdown() shutil.rmtree(tmpdir) assert False res = mdbl.sql("SELECT id FROM _tables limit 10") mdbl.shutdown() os.chdir(cwd) shutil.rmtree(tmpdir) assert len(res.get('id')) == 10
def finalizer(): monetdblite.shutdown() if tmp_path.is_dir(): shutil.rmtree(test_dbfarm)
def tearDown(self): monetdblite.shutdown() monetdblitetest.cleantempdir()