예제 #1
0
    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')
예제 #2
0
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
예제 #3
0
    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
예제 #4
0
    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
예제 #5
0
 def test_double_initialization(self, initialize_monetdblite):
     with pytest.raises(mdbl.exceptions.DatabaseError):
         mdbl.init(initialize_monetdblite)
예제 #6
0
 def test_erroneous_initialization(self):
     # init with weird argument
     with pytest.raises(Exception):
         monetdblite.init(33)
예제 #7
0
 def setUp(self):
     global dbfarm
     dbfarm = monetdblitetest.tempdir()
     monetdblite.init(dbfarm)