Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
0
    def test_article_cust_order(self):
        def cust(record):
            record = customization.page_double_hyphen(record)
            record = customization.homogenize_latex_encoding(record)
            record = customization.author(record)
            return record

        def cust2(record):
            record = customization.author(record)
            record = customization.page_double_hyphen(record)
            record = customization.homogenize_latex_encoding(record)
            return record

        with open(
            'tests/data/multiple_entries.bib', 'r'
        ) as bibfile:
            bib = BibTexParser(bibfile.read(), customization=cust)
            res = bib.get_entry_list()
        with open(
            'tests/data/multiple_entries.bib', 'r'
        ) as bibfile:
            bib2 = BibTexParser(bibfile.read(), customization=cust2)
            res2 = bib.get_entry_list()
        self.assertEqual(res, res2)
Esempio n. 6
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)
Esempio n. 7
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')
Esempio n. 8
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)
Esempio n. 9
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)
Esempio n. 10
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)
Esempio n. 11
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)
Esempio n. 12
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)
Esempio n. 13
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)
Esempio n. 14
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)
Esempio n. 15
0
    def test_book_cust_latex(self):
        with open('tests/data/book.bib', 'r') as bibfile:
            bib = BibTexParser(
                bibfile.read(), customization=customizations_latex
            )
            res = bib.get_entry_list()
            expected = [
                {
                    'ENTRYTYPE': 'book',
                    'year': '1987',
                    'edition': '2',
                    'publisher': 'Wiley Edition',
                    'ID': 'Bird1987',
                    'volume': '1',
                    'title': '{D}ynamics of {P}olymeric {L}iquid',
                    'author': [
                        'Bird, R.B.',
                        'Armstrong, R.C.',
                        'Hassager, O.',
                    ],
                }
            ]

        self.assertEqual(res, expected)
Esempio n. 16
0
 def test_article_start_with_whitespace(self):
     with open(
         'tests/data/article_start_with_whitespace.bib', 'r'
     ) as bibfile:
         bib = BibTexParser(bibfile.read())
         self.assertEqual(len(bib.get_entry_list()), 2)
Esempio n. 17
0
 def test_nonstandard_not_ignored(self):
     with open('tests/data/wrong.bib', 'r') as bibfile:
         bib = BibTexParser(bibfile.read(), ignore_nonstandard_types=False)
         res = bib.get_entry_list()
     self.assertEqual(len(res), 2)