Skip to content

Commit a9cfee6

Browse files
openqa-bats-review: Add --dry-run option
1 parent 0596047 commit a9cfee6

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

openqa-bats-review

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def resolve_clone_chain(openqa_host: str, job_id: int) -> list[int]:
136136
return chain
137137

138138

139-
def main(url: str) -> None:
139+
def main(url: str, dry_run: bool = False) -> None:
140140
"""
141141
Main function
142142
"""
@@ -197,21 +197,23 @@ def main(url: str) -> None:
197197
common_failures: set[str] = set.intersection(*all_failures)
198198

199199
if not common_failures:
200-
log.info("No common failures across clone chain. Tagging as PASSED.")
201-
# TODO: Tag job as passed
200+
if not dry_run:
201+
log.info("No common failures across clone chain. Would tag as PASSED.")
202+
# TODO: Tag job as passed
203+
else:
204+
log.info("No common failures across clone chain. Tagging as PASSED.")
202205
else:
203206
log.info("Common failures found across clone chain: %s", " ".join(common_failures))
204207
sys.exit(1)
205208

206209

207210
def parse_args() -> argparse.Namespace:
208-
"""
209-
Parse args
210-
"""
211211
parser = argparse.ArgumentParser()
212+
parser.add_argument("-n", "--dry-run", action="store_true", help="dry run")
212213
parser.add_argument("url", help="URL to openQA jobs")
213214
return parser.parse_args()
214215

215216

216217
if __name__ == "__main__":
217-
main(parse_args().url)
218+
args = parse_args()
219+
main(args.url, dry_run=args.dry_run)

tests/openqa_bats_review_test.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def mock_job_response(url):
6161
mock_get_job.side_effect = mock_job_response
6262

6363
with pytest.raises(KeyError):
64-
main("http://openqa.example.com/tests/123")
64+
main("http://openqa.example.com/tests/123", dry_run=True)
6565

6666

6767
class TestRegexPattern:
@@ -381,7 +381,7 @@ def test_main_no_clones(self, mock_log, mock_resolve_clone_chain):
381381
mock_resolve_clone_chain.return_value = [123]
382382

383383
with pytest.raises(SystemExit) as exc_info:
384-
main("http://openqa.example.com/tests/123")
384+
main("http://openqa.example.com/tests/123", dry_run=True)
385385

386386
assert exc_info.value.code == 0
387387
mock_log.info.assert_called_with("No clones. Exiting")
@@ -412,7 +412,7 @@ def mock_job_response(url):
412412
{"file1:test3", "file1:test4"}, # Job 122 failures (different)
413413
]
414414

415-
main("http://openqa.example.com/tests/123")
415+
main("http://openqa.example.com/tests/123", dry_run=True)
416416

417417
mock_log.info.assert_any_call("Processing clone chain: %s", "123 -> 122")
418418
mock_log.info.assert_any_call(
@@ -436,7 +436,7 @@ def mock_job_response(url):
436436
mock_get_job.side_effect = mock_job_response
437437

438438
with pytest.raises(SystemExit) as exc_info:
439-
main("http://openqa.example.com/tests/123")
439+
main("http://openqa.example.com/tests/123", dry_run=True)
440440

441441
assert exc_info.value.code == 0
442442
mock_log.info.assert_any_call("Job %s has no TAP logs, skipping", 123)
@@ -465,7 +465,7 @@ def mock_job_response(url):
465465
mock_get_job.side_effect = mock_job_response
466466

467467
with pytest.raises(SystemExit) as exc_info:
468-
main("http://openqa.example.com/tests/123")
468+
main("http://openqa.example.com/tests/123", dry_run=True)
469469

470470
assert exc_info.value.code == 0
471471
mock_log.info.assert_any_call("Job %s has only %d TAP logs, skipping", 123, 2)
@@ -512,7 +512,7 @@ def mock_job_response(url):
512512
{"file1:test2"}, # Job 122 failures (different)
513513
]
514514

515-
main("http://openqa.example.com/tests/123")
515+
main("http://openqa.example.com/tests/123", dry_run=True)
516516

517517
mock_log.info.assert_any_call(
518518
"No common failures across clone chain. Tagging as PASSED."
@@ -535,7 +535,7 @@ def mock_job_response(url):
535535
mock_get_job.side_effect = mock_job_response
536536

537537
with pytest.raises(SystemExit) as exc_info:
538-
main("http://openqa.example.com/tests/123")
538+
main("http://openqa.example.com/tests/123", dry_run=True)
539539

540540
assert exc_info.value.code == 0
541541
mock_log.info.assert_any_call("No logs found in chain. Exiting")
@@ -564,7 +564,7 @@ def mock_job_response(url):
564564
{"file1:test2"}, # Job 122 failures (different)
565565
]
566566

567-
main("http://openqa.example.com/tests/123")
567+
main("http://openqa.example.com/tests/123", dry_run=True)
568568

569569
mock_log.info.assert_any_call(
570570
"No common failures across clone chain. Tagging as PASSED."
@@ -576,7 +576,7 @@ def test_main_url_normalization(self):
576576
mock_resolve_clone_chain.return_value = [123]
577577

578578
with pytest.raises(SystemExit):
579-
main("openqa.example.com/tests/123") # No scheme
579+
main("openqa.example.com/tests/123", dry_run=True) # No scheme
580580

581581
# Verify that the URL was normalized to include https://
582582
mock_resolve_clone_chain.assert_called_with(
@@ -649,7 +649,7 @@ def mock_get(url, **kwargs):
649649
mock_session.get.side_effect = mock_get
650650

651651
with patch("bats_review.log") as mock_log:
652-
main("http://openqa.example.com/tests/123")
652+
main("http://openqa.example.com/tests/123", dry_run=True)
653653
mock_log.info.assert_any_call(
654654
"No common failures across clone chain. Tagging as PASSED."
655655
)

0 commit comments

Comments
 (0)