Ejemplo n.º 1
0
def test_read_file_pdf_with_bad_path(tmp_path, mock_init):
    pdf_path = str(tmp_path) + '/pathed_file.pdf'
    # (no touch)
    with open(u.ROOT+'examples/sample.bib') as f:
       text = f.read()
    text = f'pdf: {pdf_path}\n{text}'
    bibs = bm.read_file(text=text)
    assert bibs[0].pdf is None
Ejemplo n.º 2
0
def test_display_list_no_title(capfd, mock_init, mock_init_sample):
    bibs = bm.read_file(text='''@ARTICLE{Slipher1913lobAndromedaRarialVelocity,
       author = {{Slipher}, V.~M.},
         year = 1913,
}''')
    bm.display_list(bibs, verb=0)
    captured = capfd.readouterr()
    expected_output = '\x1b[0m\x1b[?7h\x1b[0m\r\n\x1b[0;38;5;33mTitle\x1b[0m: \x1b[0;38;5;130mNone, 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
Ejemplo n.º 3
0
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.read_file(u.BM_BIBFILE())
    assert loaded_bibs == sorted(my_bibs)
Ejemplo n.º 4
0
def test_display_list_no_author(capfd, mock_init, mock_init_sample):
    bibs = bm.read_file(text='''@ARTICLE{Slipher1913lobAndromedaRarialVelocity,
        title = "{The radial velocity of the Andromeda Nebula}",
         year = 1913,
}''')
    bm.display_list(bibs, verb=0)
    captured = capfd.readouterr()
    expected_output = '\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;33mkey\x1b[0m: \x1b[0;38;5;142mSlipher1913lobAndromedaRarialVelocity\x1b[0m\r\n\x1b[0m'
    assert captured.out == expected_output
Ejemplo n.º 5
0
def test_read_file_pdf_with_path(tmp_path, mock_init):
    pdf_path = str(tmp_path) + '/pathed_file.pdf'
    pathlib.Path(pdf_path).touch()
    with open(u.ROOT+'examples/sample.bib') as f:
       text = f.read()
    text = f'pdf: {pdf_path}\n{text}'
    bibs = bm.read_file(text=text)
    assert bibs[0].pdf == 'pathed_file.pdf'
    assert 'pathed_file.pdf' in os.listdir(u.BM_PDF())
    assert not os.path.isfile(pdf_path)
