예제 #1
0
def test_get_version_existing(mock_init):
    expected_version = '1.0.0'
    # Mock pickle DB file with version:
    with open(u.BM_DATABASE(), 'wb') as handle:
        pickle.dump([], handle, protocol=4)
        pickle.dump(expected_version, handle, protocol=4)
    assert bm.get_version() == expected_version
예제 #2
0
def test_load_filed(tmp_path, bibs, mock_init):
    my_bibs = [bibs["beaulieu_apj"], bibs["stodden"]]
    bm.save(my_bibs)
    db = f'{tmp_path}/bm_database.pickle'
    shutil.copy(u.BM_DATABASE(), db)
    loaded_bibs = bm.load(db)
    assert loaded_bibs == my_bibs
예제 #3
0
def test_cli_older_pickle(capsys, mock_init_sample, mock_prompt_session):
    # Mock pickle DB file with older version than bibmanager:
    with open(u.BM_DATABASE(), 'wb') as handle:
        pickle.dump([], handle, protocol=4)

    # Simulate user input:
    sys.argv = "bibm search".split()
    cli.main()
    captured = capsys.readouterr()
    assert captured.out == f"""Updating database file from version 0.0.0 to version {bibmanager.__version__}.
예제 #4
0
def test_cli_future_pickle(capsys, mock_init_sample):
    # Mock pickle DB file with later version than bibmanager:
    future_version = '2.0.0'
    with open(u.BM_DATABASE(), 'wb') as handle:
        pickle.dump([], handle, protocol=4)
        pickle.dump(future_version, handle, protocol=4)

    # Simulate user input:
    sys.argv = "bibm reset".split()
    cli.main()
    captured = capsys.readouterr()
    assert captured.out == \
       (f"Bibmanager version ({bibmanager.__version__}) is older than "
        f"saved database.  Please update to a version >= {future_version}.\n")
예제 #5
0
def test_set_home_merge(tmp_path, bibs, mock_init):
    new_home = f'{tmp_path}/bm'
    os.mkdir(f'{new_home}')
    bib1, bib2 = bibs["beaulieu_apj"], bibs["stodden"]
    bib1.pdf, bib2.pdf = 'file1.pdf', 'file2.pdf'
    bm.save([bib1])
    shutil.copy(u.BM_DATABASE(), f'{new_home}/bm_database.pickle')
    bm.export([bib1], f'{new_home}/bm_bibliography.bib', meta=True)
    bm.export([bib2], f'{new_home}/other.bib', meta=True)
    bm.init(f'{new_home}/other.bib')
    cm.set('home', new_home)
    # Check DBs are merged:
    bibs = bm.load()
    assert len(bibs) == 2
    assert bibs[0].content == bib1.content
    assert bibs[1].content == bib2.content
    # Check both meta exist:
    assert bibs[0].pdf == 'file1.pdf'
    assert bibs[1].pdf == 'file2.pdf'
예제 #6
0
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'])
예제 #7
0
def test_get_version_no_pickle(mock_init):
    # Make sure there's no database:
    with u.ignored(OSError):
        os.remove(u.BM_DATABASE())
    assert bm.get_version() == bibm.__version__
예제 #8
0
def test_get_version_older(mock_init):
    # Mock pickle DB file without version:
    with open(u.BM_DATABASE(), 'wb') as handle:
        pickle.dump([], handle, protocol=4)
    assert bm.get_version() == '0.0.0'