def test_chimedb_test_rc(self): # Create an empty on-disk sqlite database (fd, dbfile) = tempfile.mkstemp(text=True) os.close(fd) # Create a rcfile (fd, rcfile) = tempfile.mkstemp(text=True) with os.fdopen(fd, "a") as rc: rc.write("""\ chimedb: db_type: sqlite db: {0} """.format(dbfile)) # This should be ignored os.environ["CHIMEDB_TEST_RC"] = rcfile db.test_enable() db.connect(read_write=True) db.proxy.create_tables([TestTable]) TestTable.create(datum=datum_value) # Did that work? self.assertEqual( TestTable.select(TestTable.datum).scalar(), datum_value) db.close() # The on-disk sqlite database should not be empty stat = os.stat(dbfile) self.assertNotEqual(stat.st_size, 0) os.unlink(rcfile) os.unlink(dbfile)
def test_no_chimedbrc(self): # This is not allowed os.environ["CHIMEDB_TEST_RC"] = 'any string containing "chimedbrc"' db.test_enable() with self.assertRaises(OSError): db.connect()
def test_chimedb_test_sqlite(self): # Create an empty on-disk sqlite database (fd, dbfile) = tempfile.mkstemp(text=True) os.close(fd) os.environ["CHIMEDB_TEST_SQLITE"] = dbfile db.test_enable() db.connect(read_write=True) db.proxy.create_tables([TestTable]) TestTable.create(datum=datum_value) # Did that work? self.assertEqual( TestTable.select(TestTable.datum).scalar(), datum_value) db.close() # The on-disk sqlite database should not be empty anymore stat = os.stat(dbfile) self.assertNotEqual(stat.st_size, 0)