|
| 1 | +import pytest |
| 2 | +from pyfakefs.fake_filesystem import FakeFilesystem |
| 3 | + |
| 4 | +import blurb |
| 5 | + |
| 6 | + |
| 7 | +UNCHANGED_SECTIONS = ( |
| 8 | + "C API", |
| 9 | + "Core and Builtins", |
| 10 | + "Library", |
| 11 | +) |
| 12 | + |
| 13 | + |
| 14 | +@pytest.mark.parametrize("section", UNCHANGED_SECTIONS) |
| 15 | +def test_sanitize_section_no_change(section: str) -> None: |
| 16 | + sanitized = blurb.sanitize_section(section) |
| 17 | + assert sanitized == section |
| 18 | + |
| 19 | + |
| 20 | +@pytest.mark.parametrize( |
| 21 | + "section, expected", |
| 22 | + ( |
| 23 | + ("Tools/Demos", "Tools-Demos"), |
| 24 | + ), |
| 25 | +) |
| 26 | +def test_sanitize_section_changed(section: str, expected: str) -> None: |
| 27 | + sanitized = blurb.sanitize_section(section) |
| 28 | + assert sanitized == expected |
| 29 | + |
| 30 | + |
| 31 | +@pytest.mark.parametrize("section", UNCHANGED_SECTIONS) |
| 32 | +def test_unsanitize_section_no_change(section: str) -> None: |
| 33 | + unsanitized = blurb.unsanitize_section(section) |
| 34 | + assert unsanitized == section |
| 35 | + |
| 36 | + |
| 37 | +@pytest.mark.parametrize( |
| 38 | + "section, expected", |
| 39 | + ( |
| 40 | + ("Tools-Demos", "Tools/Demos"), |
| 41 | + ), |
| 42 | +) |
| 43 | +def test_unsanitize_section_changed(section: str, expected: str) -> None: |
| 44 | + unsanitized = blurb.unsanitize_section(section) |
| 45 | + assert unsanitized == expected |
| 46 | + |
| 47 | + |
| 48 | +def test_glob_blurbs_next(fs: FakeFilesystem) -> None: |
| 49 | + # Arrange |
| 50 | + fake_news_entries = ( |
| 51 | + "Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-11111.pC7gnM.rst", |
| 52 | + "Misc/NEWS.d/next/Core and Builtins/2023-03-17-12-09-45.gh-issue-33333.Pf_BI7.rst", |
| 53 | + "Misc/NEWS.d/next/Tools-Demos/2023-03-21-01-27-07.gh-issue-44444.2F1Byz.rst", |
| 54 | + "Misc/NEWS.d/next/C API/2023-03-27-22-09-07.gh-issue-66666.3SN8Bs.rst", |
| 55 | + ) |
| 56 | + fake_readmes = ( |
| 57 | + "Misc/NEWS.d/next/Library/README.rst", |
| 58 | + "Misc/NEWS.d/next/Core and Builtins/README.rst", |
| 59 | + "Misc/NEWS.d/next/Tools-Demos/README.rst", |
| 60 | + "Misc/NEWS.d/next/C API/README.rst", |
| 61 | + ) |
| 62 | + for fn in fake_news_entries + fake_readmes: |
| 63 | + fs.create_file(fn) |
| 64 | + |
| 65 | + # Act |
| 66 | + filenames = blurb.glob_blurbs("next") |
| 67 | + |
| 68 | + # Assert |
| 69 | + assert set(filenames) == set(fake_news_entries) |
| 70 | + |
| 71 | + |
| 72 | +@pytest.mark.parametrize( |
| 73 | + "news_entry, expected_section", |
| 74 | + ( |
| 75 | + ( |
| 76 | + "Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-55555.pC7gnM.rst", |
| 77 | + "Library", |
| 78 | + ), |
| 79 | + ( |
| 80 | + "Misc/NEWS.d/next/Core and Builtins/2023-03-17-12-09-45.gh-issue-33333.Pf_BI7.rst", |
| 81 | + "Core and Builtins", |
| 82 | + ), |
| 83 | + ( |
| 84 | + "Misc/NEWS.d/next/Tools-Demos/2023-03-21-01-27-07.gh-issue-44444.2F1Byz.rst", |
| 85 | + "Tools/Demos", |
| 86 | + ), |
| 87 | + ( |
| 88 | + "Misc/NEWS.d/next/C API/2023-03-27-22-09-07.gh-issue-66666.3SN8Bs.rst", |
| 89 | + "C API", |
| 90 | + ), |
| 91 | + ), |
| 92 | +) |
| 93 | +def test_load_next(news_entry: str, expected_section: str, fs: FakeFilesystem) -> None: |
| 94 | + # Arrange |
| 95 | + fs.create_file(news_entry, contents="testing") |
| 96 | + blurbs = blurb.Blurbs() |
| 97 | + |
| 98 | + # Act |
| 99 | + blurbs.load_next(news_entry) |
| 100 | + |
| 101 | + # Assert |
| 102 | + metadata = blurbs[0][0] |
| 103 | + assert metadata["section"] == expected_section |
| 104 | + |
| 105 | + |
| 106 | +@pytest.mark.parametrize( |
| 107 | + "news_entry, expected_path", |
| 108 | + ( |
| 109 | + ( |
| 110 | + "Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-55555.pC7gnM.rst", |
| 111 | + "root/Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-55555.pC7gnM.rst", |
| 112 | + ), |
| 113 | + ( |
| 114 | + "Misc/NEWS.d/next/Core and Builtins/2023-03-17-12-09-45.gh-issue-33333.Pf_BI7.rst", |
| 115 | + "root/Misc/NEWS.d/next/Core and Builtins/2023-03-17-12-09-45.gh-issue-33333.Pf_BI7.rst", |
| 116 | + ), |
| 117 | + ( |
| 118 | + "Misc/NEWS.d/next/Tools-Demos/2023-03-21-01-27-07.gh-issue-44444.2F1Byz.rst", |
| 119 | + "root/Misc/NEWS.d/next/Tools-Demos/2023-03-21-01-27-07.gh-issue-44444.2F1Byz.rst", |
| 120 | + ), |
| 121 | + ( |
| 122 | + "Misc/NEWS.d/next/C API/2023-03-27-22-09-07.gh-issue-66666.3SN8Bs.rst", |
| 123 | + "root/Misc/NEWS.d/next/C API/2023-03-27-22-09-07.gh-issue-66666.3SN8Bs.rst", |
| 124 | + ), |
| 125 | + ), |
| 126 | +) |
| 127 | +def test_extract_next_filename( |
| 128 | + news_entry: str, expected_path: str, fs: FakeFilesystem |
| 129 | +) -> None: |
| 130 | + # Arrange |
| 131 | + fs.create_file(news_entry, contents="testing") |
| 132 | + blurb.root = "root" |
| 133 | + blurbs = blurb.Blurbs() |
| 134 | + blurbs.load_next(news_entry) |
| 135 | + |
| 136 | + # Act |
| 137 | + path = blurbs._extract_next_filename() |
| 138 | + |
| 139 | + # Assert |
| 140 | + assert path == expected_path |
0 commit comments