def test_build_raise(mock_init): bm.merge(u.HOME + "examples/sample.bib") with open(u.HOME + "examples/mock_file.tex", "w") as f: f.write("\\cite{Astropycollab2013aaAstropy}") with pytest.raises(Exception, match="No 'bibiliography' call found in tex file."): lm.build_bib(u.HOME + "examples/mock_file.tex")
def test_build_bib_missing(capsys, mock_init): # Assert screen output: 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, u.HOME + "my_file.bib") captured = capsys.readouterr() assert captured.out == "References not found:\nMissingEtal2019\n" # Check content: np.testing.assert_array_equal(missing, np.array(["MissingEtal2019"])) bibs = bm.loadfile(u.HOME + "my_file.bib") assert len(bibs) == 1 assert "Astropycollab2013aaAstropy" in bibs[0].key
def test_build_bib_inplace(mock_init): bm.merge(u.HOME + "examples/sample.bib") os.chdir(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.loadfile("texsample.bib") assert len(bibs) == 7 keys = [bib.key for bib in bibs] assert "AASteamHendrickson2018aastex62" in keys assert "vanderWaltEtal2011numpy" in keys assert "JonesEtal2001scipy" in keys assert "Hunter2007ieeeMatplotlib" in keys assert "PerezGranger2007cseIPython" in keys assert "MeurerEtal2017pjcsSYMPY" in keys assert "Astropycollab2013aaAstropy" in keys
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
def test_build_bib_user_bibfile(mock_init): bm.merge(u.HOME + "examples/sample.bib") lm.build_bib(u.HOME + "examples/sample.tex", bibfile=u.HOME + "my_file.bib") files = os.listdir(u.HOME) assert "my_file.bib" in files
def test_build_bib_remote(mock_init): bm.merge(u.HOME + "examples/sample.bib") lm.build_bib(u.HOME + "examples/sample.tex") files = os.listdir(u.HOME + "examples/") assert "texsample.bib" in files
def test_build_bib_user_bibfile(tmp_path, mock_init): bibfile = f'{tmp_path}/my_file.bib' bm.merge(u.HOME + "examples/sample.bib") lm.build_bib(u.HOME + "examples/sample.tex", bibfile=bibfile) assert "my_file.bib" in os.listdir(str(tmp_path))