def test_crossref_cascading_cycle(self):
     input_file_path = ('tests/data/crossref_cascading_cycle.bib')
     entries_expected = {
         'circ1': {
             'ENTRYTYPE': 'book',
             'ID': 'circ1',
             '_FROM_CROSSREF': [],
             'crossref': 'circ2',
             'date': '1911',
         },
         'circ2': {
             'ENTRYTYPE': 'book',
             'ID': 'circ2',
             '_FROM_CROSSREF': [],
             'crossref': 'circ1',
             'date': '1911',
         },
     }
     parser = BibTexParser(add_missing_from_crossref=True)
     with self.assertLogs('bibdeskparser.bibdatabase', level='ERROR') as cm:
         with open(input_file_path) as bibtex_file:
             bibtex_database = parser.parse_file(bibtex_file)
         self.assertIn(
             "ERROR:bibdeskparser.bibdatabase:Circular crossref dependency: circ1->circ2->circ1.",
             cm.output,
         )
     self.assertDictEqual(bibtex_database.entries_dict, entries_expected)
Exemplo n.º 2
0
 def test_article_comma_first(self):
     with open(
         'tests/data/article_comma_first.bib', 'r'
     ) as bibfile:
         bib = BibTexParser(bibfile.read())
         res = bib.get_entry_list()
     expected = [
         {
             'ENTRYTYPE': 'article',
             'journal': 'Nice Journal',
             'volume': '12',
             'ID': 'Cesar2013',
             'year': '2013',
             'author': 'Jean Cesar',
             'comments': 'A comment',
             'keyword': 'keyword1, keyword2',
             'title': 'An amazing title',
         },
         {
             'ENTRYTYPE': 'article',
             'journal': 'Nice Journal',
             'volume': '12',
             'ID': 'Baltazar2013',
             'year': '2013',
             'author': 'Jean Baltazar',
             'comments': 'A comment',
             'keyword': 'keyword1, keyword2',
             'title': 'An amazing title',
         },
     ]
     self.assertEqual(res, expected)
    def test_crossref_cascading(self):
        input_file_path = 'tests/data/crossref_cascading.bib'
        entries_expected = {
            'r1': {
                'ENTRYTYPE': 'book',
                'ID': 'r1',
                '_FROM_CROSSREF': [],
                'crossref': 'r2',
                'date': '1911',
            },
            'r2': {
                'ENTRYTYPE': 'book',
                'ID': 'r2',
                '_FROM_CROSSREF': [],
                'crossref': 'r3',
                'date': '1911',
            },
            'r3': {
                'ENTRYTYPE': 'book',
                'ID': 'r3',
                '_FROM_CROSSREF': [],
                'crossref': 'r4',
                'date': '1911',
            },
            'r4': {
                'ENTRYTYPE': 'book',
                'ID': 'r4',
                'date': '1911'
            },
        }

        parser = BibTexParser(add_missing_from_crossref=True)
        with open(input_file_path) as bibtex_file:
            bibtex_database = parser.parse_file(bibtex_file)
        self.assertDictEqual(bibtex_database.entries_dict, entries_expected)
Exemplo n.º 4
0
 def test_comments_spaces_and_declarations(self):
     with codecs.open(
         'tests/data/comments_spaces_and_declarations.bib',
         'r',
         'utf-8',
     ) as bibfile:
         bib = BibTexParser(bibfile.read())
     res_dict = bib.get_entry_dict()
     expected_dict = {
         'Cesar2013': {
             'keyword': 'keyword1, keyword2',
             'ENTRYTYPE': 'article',
             'abstract': 'This is an abstract. This line should be long enough to test\nmultilines... and with a french érudit word',
             'year': '2013',
             'journal': 'Nice Journal',
             'ID': 'Cesar2013',
             'pages': '12-23',
             'title': 'A great title',
             'comments': 'A comment',
             'author': 'Jean César',
             'volume': '12',
             'month': 'jan',
         }
     }
     self.assertEqual(res_dict, expected_dict)
     self.assertEqual(bib.preambles, ["Blah blah"])
