def test_export_no_overwrite(bibs, mock_init): with open(u.BM_BIBFILE(), "w") as f: f.write("placeholder file.") my_bibs = [bibs["beaulieu_apj"], bibs["stodden"]] bm.export(my_bibs, u.BM_BIBFILE()) assert "bm_bibliography.bib" in os.listdir(u.HOME) assert f"orig_{datetime.date.today()}_bm_bibliography.bib" \ in os.listdir(u.HOME)
def test_export_home(bibs, mock_init): my_bibs = [bibs["stodden"], bibs["beaulieu_apj"]] bm.export(my_bibs, u.BM_BIBFILE()) assert "bm_bibliography.bib" in os.listdir(u.HOME) with open(u.BM_BIBFILE(), "r") as f: lines = f.readlines() assert lines[0] == "This file was created by bibmanager\n" loaded_bibs = bm.loadfile(u.BM_BIBFILE()) assert loaded_bibs == sorted(my_bibs)
def test_cli_reset_all(capsys, mock_init_sample): pathlib.Path(u.BM_BIBFILE()).touch() cm.set("ads_display", "10") captured = capsys.readouterr() # Simulate user input: sys.argv = "bibm reset".split() cli.main() captured = capsys.readouterr() assert captured.out == "Initializing new bibmanager database.\n" \ "Resetting config parameters.\n" assert set(os.listdir(u.HOME)) == set(["config", "examples", "pdf"])
def test_cli_reset_config(capsys, mock_init_sample): pathlib.Path(u.BM_BIBFILE()).touch() # Simulate user input: sys.argv = "bibm reset -c".split() cli.main() captured = capsys.readouterr() assert captured.out == "Resetting config parameters.\n" #assert filecmp.cmp(u.HOME+"config", u.ROOT+"config") assert set(os.listdir(u.HOME)) == set([ "bm_database.pickle", "bm_bibliography.bib", "config", "examples", "pdf", ])
def test_cli_reset_database(capsys, mock_init_sample): pathlib.Path(u.BM_BIBFILE()).touch() cm.set("ads_display", "10") captured = capsys.readouterr() # Simulate user input: sys.argv = "bibm reset -d".split() cli.main() captured = capsys.readouterr() assert captured.out == "Initializing new bibmanager database.\n" # filecmp does not seem to work fine, will do manually: # assert not filecmp.cmp(u.HOME+"config", u.ROOT+"config") with open(u.ROOT + "config", "r") as f: rconfig = f.read() with open(u.HOME + "config", "r") as f: hconfig = f.read() assert rconfig != hconfig assert set(os.listdir(u.HOME)) == set(["config", "examples", "pdf"])
def test_set_home_success(capsys, tmp_path, mock_init_sample): new_home = f'{tmp_path}/bm' cm.set('home', new_home) assert cm.get('home') == new_home + '/' # 'constants' now point to new home: assert u.BM_DATABASE() == f'{new_home}/bm_database.pickle' assert u.BM_BIBFILE() == f'{new_home}/bm_bibliography.bib' assert u.BM_TMP_BIB() == f'{new_home}/tmp_bibliography.bib' assert u.BM_CACHE() == f'{new_home}/cached_ads_query.pickle' assert u.BM_HISTORY_SEARCH() == f'{new_home}/history_search' assert u.BM_HISTORY_ADS() == f'{new_home}/history_ads_search' assert u.BM_PDF() == f'{new_home}/pdf/' captured = capsys.readouterr() assert captured.out == f'home updated to: {new_home}/.\n' # These files/folders stay: assert set(os.listdir(u.HOME)) == set(["config", "examples", "pdf"]) # These files have been moved/created: assert set(os.listdir(str(new_home))) == \ set(['pdf', 'bm_bibliography.bib', 'bm_database.pickle'])