Example #1
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
Example #2
0
def test_display_list_verb_one(capfd, mock_init, mock_init_sample):
    bibs = bm.load()
    bibs = [bibs[11], bibs[13]]
    bm.display_list(bibs, verb=1)
    captured = capfd.readouterr()
    expected_output = '\x1b[0m\x1b[?7h\x1b[0m\r\n\x1b[0;38;5;33mTitle\x1b[0m: \x1b[0;38;5;130mStudies based on the colors and magnitudes in stellar clusters. VII.\r\n    The distances, distribution in space, and dimensions of 69 globular\r\n    clusters., 1918\x1b[0m\r\n\x1b[0;38;5;33mAuthors\x1b[0m: \x1b[0;38;5;130m{Shapley}, H.\x1b[0m\r\n\x1b[0;38;5;33mADS URL\x1b[0m: \x1b[0;38;5;130mhttp://adsabs.harvard.edu/abs/1918ApJ....48..154S\x1b[0m\r\n\x1b[0;38;5;33mbibcode\x1b[0m: \x1b[0;38;5;130m1918ApJ....48..154S\x1b[0m\r\n\x1b[0;38;5;33mkey\x1b[0m: \x1b[0;38;5;142mShapley1918apjDistanceGlobularClusters\x1b[0m\r\n\x1b[0m\x1b[0m\x1b[?7h\x1b[0m\r\n\x1b[0;38;5;33mTitle\x1b[0m: \x1b[0;38;5;130mThe radial velocity of the Andromeda Nebula, 1913\x1b[0m\r\n\x1b[0;38;5;33mAuthors\x1b[0m: \x1b[0;38;5;130m{Slipher}, V. M.\x1b[0m\r\n\x1b[0;38;5;33mADS URL\x1b[0m: \x1b[0;38;5;130mhttps://ui.adsabs.harvard.edu/abs/1913LowOB...2...56S\x1b[0m\r\n\x1b[0;38;5;33mbibcode\x1b[0m: \x1b[0;38;5;130m1913LowOB...2...56S\x1b[0m\r\n\x1b[0;38;5;33mPDF file\x1b[0m: \x1b[0;38;5;248;3mSlipher1913.pdf\x1b[0m\r\n\x1b[0;38;5;33mkey\x1b[0m: \x1b[0;38;5;142mSlipher1913lobAndromedaRarialVelocity\x1b[0m\r\n\x1b[0m'
    assert captured.out == expected_output
Example #3
0
def test_export_no_meta(mock_init_sample):
    bibs = bm.load()
    bm_export = u.HOME + 'tmp_bm.bib'
    bm.export(bibs, bm_export, meta=False)
    with open(bm_export, "r") as f:
        lines = f.readlines()
    assert "pdf: Slipher1913.pdf\n" not in lines
Example #4
0
def test_display_list_verb_neg(capfd, mock_init, mock_init_sample):
    bibs = bm.load()
    bm.display_list(bibs[0:4], verb=-1)
    captured = capfd.readouterr()
    assert captured.out == (
        '\nKeys:\n'
        'AASteamHendrickson2018aastex62\n'
        'Astropycollab2013aaAstropy\n'
        'BeaulieuEtal2010arxivGJ436b\n'
        'BurbidgeEtal1957rvmpStellarElementSynthesis\n')
