Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions implementations/python/tests/test_identity_cutover_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,5 +443,5 @@ def test_repository_changelog_is_bound_as_generated_release_history() -> None:


def test_identity_cutover_check_is_registered_in_canonical_policy_graph() -> None:
noxfile_source = (REPO_ROOT / "noxfile.py").read_text(encoding="utf-8")
assert '"tools/check_identity_cutover.py"' in noxfile_source
policy_lane_source = (REPO_ROOT / "tools" / "nox_support" / "policy_lanes.py").read_text(encoding="utf-8")
assert '"tools/check_identity_cutover.py"' in policy_lane_source
4 changes: 2 additions & 2 deletions implementations/python/tests/test_project_positioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,5 @@ def test_positioning_check_reports_invalid_mcp_metadata(


def test_positioning_check_is_registered_in_canonical_policy_graph() -> None:
noxfile_source = (REPO_ROOT / "noxfile.py").read_text(encoding="utf-8")
assert '"tools/check_project_positioning.py"' in noxfile_source
policy_lane_source = (REPO_ROOT / "tools" / "nox_support" / "policy_lanes.py").read_text(encoding="utf-8")
assert '"tools/check_project_positioning.py"' in policy_lane_source
6 changes: 3 additions & 3 deletions implementations/python/tests/test_public_project_readiness.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@ def test_python_support_metadata_and_blocking_matrix_are_aligned() -> None:
"RAES_EXPECT_FREE_THREADED": "1",
}

noxfile = (REPO_ROOT / "noxfile.py").read_text(encoding="utf-8")
assert 'assert is_gil_enabled() is False, "interpreter is not free-threaded"' in noxfile
assert 'assert is_gil_enabled() is True, "standard lane selected a free-threaded interpreter"' in noxfile
compatibility_lane = (REPO_ROOT / "tools" / "nox_support" / "test_lanes.py").read_text(encoding="utf-8")
assert 'assert is_gil_enabled() is False, "interpreter is not free-threaded"' in compatibility_lane
assert 'assert is_gil_enabled() is True, "standard lane selected a free-threaded interpreter"' in compatibility_lane
72 changes: 47 additions & 25 deletions implementations/python/tests/test_repo_policy_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ def decorate(function: object) -> object:
return module


def _patch_nox_globals(
monkeypatch: pytest.MonkeyPatch,
noxfile: types.ModuleType,
name: str,
value: object,
) -> None:
"""Patch a noxfile global everywhere the split support modules read it."""

modules = [noxfile] + [
sys.modules[f"tools.nox_support.{module_name}"]
for module_name in ("config", "runner", "policy_lanes", "test_lanes", "graph")
if f"tools.nox_support.{module_name}" in sys.modules
]
for module in modules:
if hasattr(module, name):
monkeypatch.setattr(module, name, value)


