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_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)
def test_export_bib_nopages(self): xml_article_c = etree.tostring(etree.parse( "data/input/bib_export_no_pages.phyml", parser), pretty_print=True) # Now export it back and compare the data temp_file_handle, temp_file = tempfile.mkstemp(suffix=".bib") export_bibliography(xml_article_c, temp_file) # parse both files in yapbib and compare b_exported = biblist.BibList() 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]) os.remove(temp_file) self.assert_(exp.get('title') == "A great and important paper") self.assert_(exp.get('pages') == None)