Example #5
0
def test_add_bibtex_warning(capsys, reqs, mock_init):
    # A partially failing call will still add those that succeed:
    captured = capsys.readouterr()
    bibcodes = ['1925PhDT.....X...1P', '2018MNRAS.481.5286F']
    keys = ['Payne1925phdStellarAtmospheres', 'FolsomEtal2018mnrasHD219134']
    am.add_bibtex(bibcodes, keys)
    loaded_bibs = bm.load()
    assert len(loaded_bibs) == 1
    captured = capsys.readouterr()
    assert captured.out == """
Example #6
0
def test_display_list_verb_zero(capfd, mock_init, mock_init_sample):
    bibs = bm.load()
    bibs = [bibs[11], bibs[13]]
    bm.display_list(bibs, verb=0)
    captured = capfd.readouterr()
    # Trick to see how the screen output looks:
    #print(repr(captured.out))
    #print(captured.out)
    expected_output = '\x1b[0m\x1b[?7h\x1b[0m\r\n\x1b[0;38;5;33mTitle\x1b[0m: \x1b[0;38;5;130mStudies based on the colors and magnitudes in stellar clusters. VII.\r\n    The distances, distribution in space, and dimensions of 69 globular\r\n    clusters., 1918\x1b[0m\r\n\x1b[0;38;5;33mAuthors\x1b[0m: \x1b[0;38;5;130m{Shapley}, H.\x1b[0m\r\n\x1b[0;38;5;33mkey\x1b[0m: \x1b[0;38;5;142mShapley1918apjDistanceGlobularClusters\x1b[0m\r\n\x1b[0m\x1b[0m\x1b[?7h\x1b[0m\r\n\x1b[0;38;5;33mTitle\x1b[0m: \x1b[0;38;5;130mThe radial velocity of the Andromeda Nebula, 1913\x1b[0m\r\n\x1b[0;38;5;33mAuthors\x1b[0m: \x1b[0;38;5;130m{Slipher}, V. M.\x1b[0m\r\n\x1b[0;38;5;33mkey\x1b[0m: \x1b[0;38;5;142mSlipher1913lobAndromedaRarialVelocity\x1b[0m\r\n\x1b[0m'
    assert captured.out == expected_output
Example #7
0
def test_add_bibtex_fail(capsys, reqs, mock_init):
    captured = capsys.readouterr()
    bibcodes = ['1925PhDT.....X...1P']
    keys = ['Payne1925phdStellarAtmospheres']
    am.add_bibtex(bibcodes, keys)
    captured = capsys.readouterr()
    assert captured.out \
           == "\nError: There were no entries found for the input bibcodes.\n"
    loaded_bibs = bm.load()
    assert len(loaded_bibs) == 0
Example #8
0
def test_add_bibtex_success(capsys, reqs, mock_init):
    captured = capsys.readouterr()
    bibcodes = ['1925PhDT.........1P']
    keys = ['Payne1925phdStellarAtmospheres']
    am.add_bibtex(bibcodes, keys)
    captured = capsys.readouterr()
    assert captured.out == "\nMerged 1 new entries.\n" \
                           "(Not counting updated references)\n"
    loaded_bibs = bm.load()
    assert len(loaded_bibs) == 1
    assert loaded_bibs[0].content == \
"""@PHDTHESIS{Payne1925phdStellarAtmospheres,
Example #9
0
def test_add_bibtex_with_tags(capsys, reqs, mock_init):
    captured = capsys.readouterr()
    bibcodes = ['1925PhDT.........1P']
    keys = ['Payne1925phdStellarAtmospheres']
    tags = [['stars']]
    am.add_bibtex(bibcodes, keys, tags=tags)
    captured = capsys.readouterr()
    assert captured.out == "\nMerged 1 new entries.\n" \
                           "(Not counting updated references)\n"
    loaded_bibs = bm.load()
    assert len(loaded_bibs) == 1
    assert repr(loaded_bibs[0]) == \
"""tags: stars
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'
def test_set_home_and_edit(tmp_path, mock_init, bibs, reqs):
    new_home = f'{tmp_path}/bm'
    cm.set('home', new_home)
    assert cm.get('home') == new_home + '/'
    # Test merge:
    bm.merge(new=[bibs["beaulieu_apj"]], take='new')
    # Test search:
    matches = bm.search(authors="beaulieu")
    assert len(matches) == 1
    assert 'BeaulieuEtal2011apjGJ436bMethane' in matches[0].key
    # Test ADS add:
    am.add_bibtex(['1925PhDT.........1P'], ['Payne1925phdStellarAtmospheres'])
    # Test load:
    current_bibs = bm.load()
    assert len(current_bibs) == 2
    assert 'Payne1925phdStellarAtmospheres' in current_bibs[1].key
    # 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'])
Example #12
0
def test_merge_duplicate_title_add(bibs, mock_init_sample, mock_input):
    bm.merge(new=[bibs['no_oliphant']])
    loaded_bibs = bm.load()
    assert len(loaded_bibs) == 18
    assert bibs['no_oliphant'] in loaded_bibs
Example #13
0
def test_merge_duplicate_key_rename(bibs, mock_init_sample, mock_input):
    bm.merge(new=[bibs['oliphant_dup']])
    loaded_bibs = bm.load()
    assert len(loaded_bibs) == 18
    assert 'Oliphant2016numpyb' in [e.key for e in loaded_bibs]
Example #14
0
def test_merge_duplicate_key_ingnore(bibs, mock_init_sample, mock_input):
    bm.merge(new=[bibs['oliphant_dup']])
    loaded_bibs = bm.load()
    assert len(loaded_bibs) == 17
    assert bibs['oliphant_dup'] in loaded_bibs
Example #15
0
def test_load(bibs, mock_init):
    my_bibs = [bibs["beaulieu_apj"], bibs["stodden"]]
    bm.save(my_bibs)
    loaded_bibs = bm.load()
    assert loaded_bibs == my_bibs
Example #16
0
def test_display_list_verb_two(capfd, mock_init, mock_init_sample):
    bibs = bm.load()
    bm.display_list(bibs[3:4], verb=2)
    captured = capfd.readouterr()
    expected_output = '\x1b[0m\x1b[?7h\x1b[0m\r\n\x1b[0;38;5;33mTitle\x1b[0m: \x1b[0;38;5;130mSynthesis of the Elements in Stars, 1957\x1b[0m\r\n\x1b[0;38;5;33mAuthors\x1b[0m: \x1b[0;38;5;130m{Burbidge}, E. Margaret; {Burbidge}, G. R.; {Fowler}, William A.; and\r\n    {Hoyle}, F.\x1b[0m\r\n\x1b[0;38;5;33mADS URL\x1b[0m: \x1b[0;38;5;130mhttps://ui.adsabs.harvard.edu/abs/1957RvMP...29..547B\x1b[0m\r\n\x1b[0;38;5;33mbibcode\x1b[0m: \x1b[0;38;5;130m1957RvMP...29..547B\x1b[0m\r\n\x1b[0;38;5;33mkey\x1b[0m: \x1b[0;38;5;142mBurbidgeEtal1957rvmpStellarElementSynthesis\x1b[0m\r\n\x1b[0m'
    assert captured.out == expected_output
Example #17
0
def test_merge_duplicate_title_add(bibs, mock_init_sample, mock_input):
    bm.merge(new=[bibs['slipher_guy']])
    loaded_bibs = bm.load()
    assert len(loaded_bibs) == nentries + 1
    assert bibs['slipher_guy'] in loaded_bibs
Example #18
0
def test_merge_duplicate_key_rename(bibs, mock_init_sample, mock_input):
    bm.merge(new=[bibs['slipher_dup']])
    loaded_bibs = bm.load()
    assert len(loaded_bibs) == nentries + 1
    assert 'Slipher1913lobAnd' in [e.key for e in loaded_bibs]
Example #19
0
def test_display_list_verb_full(capfd, mock_init, mock_init_sample):
    bibs = bm.load()
    bibs = [bibs[11], bibs[13]]
    bm.display_list(bibs, verb=3)
    captured = capfd.readouterr()
    assert captured.out == '\x1b[0m\x1b[?7h\x1b[0;38;5;248;3m\r\n::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\r\n\x1b[0m\x1b[0;38;5;248;3m\x1b[0;38;5;34;1;4m@ARTICLE\x1b[0m{\x1b[0;38;5;142mShapley1918apjDistanceGlobularClusters\x1b[0m,\x1b[0;38;5;250m\r\n   \x1b[0;38;5;33mauthor\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m{{Shapley}, H.}\x1b[0m,\x1b[0;38;5;250m\r\n    \x1b[0;38;5;33mtitle\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m"{Studies based on the colors and magnitudes in stellar clusters. VII. The distances, distribution in space, and dimensions of 69 globular clusters.}"\x1b[0m,\x1b[0;38;5;250m\r\n  \x1b[0;38;5;33mjournal\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m{\\apj}\x1b[0m,\x1b[0;38;5;250m\r\n     \x1b[0;38;5;33myear\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;30m1918\x1b[0m,\x1b[0;38;5;250m\r\n    \x1b[0;38;5;33mmonth\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;124moct\x1b[0m,\x1b[0;38;5;250m\r\n   \x1b[0;38;5;33mvolume\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;30m48\x1b[0m,\x1b[0;38;5;250m\r\n      \x1b[0;38;5;33mdoi\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m{10.1086/142423}\x1b[0m,\x1b[0;38;5;250m\r\n   \x1b[0;38;5;33madsurl\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m{http://adsabs.harvard.edu/abs/1918ApJ....48..154S}\x1b[0m,\x1b[0;38;5;250m\r\n  \x1b[0;38;5;33madsnote\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m{Provided by the SAO/NASA Astrophysics Data System}\x1b[0;38;5;250m\r\n\x1b[0m}\x1b[0;38;5;250m\r\n\x1b[0m\r\n\x1b[0;38;5;248;3mpdf: Slipher1913.pdf\r\n\x1b[0;38;5;34;1;4m@ARTICLE\x1b[0m{\x1b[0;38;5;142mSlipher1913lobAndromedaRarialVelocity\x1b[0m,\x1b[0;38;5;250m\r\n       \x1b[0;38;5;33mauthor\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m{{Slipher}, V.~M.}\x1b[0m,\x1b[0;38;5;250m\r\n        \x1b[0;38;5;33mtitle\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m"{The radial velocity of the Andromeda Nebula}"\x1b[0m,\x1b[0;38;5;250m\r\n      \x1b[0;38;5;33mjournal\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m{Lowell Observatory Bulletin}\x1b[0m,\x1b[0;38;5;250m\r\n     \x1b[0;38;5;33mkeywords\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m{GALAXIES: MOTION IN LINE OF SIGHT, ANDROMEDA GALAXY}\x1b[0m,\x1b[0;38;5;250m\r\n         \x1b[0;38;5;33myear\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;30m1913\x1b[0m,\x1b[0;38;5;250m\r\n        \x1b[0;38;5;33mmonth\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;124mJan\x1b[0m,\x1b[0;38;5;250m\r\n       \x1b[0;38;5;33mvolume\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m{1}\x1b[0m,\x1b[0;38;5;250m\r\n        \x1b[0;38;5;33mpages\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m{56-57}\x1b[0m,\x1b[0;38;5;250m\r\n       \x1b[0;38;5;33madsurl\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m{https://ui.adsabs.harvard.edu/abs/1913LowOB...2...56S}\x1b[0m,\x1b[0;38;5;250m\r\n      \x1b[0;38;5;33madsnote\x1b[0;38;5;250m \x1b[0m=\x1b[0;38;5;250m \x1b[0;38;5;130m{Provided by the SAO/NASA Astrophysics Data System}\x1b[0;38;5;250m\r\n\x1b[0m}\x1b[0;38;5;250m\r\n\x1b[0m\r\n\x1b[0m'