|
| 1 | +import tomllib |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +PROJECT_ROOT = Path(__file__).resolve().parents[1] |
| 5 | +LICENSE_FILE = PROJECT_ROOT / "LICENSE" |
| 6 | +PYPROJECT = PROJECT_ROOT / "pyproject.toml" |
| 7 | +README = PROJECT_ROOT / "README.md" |
| 8 | +CHANGELOG = PROJECT_ROOT / "CHANGELOG.md" |
| 9 | +RELEASE_CHECKLIST = ( |
| 10 | + PROJECT_ROOT |
| 11 | + / "docs" |
| 12 | + / "release_checklist.md" |
| 13 | +) |
| 14 | +RELEASE_NOTES = ( |
| 15 | + PROJECT_ROOT |
| 16 | + / "docs" |
| 17 | + / "releases" |
| 18 | + / "v0.1.0.md" |
| 19 | +) |
| 20 | + |
| 21 | + |
| 22 | +EXPECTED_LICENSE = """MIT License |
| 23 | +
|
| 24 | +Copyright (c) 2026 Nafiz Noyon |
| 25 | +
|
| 26 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 27 | +of this software and associated documentation files (the "Software"), to deal |
| 28 | +in the Software without restriction, including without limitation the rights |
| 29 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 30 | +copies of the Software, and to permit persons to whom the Software is |
| 31 | +furnished to do so, subject to the following conditions: |
| 32 | +
|
| 33 | +The above copyright notice and this permission notice shall be included in all |
| 34 | +copies or substantial portions of the Software. |
| 35 | +
|
| 36 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 37 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 38 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 39 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 40 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 41 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 42 | +SOFTWARE. |
| 43 | +""" |
| 44 | + |
| 45 | + |
| 46 | +def load_metadata() -> dict: |
| 47 | + return tomllib.loads( |
| 48 | + PYPROJECT.read_text(encoding="utf-8") |
| 49 | + ) |
| 50 | + |
| 51 | + |
| 52 | +def test_license_file_matches_mit_contract() -> None: |
| 53 | + assert LICENSE_FILE.is_file() |
| 54 | + assert ( |
| 55 | + LICENSE_FILE.read_text(encoding="utf-8") |
| 56 | + == EXPECTED_LICENSE |
| 57 | + ) |
| 58 | + |
| 59 | + |
| 60 | +def test_package_declares_pep639_mit_metadata() -> None: |
| 61 | + project = load_metadata()["project"] |
| 62 | + |
| 63 | + assert project["license"] == "MIT" |
| 64 | + assert project["license-files"] == ["LICENSE"] |
| 65 | + assert not any( |
| 66 | + classifier.startswith("License ::") |
| 67 | + for classifier in project["classifiers"] |
| 68 | + ) |
| 69 | + |
| 70 | + |
| 71 | +def test_readme_exposes_license_and_external_terms() -> None: |
| 72 | + text = README.read_text(encoding="utf-8") |
| 73 | + |
| 74 | + assert "- Repository license: MIT" in text |
| 75 | + assert "## License" in text |
| 76 | + assert "[MIT License](LICENSE)" in text |
| 77 | + assert "third-party resources" in text |
| 78 | + assert "license selection: pending" not in text.lower() |
| 79 | + |
| 80 | + |
| 81 | +def test_changelog_records_resolved_license_work() -> None: |
| 82 | + text = CHANGELOG.read_text(encoding="utf-8") |
| 83 | + |
| 84 | + assert "MIT License and SPDX package metadata" in text |
| 85 | + assert "Repository license selection and addition" not in text |
| 86 | + assert ( |
| 87 | + "repository license has not yet been selected" |
| 88 | + not in text.lower() |
| 89 | + ) |
| 90 | + |
| 91 | + |
| 92 | +def test_release_documents_resolve_license_blocker() -> None: |
| 93 | + checklist = RELEASE_CHECKLIST.read_text(encoding="utf-8") |
| 94 | + notes = RELEASE_NOTES.read_text(encoding="utf-8") |
| 95 | + |
| 96 | + assert "- [x] Select and add the MIT License" in checklist |
| 97 | + assert "SPDX license expression `MIT`" in checklist |
| 98 | + assert "Built distributions include the `LICENSE` file" in checklist |
| 99 | + |
| 100 | + assert "## License" in notes |
| 101 | + assert "distributed under the MIT License" in notes |
| 102 | + assert "Select and add a repository license" not in notes |
0 commit comments