def test_align(self): bib_database = BibDatabase() bib_database.entries = [{ 'ID': 'abc123', 'ENTRYTYPE': 'book', 'author': 'test', 'thisisaverylongkey': 'longvalue', }] writer = BibTexWriter() writer.align_values = True result = bibdeskparser.dumps(bib_database, writer) expected = """@book{abc123, author = {test}, thisisaverylongkey = {longvalue} } """ self.assertEqual(result, expected) with open( 'tests/data/multiple_entries_and_comments.bib') as bibtex_file: bib_database = bibdeskparser.load(bibtex_file) writer = BibTexWriter() writer.contents = ['entries'] writer.align_values = True result = bibdeskparser.dumps(bib_database, writer) expected = """@book{Toto3000, author = {Toto, A and Titi, B}, title = {A title} } @article{Wigner1938, author = {Wigner, E.}, doi = {10.1039/TF9383400029}, issn = {0014-7672}, journal = {Trans. Faraday Soc.}, owner = {fr}, pages = {29--41}, publisher = {The Royal Society of Chemistry}, title = {The transition state method}, volume = {34}, year = {1938} } @book{Yablon2005, author = {Yablon, A.D.}, publisher = {Springer}, title = {Optical fiber fusion slicing}, year = {2005} } """ self.assertEqual(result, expected)
def test_entry_separator(self): bib_database = BibDatabase() bib_database.entries = [{ 'ID': 'abc123', 'ENTRYTYPE': 'book', 'author': 'test' }] writer = BibTexWriter() writer.entry_separator = '' result = bibdeskparser.dumps(bib_database, writer) expected = """@book{abc123, author = {test} } """ self.assertEqual(result, expected)
def test_sort_missing_field(self): bib_database = BibDatabase() bib_database.entries = [ { 'ID': 'b', 'ENTRYTYPE': 'article', 'year': '2000' }, { 'ID': 'c', 'ENTRYTYPE': 'book', 'year': '2010' }, { 'ID': 'a', 'ENTRYTYPE': 'book' }, ] writer = BibTexWriter() writer.order_entries_by = ('year', ) result = bibdeskparser.dumps(bib_database, writer) expected = "@book{a\n}\n\n@article{b,\n year = {2000}\n}\n\n@book{c,\n year = {2010}\n}\n\n" self.assertEqual(result, expected)
def test_entries_dict_prop(self): bib_db = BibDatabase() bib_db.entries = self.entries self.assertEqual(bib_db.entries_dict, bib_db.get_entry_dict())
def test_entries_list_method(self): bib_db = BibDatabase() bib_db.entries = self.entries self.assertEqual(bib_db.entries, bib_db.get_entry_list())