Ejemplo n.º 6
0
def test_display_list_no_arxiv(capfd, mock_init, mock_init_sample):
    bibs = bm.read_file(text='''@ARTICLE{Slipher1913lobAndromedaRarialVelocity,
       author = {{Slipher}, V.~M.},
        title = "{The radial velocity of the Andromeda Nebula}",
         year = 1913,
       adsurl = {https://ui.adsabs.harvard.edu/abs/1913LowOB...2...56S},
}''')
    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;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;33mkey\x1b[0m: \x1b[0;38;5;142mSlipher1913lobAndromedaRarialVelocity\x1b[0m\r\n\x1b[0m'
    assert captured.out == expected_output
Ejemplo n.º 7
0
def test_read_file_meta():
    with open(u.ROOT+'examples/sample.bib') as f:
       text = f.read()
    # prepend meta info before first entry:
    text = 'freeze\npdf: file.pdf\n'+ text
    bibs = bm.read_file(text=text)

    assert bibs[0].pdf == 'file.pdf'
    assert bibs[0].freeze is True
    assert bibs[1].pdf is None
    assert bibs[1].freeze is None
Ejemplo n.º 8
0
def test_display_list_no_ads(capfd, mock_init, mock_init_sample):
    bibs = bm.read_file(text='''@ARTICLE{Slipher1913lobAndromedaRarialVelocity,
       author = {{Slipher}, V.~M.},
        title = "{The radial velocity of the Andromeda Nebula}",
         year = 1913,
       eprint = {0000.2000},
}''')
    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;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;33mArXiv URL\x1b[0m: \x1b[0;38;5;130mhttp://arxiv.org/abs/0000.2000\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
Ejemplo n.º 9
0
def test_read_file_single_line_entry(mock_init):
    text = """@Article{Adams1991ApJ, author = {{Adams}, F.~C.}, title = "{Asymptotic theory for the spatial distribution of protostellar emission}", journal = {\apj}, keywords = {ASYMPTOTIC METHODS, EMISSION SPECTRA, PROTOSTARS, SPATIAL DISTRIBUTION, STAR FORMATION, COMPUTATIONAL ASTROPHYSICS, DENSITY DISTRIBUTION, PRE-MAIN SEQUENCE STARS, STELLAR ENVELOPES, STELLAR LUMINOSITY, TEMPERATURE DISTRIBUTION}, year = 1991, month = dec, volume = 382, pages = {544-554}, doi = {10.1086/170741}, adsurl = {http://adsabs.harvard.edu/abs/1991ApJ...382..544A}, adsnote = {Provided by the SAO/NASA Astrophysics Data System} }

@Misc{JonesOliphantPeterson2001scipy,
  author = {Eric Jones and Travis Oliphant and Pearu Peterson},
  title  = {{SciPy}: Open source scientific tools for {Python}},
  year   = {2001},
}"""
    bibs = bm.read_file(text=text)
    assert len(bibs) == 2
    assert bibs[0].key == 'Adams1991ApJ'
Ejemplo n.º 10
0
def test_build_bib_missing(capsys, tmp_path, mock_init):
    # Assert screen output:
    bibfile = f'{tmp_path}/my_file.bib'
    bm.merge(u.HOME+"examples/sample.bib")
    captured = capsys.readouterr()
    texfile = u.HOME+"examples/mock_file.tex"
    with open(texfile, "w") as f:
        f.write("\\cite{Astropycollab2013aaAstropy} \\cite{MissingEtal2019}.\n")
    missing = lm.build_bib(texfile, bibfile)
    captured = capsys.readouterr()
    assert captured.out == "References not found:\nMissingEtal2019\n"
    # Check content:
    np.testing.assert_array_equal(missing, np.array(["MissingEtal2019"]))
    bibs = bm.read_file(bibfile)
    assert len(bibs) == 1
    assert "Astropycollab2013aaAstropy" in bibs[0].key
Ejemplo n.º 11
0
def test_read_file_ignore_comment(mock_init):
    text = """
@comment{Jones2000comment,
  author = {Eric Jones},
  title  = {{SciPy}: Open source scientific fools for {Python}},
  year   = {2000},
}

@Misc{JonesEtal2001scipy,
  author = {Eric Jones and Travis Oliphant and Pearu Peterson},
  title  = {{SciPy}: Open source scientific tools for {Python}},
  year   = {2001},
}
"""
    bibs = bm.read_file(text=text)
    assert len(bibs) == 1
Ejemplo n.º 12
0
def test_build_bib_inplace(mock_init):
    bm.merge(u.HOME+"examples/sample.bib")
    with cd(u.HOME+'examples'):
        missing = lm.build_bib("sample.tex")
        files = os.listdir(".")
        assert "texsample.bib" in files
        # Now check content:
        np.testing.assert_array_equal(missing, np.zeros(0,dtype="U"))
        bibs = bm.read_file("texsample.bib")
        assert len(bibs) == 8
        keys = [bib.key for bib in bibs]
        assert "AASteamHendrickson2018aastex62" in keys
        assert "HarrisEtal2020natNumpy" in keys
        assert "VirtanenEtal2020natmeScipy" in keys
        assert "Hunter2007ieeeMatplotlib" in keys
        assert "PerezGranger2007cseIPython" in keys
        assert "MeurerEtal2017pjcsSYMPY" in keys
        assert "Astropycollab2013aaAstropy" in keys
        assert "Cubillos2019zndoBibmanager" in keys
Ejemplo n.º 13
0
def test_duplicate_isbn_same_unknown_doi(mock_init, mock_input, entries):
    text = entries['isbn_no_doi1'] + entries['isbn_no_doi2']
    bibs = bm.read_file(text=text)
    assert len(bibs) == 1
Ejemplo n.º 14
0
def test_duplicate_isbn_doi_vs_no_doi(capfd, entries):
    text = entries['isbn_doi1'] + entries['isbn_no_doi2']
    bibs = bm.read_file(text=text)
    assert len(bibs) == 2
    captured = capfd.readouterr()
    assert captured.out == ''
Ejemplo n.º 15
0
def test_merge_bibs(capfd, mock_init):
    new = bm.read_file(u.HOME + "examples/sample.bib")
    bm.merge(new=new)
    captured = capfd.readouterr()
    assert captured.out == f"\nMerged {nentries} new entries.\n"
Ejemplo n.º 16
0
def test_read_file_error_open_end(mock_init):
    text = '@misc{key,\n author={name}'
    with pytest.raises(
            ValueError,
            match="Mismatched braces at/after line 0:\n@misc{key,"):
        bibs = bm.read_file(text=text)
Ejemplo n.º 17
0
def test_read_file_error_bad_format(mock_init):
    text = '@this will fail}'
    with pytest.raises(
            ValueError,
            match="Mismatched braces at/after line 0:\n@this will fail}"):
        bibs = bm.read_file(text=text)
Ejemplo n.º 18
0
def test_read_file_bibfile(mock_init):
    bibs = bm.read_file(u.ROOT+'examples/sample.bib')
    assert len(bibs) == nentries
Ejemplo n.º 19
0
def test_read_file_ignore_comment_no_commas(mock_init):
    text = """@Comment{jabref-meta: databaseType:biblatex;}"""
    bibs = bm.read_file(text=text)
    assert len(bibs) == 0
Ejemplo n.º 20
0
def test_read_file_text(mock_init):
    with open(u.ROOT+'examples/sample.bib') as f:
       text = f.read()
    bibs = bm.read_file(text=text)
    assert len(bibs) == nentries