Exemplo n.º 5
0
 def test_encoding_with_homogenize(self):
     with codecs.open(
         'tests/data/encoding.bib', 'r', 'utf-8'
     ) as bibfile:
         bib = BibTexParser(
             bibfile.read(), customization=homogenize_latex_encoding
         )
         res = bib.get_entry_list()
         expected = [
             {
                 'keywords': 'keyword1, keyword2',
                 'ENTRYTYPE': 'article',
                 'abstract': 'This is an abstract. This line should be long enough to test\nmultilines... and with a french {\\\'e}rudit word',
                 'year': '2013',
                 'journal': 'El{\\\'e}mentaire',
                 'ID': 'Cesar_2013',
                 'pages': '12-23',
                 'title': '{A}n amazing title: {\\`a}',
                 'comments': 'A comment',
                 'author': 'Jean C{\\\'e}sar',
                 'volume': '12',
                 'month': 'jan',
             }
         ]
     self.assertEqual(res, expected)
Exemplo n.º 6
0
 def test_article_cust_latex(self):
     with codecs.open(
         'tests/data/article.bib', 'r', 'utf-8'
     ) as bibfile:
         bib = BibTexParser(
             bibfile.read(), customization=customizations_latex
         )
         res = bib.get_entry_list()
     expected = [
         {
             'abstract': 'This is an abstract. This line should be long enough to test\nmultilines... and with a french {\\\'e}rudit word',
             'ENTRYTYPE': 'article',
             'pages': '12--23',
             'volume': '12',
             'ID': 'Cesar2013',
             'year': '2013',
             'author': ['C{\\\'e}sar, Jean'],
             'journal': {'ID': 'NiceJournal', 'name': 'Nice Journal'},
             'comments': 'A comment',
             'month': 'jan',
             'keyword': ['keyword1', 'keyword2'],
             'title': '{A}n amazing title',
         }
     ]
     self.assertEqual(res, expected)
Exemplo n.º 7
0
 def test_nonstandard_ignored(self):
     with open('tests/data/wrong.bib', 'r') as bibfile:
         bib = BibTexParser(bibfile.read())
         res = bib.get_entry_list()
         expected = [
             {'author': 'correct', 'ID': 'bar', 'ENTRYTYPE': 'article'}
         ]
     self.assertEqual(res, expected)
Exemplo n.º 8
0
 def test_features(self):
     with open('tests/data/features.bib', 'r') as bibfile:
         bib = BibTexParser(bibfile.read())
         res = bib.get_entry_list()
         expected = [
             {
                 'ENTRYTYPE': 'inproceedings',
                 'year': '2014',
                 'title': 'Cool Stuff',
                 'author': 'John',
                 'ID': 'mykey',
                 'booktitle': 'My International Conference',
             }
         ]
     self.assertEqual(res, expected)
Exemplo n.º 9
0
    def test_multiline_comments(self):
        with open('tests/data/multiline_comments.bib') as bibfile:
            bib = BibTexParser(bibfile.read())
        expected = [
            """Lorem ipsum dolor sit amet,
consectetur adipisicing elit""",
            """
Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident.
 ,
""",
            """


Sunt in culpa qui officia deserunt mollit anim id est laborum.


""",
            "",
        ]
        self.maxDiff = None
        self.assertEqual(bib.comments, expected)
Exemplo n.º 10
0
    def test_multiline_comment_write(self):
        with open('tests/data/multiline_comments.bib') as bibfile:
            expected = bibfile.read()

        bib = BibTexParser(expected)
        result = to_bibtex(bib)
        self.assertEqual(result, expected)
Exemplo n.º 11
0
 def test_string_is_not_interpolated(self):
     with open(
         'tests/data/article_with_strings.bib', 'r'
     ) as bibfile:
         bib = BibTexParser(
             bibfile.read(), common_strings=True, interpolate_strings=False
         )
     res = bib.get_entry_list()[0]
     self.assertIsInstance(res['month'], BibDataStringExpression)
     self.assertEqual(len(res['month'].expr), 1)
     self.assertEqual(res['month'].get_value(), 'January')
     self.assertIsInstance(res['author'], BibDataStringExpression)
     self.assertEqual(len(res['author'].expr), 3)
     self.assertEqual(res['author'].get_value(), 'Jean César')
     self.assertIsInstance(res['journal'], BibDataStringExpression)
     self.assertEqual(len(res['journal'].expr), 1)
     self.assertEqual(res['journal'].get_value(), 'Nice Journal')
