Skip to content

Commit c6ecb5f

Browse files
committed
fix(tests): deflake unreadable-source CLI check by asserting JSON source_io_skipped contract instead of unstable console warning text
1 parent 623f6d0 commit c6ecb5f

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<a href="https://pypi.org/project/codeclone/"><img src="https://img.shields.io/pypi/v/codeclone.svg?style=flat-square" alt="PyPI"></a>
1111
<a href="https://pypi.org/project/codeclone/"><img src="https://img.shields.io/pypi/dm/codeclone.svg?style=flat-square" alt="Downloads"></a>
1212
<a href="https://github.com/orenlab/codeclone/actions/workflows/tests.yml"><img src="https://github.com/orenlab/codeclone/actions/workflows/tests.yml/badge.svg?branch=main&style=flat-square" alt="Tests"></a>
13+
<a href="https://github.com/orenlab/codeclone/actions/workflows/benchmark.yml"><img src="https://github.com/orenlab/codeclone/actions/workflows/benchmark.yml/badge.svg?style=flat-square" alt="Benchmark"></a>
1314
<a href="https://pypi.org/project/codeclone/"><img src="https://img.shields.io/pypi/pyversions/codeclone.svg?style=flat-square" alt="Python"></a>
1415
<img src="https://img.shields.io/badge/codeclone-B-green?style=flat-square" alt="CodeClone Quality">
1516
<a href="LICENSE"><img src="https://img.shields.io/pypi/l/codeclone.svg?style=flat-square" alt="License"></a>

tests/test_cli_inprocess.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2922,6 +2922,7 @@ def test_cli_unreadable_source_normal_mode_warns_and_continues(
29222922
src = tmp_path / "a.py"
29232923
src.write_text("def f():\n return 1\n", "utf-8")
29242924
cache_path = tmp_path / "cache.json"
2925+
json_out = tmp_path / "report.json"
29252926

29262927
def _source_read_error(
29272928
fp: str, *_args: object, **_kwargs: object
@@ -2932,13 +2933,21 @@ def _source_read_error(
29322933
_patch_parallel(monkeypatch)
29332934
_run_main(
29342935
monkeypatch,
2935-
[str(tmp_path), "--no-progress", "--cache-path", str(cache_path)],
2936+
[
2937+
str(tmp_path),
2938+
"--no-progress",
2939+
"--cache-path",
2940+
str(cache_path),
2941+
"--json",
2942+
str(json_out),
2943+
],
29362944
)
29372945
captured = capsys.readouterr()
29382946
combined = captured.out + captured.err
2939-
assert "Cannot read file" in combined
29402947
assert "CONTRACT ERROR:" not in combined
29412948
assert _summary_metric(captured.out, "Files skipped") == 1
2949+
payload = json.loads(json_out.read_text("utf-8"))
2950+
assert _report_inventory_files(payload)["source_io_skipped"] == 1
29422951

29432952

29442953
def test_cli_unreadable_source_fails_in_ci_with_contract_error(

0 commit comments

Comments
 (0)