def test_add_bibtex_none_found(reqs, mock_init): bibcodes = ['1925PhDT.....X...1P'] keys = ['Payne1925phdStellarAtmospheres'] with pytest.raises( ValueError, match="There were no entries found for the requested bibcodes."): am.add_bibtex(bibcodes, keys)
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 == """
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
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,
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_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'])