Exemplo n.º 12
0
 def test_multiple_entries(self):
     with open('tests/data/multiple_entries_and_comments.bib') as bibfile:
         bib = BibTexParser(bibfile.read())
     with open('tests/data/multiple_entries_and_comments_output.bib'
               ) as bibfile:
         expected = bibfile.read()
     result = to_bibtex(bib)
     self.assertEqual(result, expected)
Exemplo n.º 13
0
    def test_comment_write(self):
        with open('tests/data/comments_only.bib') as bibfile:
            bib = BibTexParser(bibfile.read())

        with open('tests/data/comments_only_output.bib') as bibfile:
            expected = bibfile.read()
        result = to_bibtex(bib)
        self.assertEqual(result, expected)
Exemplo n.º 14
0
 def test_43(self):
     comment = ("@STRING{foo = \"bar\"}\n"
                "This is a comment\n"
                "This is a second comment.")
     expected = "This is a comment\nThis is a second comment."
     bib = BibTexParser(comment)
     self.assertEqual(bib.comments, [expected])
     self.assertEqual(bib.strings, {'foo': 'bar'})
Exemplo n.º 15
0
 def test_article_annotation(self):
     with codecs.open(
         'tests/data/article_with_annotation.bib',
         'r',
         'utf-8',
     ) as bibfile:
         bib = BibTexParser(bibfile.read())
         res_list = bib.get_entry_list()
         res_dict = bib.get_entry_dict()
         expected_list = [
             {
                 'keyword': 'keyword1, keyword2',
                 'ENTRYTYPE': 'article',
                 'abstract': 'This is an abstract. This line should be long enough to test\nmultilines... and with a french érudit word',
                 'year': '2013',
                 'journal': 'Nice Journal',
                 'ID': 'Cesar2013',
                 'pages': '12-23',
                 'title': 'An amazing title',
                 'comments': 'A comment',
                 'author': 'Jean César',
                 'author+an': '1=highlight',
                 'volume': '12',
                 'month': 'jan',
             }
         ]
         expected_dict = {
             'Cesar2013': {
                 'keyword': 'keyword1, keyword2',
                 'ENTRYTYPE': 'article',
                 'abstract': 'This is an abstract. This line should be long enough to test\nmultilines... and with a french érudit word',
                 'year': '2013',
                 'journal': 'Nice Journal',
                 'ID': 'Cesar2013',
                 'pages': '12-23',
                 'title': 'An amazing title',
                 'comments': 'A comment',
                 'author': 'Jean César',
                 'author+an': '1=highlight',
                 'volume': '12',
                 'month': 'jan',
             }
         }
     self.assertEqual(res_list, expected_list)
     self.assertEqual(res_dict, expected_dict)
Exemplo n.º 16
0
 def test_comment_list(self):
     with open('tests/data/features.bib') as bibfile:
         bib = BibTexParser(bibfile.read())
     expected = [
         "ignore this line!",
         "ignore this line too!",
         "and ignore this line too!",
     ]
     self.assertEqual(bib.comments, expected)
Exemplo n.º 17
0
 def test_string_braces(self):
     with codecs.open(
         'tests/data/string.bib', 'r', 'utf-8'
     ) as bibfile:
         bib = BibTexParser(bibfile.read())
         res = bib.get_entry_list()
     expected = [
         {
             'author': 'Sang Kil Cha and Maverick Woo and David Brumley',
             'ID': 'cha:oakland15',
             'year': '2015',
             'booktitle': 'Proceedings of the {IEEE} Symposium on Security and Privacy',
             'title': '{Program-Adaptive Mutational Fuzzing}',
             'ENTRYTYPE': 'inproceedings',
             'pages': '725--741',
         }
     ]
     self.assertEqual(res, expected)
