Esempio n. 1
0
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)
Esempio n. 2
0
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")
Esempio n. 3
0
def test_create():
    with pytest.raises(NotImplementedError):
        Database.create("test.db")

    with pytest.raises(NotImplementedError):
        Database("test.db", mode="rwc", table_prefix="")
Esempio n. 4
0
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")
Esempio n. 5
0
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
Esempio n. 6
0
def fixture_sample_tradb():
    database = Database(TRADB_FILE_PATH, table_prefix="tr")
    yield database
    database.close()
Esempio n. 7
0
def fixture_sample_pridb():
    database = Database(PRIDB_FILE_PATH, table_prefix="ae")
    yield database
    database.close()