-
-
Notifications
You must be signed in to change notification settings - Fork 1
[limen GEN-a-organvm-call-function--ontological-test-coverage-0620] Raise test coverage in a-organvm/call-function--ontological #13
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
Open
4444J99
wants to merge
1
commit into
main
Choose a base branch
from
limen/gen-a-organvm-call-function--ontological-test-coverage-0620-d74c
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+163
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| """Tests for the FUNCTIONcalled naming validator.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from tools import validate_naming as naming | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("filename", "expected_layer"), | ||
| [ | ||
| ("core.router.network.c", "core"), | ||
| ("interface.portal.entry.html", "interface"), | ||
| ("logic.agent.analysis.py", "logic"), | ||
| ("application.bridge.mobile.swift", "application"), | ||
| ("bones.router.network.c", "core"), | ||
| ("skins.portal.entry.html", "interface"), | ||
| ("breath.agent.analysis.py", "logic"), | ||
| ("body.bridge.mobile.swift", "application"), | ||
| ], | ||
| ) | ||
| def test_validate_name_accepts_canonical_and_alias_layers( | ||
| filename: str, expected_layer: str | ||
| ) -> None: | ||
| is_valid, message = naming.validate_name(filename) | ||
|
|
||
| assert is_valid | ||
| assert f"layer={expected_layer}" in message | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "filename", | ||
| [ | ||
| "router.network.c", | ||
| "invalid.router.network.c", | ||
| "core.9router.network.c", | ||
| "core.router.9network.c", | ||
| "core.router.network", | ||
| "core.router.network.g7", | ||
| ], | ||
| ) | ||
| def test_validate_name_rejects_malformed_names(filename: str) -> None: | ||
| is_valid, message = naming.validate_name(filename) | ||
|
|
||
| assert not is_valid | ||
| assert "{Layer}.{Role}.{Domain}.{Extension}" in message | ||
|
|
||
|
|
||
| def test_is_excluded_skips_project_scaffolding_and_excluded_dirs(tmp_path: Path) -> None: | ||
| root = tmp_path | ||
|
|
||
| assert naming.is_excluded(root / "README.md", root) | ||
| assert naming.is_excluded(root / "core.router.network.c.meta.json", root) | ||
| assert naming.is_excluded(root / "docs" / "bad-name.md", root) | ||
| assert naming.is_excluded(root / "tests" / "test_anything.py", root) | ||
|
|
||
|
|
||
| def test_is_excluded_skips_python_import_files_inside_layer_packages( | ||
| tmp_path: Path, | ||
| ) -> None: | ||
| core_dir = tmp_path / "core" | ||
| core_dir.mkdir() | ||
| (core_dir / "__init__.py").write_text("") | ||
| source_file = core_dir / "ontology.py" | ||
|
|
||
| assert naming.is_excluded(source_file, tmp_path) | ||
|
|
||
|
|
||
| def test_is_excluded_checks_python_files_outside_layer_packages(tmp_path: Path) -> None: | ||
| logic_dir = tmp_path / "logic" | ||
| logic_dir.mkdir() | ||
| source_file = logic_dir / "worker.py" | ||
|
|
||
| assert not naming.is_excluded(source_file, tmp_path) | ||
|
|
||
|
|
||
| def test_validate_directory_reports_only_non_excluded_invalid_files( | ||
| tmp_path: Path, capsys: pytest.CaptureFixture[str] | ||
| ) -> None: | ||
| (tmp_path / "docs").mkdir() | ||
| (tmp_path / "docs" / "notes.md").write_text("") | ||
| (tmp_path / "core").mkdir() | ||
| (tmp_path / "core" / "__init__.py").write_text("") | ||
| (tmp_path / "core" / "ontology.py").write_text("") | ||
| (tmp_path / "core.router.network.c").write_text("") | ||
| (tmp_path / "bad-name.txt").write_text("") | ||
|
|
||
| errors = naming.validate_directory(str(tmp_path)) | ||
| output = capsys.readouterr().out | ||
|
|
||
| assert errors == [ | ||
| ( | ||
| "bad-name.txt", | ||
| "Does not match pattern {Layer}.{Role}.{Domain}.{Extension}", | ||
| ) | ||
| ] | ||
| assert "bad-name.txt" in output | ||
| assert "1 of 2 files do not follow the naming convention" in output | ||
|
|
||
|
|
||
| def test_validate_directory_verbose_reports_valid_and_skipped_files( | ||
| tmp_path: Path, capsys: pytest.CaptureFixture[str] | ||
| ) -> None: | ||
| (tmp_path / "README.md").write_text("") | ||
| (tmp_path / "core.router.network.c").write_text("") | ||
|
|
||
| errors = naming.validate_directory(str(tmp_path), verbose=True) | ||
| output = capsys.readouterr().out | ||
|
|
||
| assert errors == [] | ||
| assert "Skipped: README.md" in output | ||
| assert "core.router.network.c: Valid: layer=core" in output | ||
| assert "All 1 checked files follow the naming convention" in output | ||
|
|
||
|
|
||
| def test_main_validates_explicit_files( | ||
| monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str] | ||
| ) -> None: | ||
| monkeypatch.setattr( | ||
| sys, | ||
| "argv", | ||
| ["validate_naming.py", "core.router.network.c", "logic.agent.analysis.py"], | ||
| ) | ||
|
|
||
| naming.main() | ||
| output = capsys.readouterr().out | ||
|
|
||
| assert "core.router.network.c: Valid: layer=core" in output | ||
| assert "logic.agent.analysis.py: Valid: layer=logic" in output | ||
|
|
||
|
|
||
| def test_main_exits_nonzero_for_invalid_explicit_file( | ||
| monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str] | ||
| ) -> None: | ||
| monkeypatch.setattr( | ||
| sys, | ||
| "argv", | ||
| ["validate_naming.py", "core.router.network.c", "bad-name.txt"], | ||
| ) | ||
|
|
||
| with pytest.raises(SystemExit) as exc_info: | ||
| naming.main() | ||
|
|
||
| output = capsys.readouterr().out | ||
| assert exc_info.value.code == 1 | ||
| assert "core.router.network.c: Valid: layer=core" in output | ||
| assert "bad-name.txt: Does not match pattern" in output | ||
|
|
||
|
|
||
| def test_main_exits_nonzero_when_root_scan_finds_errors( | ||
| tmp_path: Path, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| (tmp_path / "bad-name.txt").write_text("") | ||
| monkeypatch.setattr(sys, "argv", ["validate_naming.py", "--root", str(tmp_path)]) | ||
|
|
||
| with pytest.raises(SystemExit) as exc_info: | ||
| naming.main() | ||
|
|
||
| assert exc_info.value.code == 1 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This new test module is added under
tests/, but the repository's current validation workflow runspython -m pytest tools/ -vin.github/workflows/validate.ymlline 42, and the contributor docs use the sametools/test command. As a result, these coverage tests are skipped in CI and by the documented test command, so regressions intools/validate_naming.pystill won't be caught unless someone manually runs plainpytest; either move the tests undertools/or update the workflow/docs command to includetests/.Useful? React with 👍 / 👎.