@@ -565,61 +565,112 @@ def test_blaxel_executor_instantiation_without_blaxel_sdk(self):
565565 BlaxelExecutor (additional_imports = [], logger = logger )
566566 assert "Please install 'blaxel' extra" in str (excinfo .value )
567567
568+ @patch ("smolagents.remote_executors._create_kernel_http" )
568569 @patch ("blaxel.core.SandboxInstance" )
569- def test_blaxel_executor_instantiation_with_blaxel_sdk (self , mock_sandbox_instance ):
570+ @patch ("blaxel.core.client.api.compute.create_sandbox" )
571+ @patch ("blaxel.core.settings" )
572+ def test_blaxel_executor_instantiation_with_blaxel_sdk (
573+ self , mock_settings , mock_create_sandbox , mock_sandbox_instance , mock_create_kernel
574+ ):
570575 """Test BlaxelExecutor instantiation with mocked Blaxel SDK."""
571576 logger = MagicMock ()
577+ mock_settings .headers = {}
578+
579+ # Mock sandbox response
580+ mock_response = MagicMock ()
581+ mock_create_sandbox .sync .return_value = mock_response
582+
583+ # Mock SandboxInstance
572584 mock_sandbox = MagicMock ()
573- mock_sandbox_instance .create .return_value = mock_sandbox
574-
575- with patch ("asyncio.run" ) as mock_asyncio_run :
576- mock_asyncio_run .return_value = mock_sandbox
577- executor = BlaxelExecutor (additional_imports = [], logger = logger )
578-
579- assert executor .sandbox_name == "smolagent-executor"
580- assert executor .image == "blaxel/prod-py-app:latest"
581- assert executor .memory == 4096
582- assert executor .region is None
583-
585+ mock_metadata = MagicMock ()
586+ mock_metadata .url = "https://test-sandbox.bl.run"
587+ mock_sandbox .metadata = mock_metadata
588+ mock_sandbox_instance .return_value = mock_sandbox
589+
590+ # Mock kernel creation
591+ mock_create_kernel .return_value = "kernel-123"
592+
593+ executor = BlaxelExecutor (additional_imports = [], logger = logger )
594+
595+ assert executor .sandbox_name .startswith ("smolagent-executor-" )
596+ assert executor .image == "blaxel/jupyter-notebook"
597+ assert executor .memory == 4096
598+ assert executor .region is None
599+
600+ @patch ("smolagents.remote_executors.BlaxelExecutor.install_packages" )
601+ @patch ("smolagents.remote_executors._create_kernel_http" )
584602 @patch ("blaxel.core.SandboxInstance" )
585- def test_blaxel_executor_custom_parameters (self , mock_sandbox_instance ):
603+ @patch ("blaxel.core.client.api.compute.create_sandbox" )
604+ @patch ("blaxel.core.settings" )
605+ def test_blaxel_executor_custom_parameters (
606+ self , mock_settings , mock_create_sandbox , mock_sandbox_instance , mock_create_kernel , mock_install_packages
607+ ):
586608 """Test BlaxelExecutor with custom parameters."""
587609 logger = MagicMock ()
610+ mock_settings .headers = {}
611+ mock_install_packages .return_value = ["numpy" ]
612+
613+ # Mock sandbox response
614+ mock_response = MagicMock ()
615+ mock_create_sandbox .sync .return_value = mock_response
616+
617+ # Mock SandboxInstance
588618 mock_sandbox = MagicMock ()
589- mock_sandbox_instance .create .return_value = mock_sandbox
590-
591- with patch ("asyncio.run" ) as mock_asyncio_run :
592- mock_asyncio_run .return_value = mock_sandbox
593- executor = BlaxelExecutor (
594- additional_imports = ["numpy" ],
595- logger = logger ,
596- sandbox_name = "test-sandbox" ,
597- image = "custom-image:latest" ,
598- memory = 8192 ,
599- region = "us-was-1" ,
600- )
619+ mock_metadata = MagicMock ()
620+ mock_metadata .url = "https://test-sandbox.us-was-1.bl.run"
621+ mock_sandbox .metadata = mock_metadata
622+ mock_sandbox_instance .return_value = mock_sandbox
623+
624+ # Mock kernel creation
625+ mock_create_kernel .return_value = "kernel-123"
626+
627+ executor = BlaxelExecutor (
628+ additional_imports = ["numpy" ],
629+ logger = logger ,
630+ sandbox_name = "test-sandbox" ,
631+ image = "custom-image:latest" ,
632+ memory = 8192 ,
633+ region = "us-was-1" ,
634+ )
601635
602- assert executor .sandbox_name == "test-sandbox"
603- assert executor .image == "custom-image:latest"
604- assert executor .memory == 8192
605- assert executor .region == "us-was-1"
636+ assert executor .sandbox_name == "test-sandbox"
637+ assert executor .image == "custom-image:latest"
638+ assert executor .memory == 8192
639+ assert executor .region == "us-was-1"
640+ assert mock_install_packages .called
606641
642+ @patch ("smolagents.remote_executors._create_kernel_http" )
607643 @patch ("blaxel.core.SandboxInstance" )
644+ @patch ("blaxel.core.client.api.compute.create_sandbox" )
608645 @patch ("blaxel.core.client.api.compute.delete_sandbox" )
609- def test_blaxel_executor_cleanup (self , mock_delete_sandbox , mock_sandbox_instance ):
646+ @patch ("blaxel.core.settings" )
647+ def test_blaxel_executor_cleanup (
648+ self , mock_settings , mock_delete_sandbox , mock_create_sandbox , mock_sandbox_instance , mock_create_kernel
649+ ):
610650 """Test BlaxelExecutor cleanup method."""
611651 logger = MagicMock ()
652+ mock_settings .headers = {}
653+
654+ # Mock sandbox response
655+ mock_response = MagicMock ()
656+ mock_create_sandbox .sync .return_value = mock_response
657+
658+ # Mock SandboxInstance
612659 mock_sandbox = MagicMock ()
613- mock_sandbox_instance .create .return_value = mock_sandbox
614-
615- with patch ("asyncio.run" ) as mock_asyncio_run :
616- mock_asyncio_run .return_value = mock_sandbox
617- executor = BlaxelExecutor (additional_imports = [], logger = logger )
618-
619- # Test cleanup
620- executor .cleanup ()
660+ mock_metadata = MagicMock ()
661+ mock_metadata .url = "https://test-sandbox.bl.run"
662+ mock_sandbox .metadata = mock_metadata
663+ mock_sandbox_instance .return_value = mock_sandbox
664+
665+ # Mock kernel creation
666+ mock_create_kernel .return_value = "kernel-123"
667+
668+ executor = BlaxelExecutor (additional_imports = [], logger = logger )
669+
670+ # Test cleanup
671+ executor .cleanup ()
621672
622- # Verify that delete_sandbox.sync was called
623- assert mock_delete_sandbox .sync .called
624- # Verify sandbox reference was cleaned up
625- assert not hasattr (executor , "sandbox" )
673+ # Verify that delete_sandbox.sync was called
674+ assert mock_delete_sandbox .sync .called
675+ # Verify sandbox reference was cleaned up
676+ assert not hasattr (executor , "sandbox" )
0 commit comments