def test_parallel_coverage_command_is_capped_and_worker_safe(
monkeypatch: pytest.MonkeyPatch,
tmp_path: Path,
Expand Down Expand Up @@ -124,7 +142,7 @@ def chdir(self, _path: Path):
assert kwargs["env"] == {"COVERAGE_FILE": str(coverage_file)}

session.commands.clear()
monkeypatch.setattr(noxfile, "_enforce_line_coverage", lambda _path: 90.0)
_patch_nox_globals(monkeypatch, noxfile, "_enforce_line_coverage", lambda _path: 90.0)
noxfile._run_pytest(
session,
"-m",
Expand Down Expand Up @@ -300,7 +318,7 @@ def chdir(self, _path: Path):
return nullcontext()

session = FakeSession()
monkeypatch.setattr(noxfile, "_enforce_line_coverage", lambda _path: 90.0)
_patch_nox_globals(monkeypatch, noxfile, "_enforce_line_coverage", lambda _path: 90.0)
noxfile._finalize_parallel_coverage(session, tmp_path)

coverage_commands = [
Expand Down Expand Up @@ -361,8 +379,9 @@ def fake_run(session: FakeSession, *command: str, **_kwargs: object) -> None:
monkeypatch.setenv(noxfile.EXPECTED_PYTHON_ENV, "3.14")
monkeypatch.setenv("UV_PYTHON", "cpython-3.14")
monkeypatch.setenv(noxfile.EXPECT_FREE_THREADED_ENV, "1")
monkeypatch.setattr(noxfile, "_run", fake_run)
monkeypatch.setattr(
_patch_nox_globals(monkeypatch, noxfile, "_run", fake_run)
_patch_nox_globals(
monkeypatch,
noxfile,
"_run_pytest",
lambda _session, *args, **_kwargs: pytest_calls.append(tuple(args)),
Expand Down Expand Up @@ -438,12 +457,15 @@ def test_python_compatibility_and_osv_session_wrappers_always_summarize(
calls: list[str] = []
logs: list[str] = []
session = types.SimpleNamespace(log=logs.append, posargs=[])
monkeypatch.setattr(
_patch_nox_globals(
monkeypatch,
noxfile,
"_run_python_compatibility",
lambda _session, _reporter: calls.append("python"),
)
monkeypatch.setattr(noxfile, "_run_osv_scan", lambda _session, _reporter, **_kwargs: calls.append("osv"))
_patch_nox_globals(
monkeypatch, noxfile, "_run_osv_scan", lambda _session, _reporter, **_kwargs: calls.append("osv")
)

noxfile.python_compatibility(session)
noxfile.osv_scan(session)
Expand Down Expand Up @@ -518,14 +540,14 @@ def test_make_policy_skips_only_requirement_governance_without_a_uid() -> None:
def test_hook_policy_context_skips_only_requirement_free_branches(monkeypatch: pytest.MonkeyPatch) -> None:
noxfile = load_noxfile_with_fake_nox(monkeypatch)
monkeypatch.delenv("RAES_REQUIREMENT_UID", raising=False)
monkeypatch.setattr(noxfile, "_git_lines", lambda *_args: ["1104-minimal-coverage-policy"])
_patch_nox_globals(monkeypatch, noxfile, "_git_lines", lambda *_args: ["1104-minimal-coverage-policy"])
assert noxfile._requirement_aware_policy_args("--staged") == ["--staged", "--skip-requirement"]

monkeypatch.setattr(noxfile, "_git_lines", lambda *_args: ["1104-ASR-505-coverage-policy"])
_patch_nox_globals(monkeypatch, noxfile, "_git_lines", lambda *_args: ["1104-ASR-505-coverage-policy"])
assert noxfile._requirement_aware_policy_args("--staged") == ["--staged"]

monkeypatch.setenv("RAES_REQUIREMENT_UID", "ASR-505")
monkeypatch.setattr(noxfile, "_git_lines", lambda *_args: ["1104-minimal-coverage-policy"])
_patch_nox_globals(monkeypatch, noxfile, "_git_lines", lambda *_args: ["1104-minimal-coverage-policy"])
assert noxfile._requirement_aware_policy_args("--staged") == ["--staged"]


Expand All @@ -545,12 +567,12 @@ def run(self, *args: str, **_kwargs: Any) -> None:

fake_vale = tmp_path / "vale"
fake_vale.write_text("", encoding="utf-8")
monkeypatch.setattr(noxfile, "ensure_vale", lambda _repo_root: fake_vale)
monkeypatch.setattr(noxfile, "REPO_ROOT", tmp_path)
monkeypatch.setattr(noxfile, "PROJECT_ROOT", tmp_path / "implementations" / "python")
_patch_nox_globals(monkeypatch, noxfile, "ensure_vale", lambda _repo_root: fake_vale)
_patch_nox_globals(monkeypatch, noxfile, "REPO_ROOT", tmp_path)
_patch_nox_globals(monkeypatch, noxfile, "PROJECT_ROOT", tmp_path / "implementations" / "python")
public_root = tmp_path / "docs" / "public"
monkeypatch.setattr(noxfile, "PUBLIC_DOCS_ROOT", public_root)
monkeypatch.setattr(noxfile, "DOCS_BUILD_ROOT", tmp_path / "docs" / "_build")
_patch_nox_globals(monkeypatch, noxfile, "PUBLIC_DOCS_ROOT", public_root)
_patch_nox_globals(monkeypatch, noxfile, "DOCS_BUILD_ROOT", tmp_path / "docs" / "_build")
reporter = noxfile.SessionReporter(FakeSession(), "docs")

noxfile._run_docs(reporter.session, reporter)
Expand Down Expand Up @@ -598,11 +620,11 @@ def run(self, *args: str, **_kwargs: Any) -> None:

fake_vale = tmp_path / "vale"
fake_vale.write_text("", encoding="utf-8")
monkeypatch.setattr(noxfile, "ensure_vale", lambda _repo_root: fake_vale)
monkeypatch.setattr(noxfile, "REPO_ROOT", tmp_path)
monkeypatch.setattr(noxfile, "PROJECT_ROOT", tmp_path / "implementations" / "python")
monkeypatch.setattr(noxfile, "PUBLIC_DOCS_ROOT", tmp_path / "docs" / "public")
monkeypatch.setattr(noxfile, "DOCS_BUILD_ROOT", tmp_path / "docs" / "_build")
_patch_nox_globals(monkeypatch, noxfile, "ensure_vale", lambda _repo_root: fake_vale)
_patch_nox_globals(monkeypatch, noxfile, "REPO_ROOT", tmp_path)
_patch_nox_globals(monkeypatch, noxfile, "PROJECT_ROOT", tmp_path / "implementations" / "python")
_patch_nox_globals(monkeypatch, noxfile, "PUBLIC_DOCS_ROOT", tmp_path / "docs" / "public")
_patch_nox_globals(monkeypatch, noxfile, "DOCS_BUILD_ROOT", tmp_path / "docs" / "_build")
reporter = noxfile.SessionReporter(FakeSession(), "docs-local")

noxfile._run_docs(reporter.session, reporter, include_external_links=False)
Expand Down Expand Up @@ -703,7 +725,7 @@ def fake_changed_paths(*, staged: bool = False, base_rev: str | None = None) ->
calls.append({"staged": staged, "base_rev": base_rev})
return ["noxfile.py"]

monkeypatch.setattr(noxfile, "_changed_paths", fake_changed_paths)
_patch_nox_globals(monkeypatch, noxfile, "_changed_paths", fake_changed_paths)

skip_selection = noxfile._parse_hygiene_posargs(
["--base-rev", "origin/dev", "--skip-requirement"],
Expand Down Expand Up @@ -2942,18 +2964,18 @@ def log(self, _message: str) -> None:
lockfile.write_text("", encoding="utf-8")
report = lockfile.with_name("osv-scanner-report.json")
scanner_binary = tmp_path / "osv-scanner"
monkeypatch.setattr(noxfile, "REPO_ROOT", tmp_path)
monkeypatch.setattr(noxfile, "OSV_LOCKFILE_PATH", lockfile)
monkeypatch.setattr(noxfile, "OSV_REPORT_PATH", report)
monkeypatch.setattr(noxfile, "ensure_osv_scanner", lambda _repo_root: scanner_binary)
_patch_nox_globals(monkeypatch, noxfile, "REPO_ROOT", tmp_path)
_patch_nox_globals(monkeypatch, noxfile, "OSV_LOCKFILE_PATH", lockfile)
_patch_nox_globals(monkeypatch, noxfile, "OSV_REPORT_PATH", report)
_patch_nox_globals(monkeypatch, noxfile, "ensure_osv_scanner", lambda _repo_root: scanner_binary)

def fake_run_osv_scanner(actual_lockfile: Path, actual_report: Path, *, binary: Path) -> int:
assert actual_lockfile == lockfile
assert actual_report == report
assert binary == scanner_binary
return exit_code

monkeypatch.setattr(noxfile, "run_osv_scanner", fake_run_osv_scanner)
_patch_nox_globals(monkeypatch, noxfile, "run_osv_scanner", fake_run_osv_scanner)
noxfile.osv_scan(FakeSession())


Expand Down
Loading