def db(): """CardsDB object connected to a temporary database""" with TemporaryDirectory() as db_dir: db_path = Path(db_dir) db_ = cards.CardsDB(db_path) yield db_ db_.close()
def test_empty(): with TemporaryDirectory() as db_dir: db_path = Path(db_dir) db = cards.CardsDB(db_path) count = db.count() db.close() assert count == 0
def session_cards_db(tmp_db_path): """CardsDB""" db_ = cards.CardsDB(tmp_db_path) yield db_ db_.close()
def cards_db(): db_path = get_path() db = cards.CardsDB(db_path) yield db db.close()
def test_no_path_fail(): cards.CardsDB()
def cards_db(): with TemporaryDirectory() as db_dir: db_path = Path(db_dir) db = cards.CardsDB(db_path) yield db db.close()
def cards_db(): # just put it in users home dir for now db_path = pathlib.Path().home() / '.cards_db.json' return cards.CardsDB(db_path)
def db(tmp_path_factory): """CardsDB object connected to a temporary database""" db_path = tmp_path_factory.mktemp("cards_db") db_ = cards.CardsDB(db_path) yield db_ db_.close()
def test_raises_with_info(): match_regex = "missing 1 .* positional argument" with pytest.raises(TypeError, match=match_regex): cards.CardsDB()
def test_no_path_raises(): with pytest.raises(TypeError): cards.CardsDB()
def test_raises_with_info_alt(): with pytest.raises(TypeError) as exc_info: cards.CardsDB() expected = "missing 1 required positional argument" assert expected in str(exc_info.value)
def cards_db(db_path, monkeypatch): monkeypatch.setenv("CARDS_DB_DIR", str(db_path)) db_ = cards.CardsDB(db_path) db_.delete_all() yield db_ db_.close()