@@ -121,14 +121,14 @@ def test_java_version_parse_missing() -> None:
121121class FriendOfSwitchInstaller (SwitchInstaller ):
122122 """A friend class to access protected methods for testing purposes."""
123123
124- def has_valid_job (self , install_state : Any ) -> bool :
125- return self ._has_valid_job (install_state )
124+ def get_existing_job_id (self , install_state : Any ) -> str | None :
125+ return self ._get_existing_job_id (install_state )
126126
127- def create_or_update_switch_job (self , install_state : Any ) -> str :
128- return self ._create_or_update_switch_job (install_state )
127+ def create_or_update_switch_job (self , job_id : str | None ) -> str :
128+ return self ._create_or_update_switch_job (job_id )
129129
130- def get_switch_parameters_from_config (self ) -> dict :
131- return self ._get_switch_parameters_from_config ()
130+ def get_switch_job_parameters (self ) -> list :
131+ return self ._get_switch_job_parameters ()
132132
133133 def prompt_for_switch_resources (self ) -> tuple [str , str , str ]:
134134 return self ._prompt_for_switch_resources ()
@@ -343,20 +343,20 @@ def test_get_configured_resources(
343343 @pytest .mark .parametrize (
344344 ("jobs_state" , "get_side_effect" , "expected" ),
345345 (
346- pytest .param ({}, None , False , id = "no_job_in_state" ),
347- pytest .param ({"Switch" : "12345" }, None , True , id = "valid_job_exists" ),
348- pytest .param ({"Switch" : "99999" }, NotFound ("Job not found" ), False , id = "job_not_found" ),
349- pytest .param ({"Switch" : "invalid" }, ValueError ("Invalid job ID" ), False , id = "invalid_job_id" ),
346+ pytest .param ({}, None , None , id = "no_job_in_state" ),
347+ pytest .param ({"Switch" : "12345" }, None , "12345" , id = "valid_job_exists" ),
348+ pytest .param ({"Switch" : "99999" }, NotFound ("Job not found" ), None , id = "job_not_found" ),
349+ pytest .param ({"Switch" : "invalid" }, ValueError ("Invalid job ID" ), None , id = "invalid_job_id" ),
350350 ),
351351 )
352- def test_has_valid_job (
352+ def test_get_existing_job_id (
353353 self ,
354354 jobs_state : dict ,
355355 get_side_effect : Exception | None ,
356- expected : bool ,
356+ expected : str | None ,
357357 tmp_path : Path ,
358358 ) -> None :
359- """Test _has_valid_job checks job validity in workspace ."""
359+ """Test _get_existing_job_id returns job_id if valid, None otherwise ."""
360360 install_state = Mock ()
361361 install_state .jobs = jobs_state
362362
@@ -367,19 +367,19 @@ def test_has_valid_job(
367367 # Use friend class to access protected method
368368 repository = TranspilerRepository (tmp_path )
369369 friend_installer = FriendOfSwitchInstaller (repository , mock_ws , Mock ())
370- result = friend_installer .has_valid_job (install_state )
370+ result = friend_installer .get_existing_job_id (install_state )
371371
372372 assert result == expected
373373 if jobs_state and "Switch" in jobs_state and not get_side_effect :
374374 mock_ws .jobs .get .assert_called_once_with (int (jobs_state ["Switch" ]))
375375
376376 @pytest .mark .parametrize (
377- ("initial_jobs " , "reset_side_effect" , "expected_job_id" , "expect_create" , "expect_reset" ),
377+ ("initial_job_id " , "reset_side_effect" , "expected_job_id" , "expect_create" , "expect_reset" ),
378378 (
379- pytest .param ({} , None , "12345" , True , False , id = "new_job_creation" ),
380- pytest .param ({ "Switch" : " 67890"} , None , "67890" , False , True , id = "existing_job_update" ),
379+ pytest .param (None , None , "12345" , True , False , id = "new_job_creation" ),
380+ pytest .param (" 67890" , None , "67890" , False , True , id = "existing_job_update" ),
381381 pytest .param (
382- { "Switch" : " 99999"} ,
382+ " 99999" ,
383383 InvalidParameterValue ("Job not found" ),
384384 "12345" ,
385385 True ,
@@ -389,26 +389,18 @@ def test_has_valid_job(
389389 ),
390390 )
391391 @patch .object (SwitchInstaller , "_get_switch_job_settings" )
392- @patch ("databricks.labs.lakebridge.transpiler.installers.InstallState" )
393392 def test_job_creation (
394393 self ,
395- mock_install_state_class : Mock ,
396394 mock_get_settings : Mock ,
397- initial_jobs : dict ,
395+ initial_job_id : str | None ,
398396 reset_side_effect : Exception | None ,
399397 expected_job_id : str ,
400398 expect_create : bool ,
401399 expect_reset : bool ,
402- installer : SwitchInstaller ,
403400 tmp_path : Path ,
404401 ) -> None :
405402 """Test Switch job creation and update scenarios."""
406403 # Setup
407- mock_install_state = Mock ()
408- mock_install_state .jobs = dict (initial_jobs )
409- mock_install_state .save = Mock ()
410- mock_install_state_class .from_installation .return_value = mock_install_state
411-
412404 mock_get_settings .return_value = {"name" : "test_job" }
413405
414406 mock_job = Mock ()
@@ -428,14 +420,15 @@ def test_job_creation(
428420 test_repository = TranspilerRepository (tmp_path )
429421 mock_installation = Mock ()
430422 friend_installer = FriendOfSwitchInstaller (test_repository , mock_ws , mock_installation )
431- result = friend_installer .create_or_update_switch_job (mock_install_state )
423+ result = friend_installer .create_or_update_switch_job (initial_job_id )
432424
433425 # Assert
434426 assert result == expected_job_id
435427
436428 if expect_reset :
437429 if reset_side_effect :
438- mock_jobs .reset .assert_called_once_with (int (initial_jobs ["Switch" ]), JobSettings (name = "test_job" ))
430+ assert initial_job_id is not None
431+ mock_jobs .reset .assert_called_once_with (int (initial_job_id ), JobSettings (name = "test_job" ))
439432 else :
440433 mock_jobs .reset .assert_called_once_with (int (expected_job_id ), JobSettings (name = "test_job" ))
441434 else :
@@ -446,9 +439,7 @@ def test_job_creation(
446439 else :
447440 mock_jobs .create .assert_not_called ()
448441
449- assert mock_install_state .jobs ["Switch" ] == expected_job_id
450-
451- def test_get_switch_parameters_handles_various_default_values (
442+ def test_get_switch_job_parameters_handles_various_default_values (
452443 self , installer : SwitchInstaller , tmp_path : Path
453444 ) -> None :
454445 """Test that different default values in config are correctly converted."""
@@ -469,20 +460,25 @@ def test_get_switch_parameters_handles_various_default_values(
469460 friend_installer = FriendOfSwitchInstaller (test_repository , mock_ws , mock_installation )
470461
471462 with patch .object (test_repository , "all_transpiler_configs" , return_value = {"switch" : mock_config }):
472- params = friend_installer .get_switch_parameters_from_config ()
473-
474- assert "input_dir" in params
475- assert "output_dir" in params
476- assert "result_catalog" in params
477- assert "result_schema" in params
478- assert "builtin_prompt" in params
479- assert params ["flag1" ] == ""
480- assert params ["flag2" ] == "123"
481- assert params ["flag3" ] == ""
482- assert params ["flag4" ] == "value"
483- assert params ["flag5" ] == "3.14"
484-
485- def test_get_switch_parameters_raises_when_config_missing (self , installer : SwitchInstaller , tmp_path : Path ) -> None :
463+ params = friend_installer .get_switch_job_parameters ()
464+
465+ # Convert list to dict for easier testing
466+ params_dict = {p .name : p .default for p in params }
467+
468+ assert "input_dir" in params_dict
469+ assert "output_dir" in params_dict
470+ assert "result_catalog" in params_dict
471+ assert "result_schema" in params_dict
472+ assert "builtin_prompt" in params_dict
473+ assert params_dict ["flag1" ] == ""
474+ assert params_dict ["flag2" ] == "123"
475+ assert params_dict ["flag3" ] == ""
476+ assert params_dict ["flag4" ] == "value"
477+ assert params_dict ["flag5" ] == "3.14"
478+
479+ def test_get_switch_job_parameters_raises_when_config_missing (
480+ self , installer : SwitchInstaller , tmp_path : Path
481+ ) -> None :
486482 """Test that ValueError is raised when Switch config is not found."""
487483 test_repository = TranspilerRepository (tmp_path )
488484 mock_ws = Mock ()
@@ -491,7 +487,7 @@ def test_get_switch_parameters_raises_when_config_missing(self, installer: Switc
491487
492488 with patch .object (test_repository , "all_transpiler_configs" , return_value = {}):
493489 with pytest .raises (ValueError , match = "Switch config.yml not found" ):
494- friend_installer .get_switch_parameters_from_config ()
490+ friend_installer .get_switch_job_parameters ()
495491
496492 @patch ("databricks.labs.lakebridge.transpiler.installers.ResourceConfigurator" )
497493 @patch ("databricks.labs.lakebridge.transpiler.installers.CatalogOperations" )
0 commit comments