Exemplo n.º 18
0
    def test_book(self):
        with open('tests/data/book.bib', 'r') as bibfile:
            bib = BibTexParser(bibfile.read())
            res = bib.get_entry_list()
            expected = [
                {
                    'ENTRYTYPE': 'book',
                    'year': '1987',
                    'edition': '2',
                    'publisher': 'Wiley Edition',
                    'ID': 'Bird1987',
                    'volume': '1',
                    'title': 'Dynamics of Polymeric Liquid',
                    'author': 'Bird, R.B. and Armstrong, R.C. and Hassager, O.',
                }
            ]

        self.assertEqual(res, expected)
Exemplo n.º 19
0
    def test_book(self):
        with io.open(_data_path('book.bib'), 'r') as bibfile:
            bib = BibTexParser(bibfile.read())

        with io.open(_data_path('book_output.bib'), 'r') as bibfile:
            expected = bibfile.read()
        result = to_bibtex(bib)
        self.maxDiff = None
        self.assertEqual(expected, result)
Exemplo n.º 20
0
 def test_43_bis(self):
     comment = ("@STRING{foo = \"bar\"}\n"
                "This is a comment\n"
                "STRING{Baz = \"This should be interpreted as comment.\"}")
     expected = ("This is a comment\n"
                 "STRING{Baz = \"This should be interpreted as comment.\"}")
     bib = BibTexParser(comment)
     self.assertEqual(bib.comments, [expected])
     self.assertEqual(bib.strings, {'foo': 'bar'})
Exemplo n.º 21
0
 def test_string_definitions(self):
     with open(
         'tests/data/article_with_strings.bib', 'r'
     ) as bibfile:
         bib = BibTexParser(bibfile.read(), common_strings=True)
     res = dict(bib.strings)
     expected = COMMON_STRINGS.copy()
     expected.update(
         {'nice_journal': 'Nice Journal', 'jean': 'Jean', 'cesar': "César"}
     )
     self.assertEqual(res, expected)
Exemplo n.º 22
0
    def test_comma_first(self):
        with io.open(_data_path('book.bib'), 'r') as bibfile:
            bib = BibTexParser(bibfile.read())

        with io.open(_data_path('book_comma_first.bib'), 'r') as bibfile:
            expected = bibfile.read()
        writer = BibTexWriter()
        writer.indent = '   '
        writer.comma_first = True
        result = writer.write(bib)
        self.maxDiff = None
        self.assertEqual(expected, result)
Exemplo n.º 23
0
 def test_with_strings(self):
     with io.open(_data_path('article_with_strings.bib'), 'r') as bibfile:
         bib = BibTexParser(
             bibfile.read(), common_strings=True, interpolate_strings=False
         )
     with io.open(
         _data_path('article_with_strings_output.bib'), 'r'
     ) as bibfile:
         expected = bibfile.read()
     result = to_bibtex(bib)
     self.maxDiff = None
     self.assertEqual(expected, result)
Exemplo n.º 24
0
    def test_article_with_annotation(self):
        with io.open(
            _data_path('article_with_annotation.bib'), 'r'
        ) as bibfile:
            bib = BibTexParser(bibfile.read())

        with io.open(
            _data_path('article_with_annotation_output.bib'), 'r'
        ) as bibfile:
            expected = bibfile.read()
        result = to_bibtex(bib)
        self.maxDiff = None
        self.assertEqual(expected, result)
Exemplo n.º 25
0
    def test_trailing_comma(self):
        with io.open(_data_path('article.bib'), 'r') as bibfile:
            bib = BibTexParser(bibfile.read())

        with io.open(
            _data_path('article_trailing_comma_output.bib'), 'r'
        ) as bibfile:
            expected = bibfile.read()
        writer = BibTexWriter()
        writer.add_trailing_comma = True
        result = writer.write(bib)
        self.maxDiff = None
        self.assertEqual(expected, result)
