-
Notifications
You must be signed in to change notification settings - Fork 1
adding the API contracts #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c0cede1
59e5a79
ce855f9
9bd615e
002fc23
c784436
c3aadd2
1320819
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,4 +172,5 @@ cython_debug/ | |
|
|
||
| # PyPI configuration file | ||
| .pypirc | ||
| data/* | ||
| testing.ipynb | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -51,6 +51,25 @@ You can run pytest on your work using the following example: | |||||
| % uv run pytest | ||||||
| ``` | ||||||
|
|
||||||
| ### Linting, testing, coverage, and updating coverage badges | ||||||
|
|
||||||
| We apply a custom script to update our coverage badge in the README during our CI workflow. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome! Thanks for spelling this out. |
||||||
| When running `scripts/update_coverage_badge.py` the script will parse the `coverage.xml` file generated from pytest and update the badge in the README with the new coverage percentage. | ||||||
| When running `just all` locally, the coverage badge will not be updated since it is intended to be updated as part of the CI workflow. | ||||||
|
|
||||||
| ``` | ||||||
| just all | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider providing an indication of "which" "all" we're meaning when we call this from |
||||||
| ``` | ||||||
|
|
||||||
| the coverage badge will be automatically updated as part of the workflow. | ||||||
| If you want to update the covererage then just run: | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| ``` | ||||||
| just coverage | ||||||
| ``` | ||||||
|
|
||||||
| This will run the tests and update the coverage badge in the README. | ||||||
|
|
||||||
| ## Making changes to this repository | ||||||
|
|
||||||
| We welcome anyone to use [GitHub issues](https://docs.github.com/en/issues/tracking-your-work-with-issues/about-issues) (requires a GitHub login) or create [pull requests](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests) (to directly make changes within this repository) to modify content found within this repository. | ||||||
|
|
||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import importlib.util | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| # Load the module relative to this test file | ||
| _spec = importlib.util.spec_from_file_location( | ||
| "update_coverage_badge", Path(__file__).parent / "update_coverage_badge.py" | ||
| ) | ||
| mod = importlib.util.module_from_spec(_spec) | ||
| _spec.loader.exec_module(mod) | ||
|
|
||
|
|
||
| def test_replaces_existing_badge(tmp_path: Path) -> None: | ||
| readme = tmp_path / "README.md" | ||
| original = ( | ||
| "# Project\n\n" | ||
| "[](#quality-gates)\n\n" | ||
| "Some text\n" | ||
| ) | ||
| readme.write_text(original, encoding="utf-8") | ||
|
|
||
| changed = mod.update_readme_badge(readme, 85) | ||
| assert changed is True | ||
|
|
||
| updated = readme.read_text(encoding="utf-8") | ||
| assert "coverage-85%25-green" in updated | ||
| assert updated.count("[![Coverage]") == 1 | ||
| assert "coverage-42%25-red" not in updated | ||
|
|
||
|
|
||
| def test_inserts_badge_when_missing(tmp_path: Path) -> None: | ||
| readme = tmp_path / "README.md" | ||
| original = "# Project\nDescription line\n" | ||
| readme.write_text(original, encoding="utf-8") | ||
|
|
||
| changed = mod.update_readme_badge(readme, 60) | ||
| assert changed is True | ||
|
|
||
| updated = readme.read_text(encoding="utf-8") | ||
| lines = updated.splitlines() | ||
| # After insertion: title at 0, blank line at 1, badge at 2 | ||
| assert lines[0] == "# Project" | ||
| assert lines[1] == "" | ||
| assert lines[2].startswith("[![Coverage]") | ||
| assert "coverage-60%25-yellow" in lines[2] | ||
|
|
||
|
|
||
| def test_preserves_trailing_newline_on_insert(tmp_path: Path) -> None: | ||
| readme = tmp_path / "README.md" | ||
| original = "# Project\nDescription line\n" # ends with newline | ||
| readme.write_text(original, encoding="utf-8") | ||
|
|
||
| changed = mod.update_readme_badge(readme, 70) | ||
| assert changed is True | ||
|
|
||
| updated = readme.read_text(encoding="utf-8") | ||
| assert updated.endswith("\n") | ||
|
|
||
|
|
||
| def test_no_change_returns_false_when_badge_already_exact(tmp_path: Path) -> None: | ||
| readme = tmp_path / "README.md" | ||
| # percent 75 -> color "yellowgreen" (per thresholds) | ||
| badge = "[](#quality-gates)" | ||
| original = f"# Project\n\n{badge}\n\nMore\n" | ||
| readme.write_text(original, encoding="utf-8") | ||
|
|
||
| changed = mod.update_readme_badge(readme, 75) | ||
| assert changed is False | ||
| assert readme.read_text(encoding="utf-8") == original | ||
|
|
||
|
|
||
| def test_empty_readme_raises_value_error(tmp_path: Path) -> None: | ||
| readme = tmp_path / "README.md" | ||
| readme.write_text("", encoding="utf-8") | ||
| with pytest.raises(ValueError): | ||
| mod.update_readme_badge(readme, 50) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this dir be incorporated into the tests suite?