|
13 | 13 | from docfx_yaml.extension import parse_markdown_header |
14 | 14 |
|
15 | 15 | import unittest |
| 16 | +from parameterized import parameterized |
16 | 17 |
|
17 | 18 | from yaml import load, Loader |
18 | 19 |
|
@@ -667,74 +668,70 @@ def test_parse_markdown_header_alternate(self): |
667 | 668 | self.assertEqual(header_line_got, header_line_want) |
668 | 669 |
|
669 | 670 |
|
670 | | - def test_extract_header_from_markdown(self): |
671 | | - # Check the header for a normal markdown file. |
| 671 | + test_markdown_filenames = [ |
| 672 | + [ |
| 673 | + # Check the header for a normal markdown file. |
| 674 | + "tests/markdown_example.md" |
| 675 | + ], |
| 676 | + [ |
| 677 | + # The header should be the same even with the license header. |
| 678 | + "tests/markdown_example_header.md" |
| 679 | + ], |
| 680 | + ] |
| 681 | + @parameterized.expand(test_markdown_filenames) |
| 682 | + def test_extract_header_from_markdown(self, markdown_filename): |
| 683 | + # Check the header for markdown files. |
672 | 684 | header_line_want = "Test header for a simple markdown file." |
673 | 685 |
|
674 | | - with open('tests/markdown_example.md', 'r') as mdfile: |
| 686 | + with open(markdown_filename, 'r') as mdfile: |
675 | 687 | header_line_got = extract_header_from_markdown(mdfile) |
676 | 688 |
|
677 | 689 | self.assertEqual(header_line_got, header_line_want) |
678 | 690 |
|
679 | | - # The header should be the same even with the license header. |
680 | | - header_line_with_license_want = header_line_want |
681 | | - |
682 | | - with open('tests/markdown_example_header.md', 'r') as mdfile_license: |
683 | | - header_line_with_license_got = extract_header_from_markdown(mdfile_license) |
684 | | - |
685 | | - self.assertEqual(header_line_with_license_got, header_line_with_license_want) |
686 | 691 |
|
687 | | - |
688 | | - def test_extract_header_from_markdown_alternate_header(self): |
689 | | - # Check the header for an alternate header style. |
690 | | - header_line_want = "This is a simple alternate header" |
691 | | - |
692 | | - with open('tests/markdown_example_alternate.md', 'r') as mdfile: |
693 | | - header_line_got = extract_header_from_markdown(mdfile) |
694 | | - |
695 | | - self.assertEqual(header_line_got, header_line_want) |
696 | | - |
697 | | - # The header should be the same even with the license header. |
698 | | - header_line_with_license_want = header_line_want |
699 | | - |
700 | | - with open('tests/markdown_example_alternate_header.md', 'r') as mdfile: |
701 | | - header_line_with_license_got = extract_header_from_markdown(mdfile) |
702 | | - |
703 | | - self.assertEqual(header_line_with_license_got, header_line_with_license_want) |
704 | | - |
705 | | - # Check the header for an alternate header style. |
| 692 | + test_markdown_filenames = [ |
| 693 | + [ |
| 694 | + # Check the header for an alternate header style. |
| 695 | + "tests/markdown_example_alternate.md" |
| 696 | + ], |
| 697 | + [ |
| 698 | + # The header should be the same even with the license header. |
| 699 | + "tests/markdown_example_alternate_header.md" |
| 700 | + ], |
| 701 | + [ |
| 702 | + # Check the header for an alternate header style. |
| 703 | + "tests/markdown_example_alternate_less.md" |
| 704 | + ], |
| 705 | + ] |
| 706 | + @parameterized.expand(test_markdown_filenames) |
| 707 | + def test_extract_header_from_markdown_alternate_header(self, markdown_filename): |
| 708 | + # Check the header for different accepted styles. |
706 | 709 | header_line_want = "This is a simple alternate header" |
707 | 710 |
|
708 | | - with open('tests/markdown_example_alternate_less.md', 'r') as mdfile: |
| 711 | + with open(markdown_filename, 'r') as mdfile: |
709 | 712 | header_line_got = extract_header_from_markdown(mdfile) |
710 | 713 |
|
711 | 714 | self.assertEqual(header_line_got, header_line_want) |
712 | 715 |
|
713 | 716 |
|
714 | | - def test_extract_header_from_markdown_bad_headers(self): |
715 | | - # Check that the filename is used as header if no valid header is found. |
716 | | - header_line_want = "Markdown_example_bad_header" |
717 | | - |
718 | | - with open('tests/markdown_example_bad_header.md', 'r') as mdfile: |
719 | | - header_line_got = extract_header_from_markdown(mdfile) |
720 | | - |
721 | | - self.assertEqual(header_line_want, header_line_got) |
722 | | - |
723 | | - # Check that only h1 headers are parsed. |
724 | | - header_line_want = "Markdown_example_h2" |
725 | | - |
726 | | - with open('tests/markdown_example_h2.md', 'r') as mdfile: |
727 | | - header_line_got = extract_header_from_markdown(mdfile) |
728 | | - |
729 | | - self.assertEqual(header_line_want, header_line_got) |
730 | | - |
731 | | - # Check that there must be a line before the h1 header breaker. |
732 | | - header_line_want = "Markdown_example_alternate_bad" |
733 | | - |
734 | | - with open('tests/markdown_example_alternate_bad.md', 'r') as mdfile: |
| 717 | + test_markdown_filenames = [ |
| 718 | + [ |
| 719 | + "tests/markdown_example_bad_header.md" |
| 720 | + ], |
| 721 | + [ |
| 722 | + "tests/markdown_example_h2.md" |
| 723 | + ], |
| 724 | + [ |
| 725 | + "tests/markdown_example_alternate_bad.md" |
| 726 | + ], |
| 727 | + ] |
| 728 | + @parameterized.expand(test_markdown_filenames) |
| 729 | + def test_extract_header_from_markdown_bad_headers(self, markdown_filename): |
| 730 | + # Check that empty string is returned if no valid header is found. |
| 731 | + with open(markdown_filename, 'r') as mdfile: |
735 | 732 | header_line_got = extract_header_from_markdown(mdfile) |
736 | 733 |
|
737 | | - self.assertEqual(header_line_want, header_line_got) |
| 734 | + self.assertFalse(header_line_got) |
738 | 735 |
|
739 | 736 |
|
740 | 737 | def test_parse_docstring_summary(self): |
|
0 commit comments