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 initialize_monetdblite(request, tmp_path): test_dbfarm = tmp_path.resolve().as_posix() def finalizer(): monetdblite.shutdown() if tmp_path.is_dir(): shutil.rmtree(test_dbfarm) request.addfinalizer(finalizer) monetdblite.init(test_dbfarm) return test_dbfarm
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 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_double_initialization(self, initialize_monetdblite): with pytest.raises(mdbl.exceptions.DatabaseError): mdbl.init(initialize_monetdblite)
def test_erroneous_initialization(self): # init with weird argument with pytest.raises(Exception): monetdblite.init(33)
def setUp(self): global dbfarm dbfarm = monetdblitetest.tempdir() monetdblite.init(dbfarm)