88import respx
99import yaml
1010
11- from mergify_cli .ci .git_refs import detector
1211from mergify_cli .ci .scopes import cli
1312from mergify_cli .ci .scopes import config
1413from mergify_cli .ci .scopes import exceptions
@@ -337,13 +336,11 @@ def test_maybe_write_github_outputs_no_env(
337336 cli .maybe_write_github_outputs (["backend" ], {"backend" })
338337
339338
340- @mock .patch ("mergify_cli.ci.git_refs.detector.detect" )
341339@mock .patch ("mergify_cli.ci.scopes.changed_files.git_changed_files" )
342340@mock .patch ("mergify_cli.ci.scopes.cli.maybe_write_github_outputs" )
343341def test_detect_with_matches (
344342 mock_github_outputs : mock .Mock ,
345343 mock_git_changed : mock .Mock ,
346- mock_detect_base : mock .Mock ,
347344 tmp_path : pathlib .Path ,
348345) -> None :
349346 # Setup config file
@@ -361,19 +358,18 @@ def test_detect_with_matches(
361358 config_file .write_text (yaml .dump (config_data ))
362359
363360 # Setup mocks
364- mock_detect_base .return_value = detector .References (
365- "old" ,
366- "new" ,
367- is_merge_queue = True ,
368- )
369361 mock_git_changed .return_value = ["api/models.py" , "other.txt" ]
370362
371363 # Capture output
372364 with mock .patch ("click.echo" ) as mock_echo :
373- result = cli .detect (str (config_file ))
365+ result = cli .detect (
366+ str (config_file ),
367+ base = "old" ,
368+ head = "new" ,
369+ is_merge_queue = True ,
370+ )
374371
375372 # Verify calls
376- mock_detect_base .assert_called_once ()
377373 mock_git_changed .assert_called_once_with ("old" , "new" )
378374 mock_github_outputs .assert_called_once ()
379375
@@ -385,16 +381,12 @@ def test_detect_with_matches(
385381 assert "- backend" in calls
386382 assert "- merge-queue" in calls
387383
388- assert result .base_ref == "old"
389- assert result .head_ref == "new"
390384 assert result .scopes == {"backend" , "merge-queue" }
391385
392386
393- @mock .patch ("mergify_cli.ci.git_refs.detector.detect" )
394387@mock .patch ("mergify_cli.ci.scopes.cli.maybe_write_github_outputs" )
395388def test_detect_manual (
396389 _ : mock .Mock ,
397- mock_detect_base : mock .Mock ,
398390 tmp_path : pathlib .Path ,
399391) -> None :
400392 # Setup config file
@@ -404,28 +396,24 @@ def test_detect_manual(
404396 config_file = tmp_path / ".mergify-ci.yml"
405397 config_file .write_text (yaml .dump (config_data ))
406398
407- # Setup mocks
408- mock_detect_base .return_value = detector .References (
409- "old" ,
410- "new" ,
411- is_merge_queue = False ,
412- )
413-
414399 # Capture output
415400 with pytest .raises (
416401 exceptions .ScopesError ,
417402 match = "source `manual` has been set, scopes must be sent with `scopes-send` or API" ,
418403 ):
419- cli .detect (str (config_file ))
404+ cli .detect (
405+ str (config_file ),
406+ base = "old" ,
407+ head = "new" ,
408+ is_merge_queue = False ,
409+ )
420410
421411
422- @mock .patch ("mergify_cli.ci.git_refs.detector.detect" )
423412@mock .patch ("mergify_cli.ci.scopes.changed_files.git_changed_files" )
424413@mock .patch ("mergify_cli.ci.scopes.cli.maybe_write_github_outputs" )
425414def test_detect_no_matches (
426415 _ : mock .Mock ,
427416 mock_git_changed : mock .Mock ,
428- mock_detect_base : mock .Mock ,
429417 tmp_path : pathlib .Path ,
430418) -> None :
431419 # Setup config file
@@ -436,32 +424,28 @@ def test_detect_no_matches(
436424 config_file .write_text (yaml .dump (config_data ))
437425
438426 # Setup mocks
439- mock_detect_base .return_value = detector .References (
440- "old" ,
441- "new" ,
442- is_merge_queue = False ,
443- )
444427 mock_git_changed .return_value = ["other.txt" ]
445428
446429 # Capture output
447430 with mock .patch ("click.echo" ) as mock_echo :
448- result = cli .detect (str (config_file ))
431+ result = cli .detect (
432+ str (config_file ),
433+ base = "old" ,
434+ head = "new" ,
435+ is_merge_queue = False ,
436+ )
449437
450438 # Verify output
451439 calls = [call .args [0 ] for call in mock_echo .call_args_list ]
452440 assert "Base: old" in calls
453441 assert "Head: new" in calls
454442 assert "No scopes matched." in calls
455443 assert result .scopes == set ()
456- assert result .base_ref == "old"
457- assert result .head_ref == "new"
458444
459445
460- @mock .patch ("mergify_cli.ci.git_refs.detector.detect" )
461446@mock .patch ("mergify_cli.ci.scopes.changed_files.git_changed_files" )
462447def test_detect_debug_output (
463448 mock_git_changed : mock .Mock ,
464- mock_detect_base : mock .Mock ,
465449 tmp_path : pathlib .Path ,
466450 monkeypatch : pytest .MonkeyPatch ,
467451) -> None :
@@ -476,23 +460,21 @@ def test_detect_debug_output(
476460 config_file .write_text (yaml .dump (config_data ))
477461
478462 # Setup mocks
479- mock_detect_base .return_value = detector .References (
480- "main" ,
481- "HEAD" ,
482- is_merge_queue = False ,
483- )
484463 mock_git_changed .return_value = ["api/models.py" , "api/views.py" ]
485464
486465 # Capture output
487466 with mock .patch ("click.echo" ) as mock_echo :
488- result = cli .detect (str (config_file ))
489-
467+ result = cli .detect (
468+ str (config_file ),
469+ base = "old" ,
470+ head = "new" ,
471+ is_merge_queue = False ,
472+ )
490473 # Verify debug output includes file details
491474 calls = [call .args [0 ] for call in mock_echo .call_args_list ]
492475 assert any (" api/models.py" in call for call in calls )
493476 assert any (" api/views.py" in call for call in calls )
494477
495- assert result .base_ref == "main"
496478 assert result .scopes == {"backend" }
497479
498480
@@ -535,12 +517,9 @@ async def test_upload_scopes(respx_mock: respx.MockRouter) -> None:
535517def test_dump (tmp_path : pathlib .Path ) -> None :
536518 config_file = tmp_path / "scopes.json"
537519 saved = cli .DetectedScope (
538- base_ref = "base" ,
539- head_ref = "head" ,
540520 scopes = {"backend" , "merge-queue" },
541521 )
542522 saved .save_to_file (str (config_file ))
543523
544524 loaded = cli .DetectedScope .load_from_file (str (config_file ))
545525 assert loaded .scopes == saved .scopes
546- assert loaded .base_ref == saved .base_ref
0 commit comments