def test_init(): # try open not existing database with pytest.raises(sqlite3.OperationalError): Database("file_does_not_exist.database", table_prefix="ae") # open existing database database = Database(PRIDB_FILE_PATH, table_prefix="ae") assert database.connected database.close() assert not database.connected database.close() # double close should not cause an exception # require file extension with pytest.raises(ValueError): Database(PRIDB_FILE_PATH, table_prefix="ae", required_file_ext=".nonsense")
def fixture_empty_pridb(): filename = "test.pridb" try: PriDatabase.create(filename) with Database(filename, mode="rw", table_prefix="ae") as db: yield db finally: os.remove(filename)
def test_create(): with pytest.raises(NotImplementedError): Database.create("test.db") with pytest.raises(NotImplementedError): Database("test.db", mode="rwc", table_prefix="")
def test_main_table_not_existing(): # exception is thrown, if main table doesn"t exist with pytest.raises(ValueError): Database(PRIDB_FILE_PATH, table_prefix="tr")
def test_context(): with Database(PRIDB_FILE_PATH, table_prefix="ae") as database: # check if connection is opened with __enter__ assert database.connected # check if connection is closed with __exit__ assert not database.connected
def fixture_sample_tradb(): database = Database(TRADB_FILE_PATH, table_prefix="tr") yield database database.close()
def fixture_sample_pridb(): database = Database(PRIDB_FILE_PATH, table_prefix="ae") yield database database.close()