Exemplo n.º 26
0
 def test_traps(self):
     with codecs.open(
         'tests/data/traps.bib', 'r', 'utf-8'
     ) as bibfile:
         bib = BibTexParser(bibfile.read())
         res = bib.get_entry_list()
         expected = [
             {
                 'keywords': 'keyword1, keyword2',
                 'ENTRYTYPE': 'article',
                 'abstract': 'This is an abstract. This line should be long enough to test\nmultilines... and with a french érudit word',
                 'year': '2013',
                 'journal': 'Nice Journal',
                 'ID': 'Laide2013',
                 'pages': '12-23',
                 'title': '{An} amazing {title}',
                 'comments': 'A comment',
                 'author': 'Jean Laid{\\\'e},\nBen Loaeb',
                 'volume': 'n.s.~2',
                 'month': 'jan',
             }
         ]
     self.assertEqual(res, expected)
Exemplo n.º 27
0
 def test_article_protection_braces(self):
     with open(
         'tests/data/article_with_protection_braces.bib', 'r'
     ) as bibfile:
         bib = BibTexParser(bibfile.read())
         res = bib.get_entry_list()
     expected = [
         {
             'ENTRYTYPE': 'article',
             'journal': '{Nice Journal}',
             'volume': '12',
             'pages': '12-23',
             'ID': 'Cesar2013',
             'year': '2013',
             'month': 'jan',
             'author': 'Jean César',
             'comments': 'A comment',
             'keyword': 'keyword1, keyword2',
             'title': '{An amazing title}',
             'abstract': "This is an abstract. This line should be long enough to test\nmultilines... and with a french érudit word",
         }
     ]
     self.assertEqual(res, expected)
Exemplo n.º 28
0
    def test_crossref_missing_entries(self):
        input_file_path = ('tests/data/crossref_missing_entries.bib')
        entries_expected = {
            'mcr': {
                'ENTRYTYPE': 'inbook',
                'ID': 'mcr',
                '_crossref': 'missing1',
                'author': 'Megan Mistrel',
                'crossref': 'missing1',
                'origdate': '1933',
                'title': 'Lumbering Lunatics',
            }
        }

        parser = BibTexParser(add_missing_from_crossref=True)
        with self.assertLogs('bibdeskparser.bibdatabase', level='ERROR') as cm:
            with open(input_file_path) as bibtex_file:
                bibtex_database = parser.parse_file(bibtex_file)
            self.assertIn(
                "ERROR:bibdeskparser.bibdatabase:Crossref reference missing1 for mcr is missing.",
                cm.output,
            )
        self.assertDictEqual(bibtex_database.entries_dict, entries_expected)
Exemplo n.º 29
0
 def test_string_is_interpolated(self):
     with open(
         'tests/data/article_with_strings.bib', 'r'
     ) as bibfile:
         bib = BibTexParser(
             bibfile.read(), common_strings=True, interpolate_strings=True
         )
     res = bib.get_entry_list()
     expected = [
         {
             'keyword': 'keyword1, keyword2',
             'ENTRYTYPE': 'article',
             'year': '2013',
             'month': 'January',
             'journal': 'Nice Journal',
             'ID': 'Cesar2013',
             'pages': '12-23',
             'title': 'An amazing title',
             'comments': 'A comment',
             'author': 'Jean César',
             'volume': '12',
         }
     ]
     self.assertEqual(res, expected)
Exemplo n.º 30
0
 def test_field_name_with_dash_underscore(self):
     with open(
         'tests/data/article_field_name_with_underscore.bib',
         'r',
     ) as bibfile:
         bib = BibTexParser(bibfile.read())
     res = bib.get_entry_list()
     expected = [
         {
             'keyword': 'keyword1, keyword2',
             'ENTRYTYPE': 'article',
             'year': '2013',
             'journal': 'Nice Journal',
             'ID': 'Cesar2013',
             'pages': '12-23',
             'title': 'An amazing title',
             'comments': 'A comment',
             'author': 'Jean César',
             'volume': '12',
             'strange_field_name': 'val',
             'strange-field-name2': 'val2',
         }
     ]
     self.assertEqual(res, expected)