Skip to content
Open
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
15 changes: 15 additions & 0 deletions tools/pr-management/tests/stats/test_json_parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

import json

import pytest

from pr_management.stats import dashboard, reference

from .helpers import comment, make_pr
Expand Down Expand Up @@ -78,6 +80,17 @@ def fake_paginated_search(query, search_q, *args, status=None, **kwargs):
monkeypatch.setattr(module, "paginated_search", fake_paginated_search)
monkeypatch.setattr(module, "fetch_codeowners", lambda repo: "")
monkeypatch.setattr(module, "fetch_ready_pr_files", lambda repo, nums: {})
if module is dashboard:
# dashboard.main() ends by publishing to a secret gist through `gh`.
# A unit test must never reach GitHub, so fail loudly if it gets there.
def refuse_publish(*args, **kwargs):
pytest.fail("unit test reached the dashboard gist publish step")

# Guard each entry point independently of main()'s current call order.
monkeypatch.setattr(module, "gist_scope_available", refuse_publish)
monkeypatch.setattr(module, "publish_gist", refuse_publish)
monkeypatch.setattr(module, "read_stats_gist_id", refuse_publish)
monkeypatch.setattr(module, "store_stats_gist_id", refuse_publish)


def _run(monkeypatch, module, out_path):
Expand All @@ -93,6 +106,8 @@ def _run(monkeypatch, module, out_path):
"--out",
str(out_path),
]
if module is dashboard:
argv.append("--no-publish") # reference.py has no publish step and no such flag
monkeypatch.setattr(module.sys, "argv", argv)
module.main()
return json.loads(out_path.with_suffix(".json").read_text())
Expand Down