def test_export_bib_book(self): xml_article_c = etree.tostring(etree.parse( "data/output/bib_import_single_book.phyml", parser), pretty_print=True) bib_article = "data/input/book.bib" xml = etree.tostring(xml_start) new_xml = import_bibliography(xml, bib_article) # Now export it back and compare the data temp_file_handle, temp_file = tempfile.mkstemp(suffix=".bib") export_bibliography(new_xml, temp_file) # parse both files in yapbib and compare b_orig = biblist.BibList() b_exported = biblist.BibList() b_orig.import_bibtex(bib_article) b_exported.import_bibtex(temp_file) items = b_exported.List( ) # yapbib helpfully renames the item key, so grab the first one exp = b_exported.get_item(items[0]) items = b_orig.List( ) # yapbib helpfully renames the item key, so grab the first one orig = b_orig.get_item(items[0]) os.remove(temp_file) self.assert_(orig.get('title') == exp.get('title')) self.assert_(orig.get('series') == exp.get('series')) self.assert_(orig.get('doi') == exp.get('doi')) self.assert_(orig.get('pages') == exp.get('pages')) self.assert_(orig.get('author') == exp.get('author')) self.assert_(orig.get('editor') == exp.get('editor')) self.assert_(orig.get('publisher') == exp.get('publisher'))
def test_katie_article2(self): bib_book = "data/input/endnote_online.bib" xml = etree.tostring(xml_start) try: new_xml = import_bibliography(xml, bib_book) except: return False return self.assert_(True)
def test_ut8_article(self): bib_import_utf8_answer = etree.tostring(etree.parse( "data/output/bib_import_utf8.phyml", parser), pretty_print=True) bib_utf8 = "data/input/utf8_input.bib" xml = etree.tostring(xml_start) new_xml = import_bibliography(xml, bib_utf8) self.assert_(isEqualXML(new_xml, bib_import_utf8_answer))
def test_import_single_book(self): xml_book_c = etree.tostring(etree.parse( "data/output/bib_import_single_book.phyml", parser), pretty_print=True) bib_book = "data/input/book.bib" xml = etree.tostring(xml_start) new_xml = import_bibliography(xml, bib_book) self.assert_(isEqualXML(new_xml, xml_book_c))
def test_import_single_article_doi(self): xml_article_c = etree.tostring(etree.parse( "data/output/bib_import_single_article_doi.phyml", parser), pretty_print=True) bib_article = "data/input/article_doi.bib" # import basic xml file xml = etree.tostring(xml_start) # call import_bib function new_xml = import_bibliography(xml, bib_article) # test resulting xml self.assert_(isEqualXML(new_xml, xml_article_c))
def test_missing_key(self): bib_book = "data/input/test2.bib" xml = etree.tostring(xml_start) try: new_xml = import_bibliography(xml, bib_book) except BibImportError as details: self.assert_( details.msg == "Error importing bib file. Error parsing: author = {Ahyong, S. T. and O'Meally, D.}, title = {Phylogeny of the Decapoda reptantia: Resolutio...\nMissing Bibtex Key" ) except: return False
def test_katie_article(self): bib_book = "data/input/test.bib" xml = etree.tostring(xml_start) try: new_xml = import_bibliography(xml, bib_book) except BibImportError as details: # Check that an entry with dodgy author entry reports the correct key to help the user find it self.assert_( details.msg == "Error importing bib file. Check all your authors for correct format: Porter2005" ) except: return False
def test_difficult_bibtex(self): bib_article = "data/input/difficult_bib.bib" xml = etree.tostring(xml_start) new_xml = import_bibliography(xml, bib_article) # Now export it back and compare the data temp_file_handle, temp_file = tempfile.mkstemp(suffix=".tex") export_bibliography(new_xml, temp_file) f = open(temp_file, "r") output = f.readlines() output = '\n'.join(output) os.remove(temp_file) # just asserts something useful has been written out self.assert_(output.find('Silva') > -1) self.assert_(output.find('pages = {1032-') > -1)
def test_export_short(self): bib_article = "data/input/article.bib" xml = etree.tostring(xml_start) new_xml = import_bibliography(xml, bib_article) # Now export it back and compare the data temp_file_handle, temp_file = tempfile.mkstemp(suffix=".tex") export_bibliography(new_xml, temp_file, format="short") f = open(temp_file, "r") output = f.readlines() output = '\n'.join(output) os.remove(temp_file) # just asserts something useful has been written out self.assert_(output.find('Davis') > -1) self.assert_(output.find('Hill') > -1)
def test_import_single_inbook(self): bib_article = "data/input/inbook.bib" xml = etree.tostring(xml_start) new_xml = import_bibliography(xml, bib_article) self.assert_(new_xml.find('in_book') > -1) # Now export it back and compare the data temp_file_handle, temp_file = tempfile.mkstemp(suffix=".tex") export_bibliography(new_xml, temp_file) f = open(temp_file, "r") output = f.readlines() output = '\n'.join(output) os.remove(temp_file) # just asserts something useful has been written out self.assert_(output.find('author = { Mallet') > -1) self.assert_(output.find('pages = {177-') > -1) self.assert_(output.find('Speciation and Patterns of Diversity') > -1)