|
6 | 6 | import os |
7 | 7 | import unittest |
8 | 8 | import codecs |
| 9 | +import warnings |
9 | 10 |
|
| 11 | +import bibtexparser |
10 | 12 | from bibtexparser.bparser import BibTexParser |
11 | 13 | from bibtexparser.bibdatabase import (COMMON_STRINGS, BibDataStringExpression) |
12 | 14 | from bibtexparser.customization import * |
@@ -650,6 +652,60 @@ def test_no_citekey_parsed_as_comment(self): |
650 | 652 | self.assertEqual(bib.strings, {}) |
651 | 653 | self.assertEqual(bib.comments, ['@BOOK{, title = "bla"}']) |
652 | 654 |
|
| 655 | + def test_parsing_just_once_not_raising_warnings_with_default_settings(self): |
| 656 | + parser = BibTexParser() |
| 657 | + |
| 658 | + with open('bibtexparser/tests/data/article_comma_normal_single.bib', |
| 659 | + 'r', encoding='utf-8') as bibfile: |
| 660 | + with warnings.catch_warnings(record=True) as warning: |
| 661 | + warnings.simplefilter("always") |
| 662 | + bibtexparser.load(bibfile, parser) |
| 663 | + assert len(warning) == 0 |
| 664 | + |
| 665 | + def test_parsing_twice_raise_warnings_with_default_settings(self): |
| 666 | + parser = BibTexParser() |
| 667 | + |
| 668 | + with open('bibtexparser/tests/data/article_comma_normal_single.bib', |
| 669 | + 'r', encoding='utf-8') as bibfile_first, \ |
| 670 | + open('bibtexparser/tests/data/article_comma_normal_multiple.bib', 'r', encoding='utf-8') \ |
| 671 | + as bibfile_second: |
| 672 | + with warnings.catch_warnings(record=True) as warning: |
| 673 | + warnings.simplefilter("always") |
| 674 | + bibtexparser.load(bibfile_first, parser) |
| 675 | + bibtexparser.load(bibfile_second, parser) |
| 676 | + assert len(warning) != 0 |
| 677 | + |
| 678 | + def test_parsing_three_times_raise_warnings_only_once_with_default_settings(self): |
| 679 | + parser = BibTexParser() |
| 680 | + |
| 681 | + with open('bibtexparser/tests/data/article_comma_normal_single.bib', |
| 682 | + 'r', encoding='utf-8') as bibfile_first, \ |
| 683 | + open('bibtexparser/tests/data/article_comma_normal_multiple.bib', 'r', encoding='utf-8') \ |
| 684 | + as bibfile_second, \ |
| 685 | + open('bibtexparser/tests/data/article.bib', 'r', encoding='utf-8') as bibfile_third: |
| 686 | + with warnings.catch_warnings(record=True) as warning: |
| 687 | + warnings.simplefilter("always") |
| 688 | + bibtexparser.load(bibfile_first, parser) |
| 689 | + bibtexparser.load(bibfile_second, parser) |
| 690 | + bibtexparser.load(bibfile_third, parser) |
| 691 | + assert len(warning) == 1 |
| 692 | + |
| 693 | + def test_parsing_three_times_not_raising_a_warning_if_expect_multiple_parse_is_true(self): |
| 694 | + parser = BibTexParser() |
| 695 | + parser.expect_multiple_parse = True |
| 696 | + |
| 697 | + with open('bibtexparser/tests/data/article_comma_normal_single.bib', |
| 698 | + 'r', encoding='utf-8') as bibfile_first, \ |
| 699 | + open('bibtexparser/tests/data/article_comma_normal_multiple.bib', 'r', encoding='utf-8') \ |
| 700 | + as bibfile_second, \ |
| 701 | + open('bibtexparser/tests/data/article.bib', 'r', encoding='utf-8') as bibfile_third: |
| 702 | + with warnings.catch_warnings(record=True) as warning: |
| 703 | + warnings.simplefilter("always") |
| 704 | + bibtexparser.load(bibfile_first, parser) |
| 705 | + bibtexparser.load(bibfile_second, parser) |
| 706 | + bibtexparser.load(bibfile_third, parser) |
| 707 | + assert len(warning) == 0 |
| 708 | + |
653 | 709 |
|
654 | 710 | if __name__ == '__main__': |
655 | 711 | unittest.main() |
0 commit comments