@@ -422,6 +422,84 @@ def test__build_docker(plugin):
422422 mock_docker .assert_called_once_with (sentinel .base_path )
423423
424424
425+ # Test _build_docker on Linux/Unix-like systems
426+ def test__build_docker_posix (plugin ):
427+ plugin ._use_docker = True
428+
429+ patch_pip = patch .object (plugin , "_pip_build" , autospec = True )
430+ patch_from_env = patch ("rpdk.python.codegen.docker.from_env" , autospec = True )
431+ patch_os_name = patch ("rpdk.python.codegen.os.name" , "posix" )
432+
433+ with patch_pip as mock_pip , patch_from_env as mock_from_env :
434+ mock_run = mock_from_env .return_value .containers .run
435+ with patch_os_name :
436+ plugin ._build (sentinel .base_path )
437+
438+ mock_pip .assert_not_called ()
439+ mock_run .assert_called_once_with (
440+ image = ANY ,
441+ command = ANY ,
442+ auto_remove = True ,
443+ volumes = {str (sentinel .base_path ): {"bind" : "/project" , "mode" : "rw" }},
444+ stream = True ,
445+ entrypoint = "" ,
446+ user = ANY ,
447+ )
448+
449+
450+ # Test _build_docker on Windows
451+ def test__build_docker_windows (plugin ):
452+ plugin ._use_docker = True
453+
454+ patch_pip = patch .object (plugin , "_pip_build" , autospec = True )
455+ patch_from_env = patch ("rpdk.python.codegen.docker.from_env" , autospec = True )
456+ patch_os_name = patch ("rpdk.python.codegen.os.name" , "nt" )
457+
458+ with patch_pip as mock_pip , patch_from_env as mock_from_env :
459+ mock_run = mock_from_env .return_value .containers .run
460+ with patch_os_name :
461+ plugin ._build (sentinel .base_path )
462+
463+ mock_pip .assert_not_called ()
464+ mock_run .assert_called_once_with (
465+ image = ANY ,
466+ command = ANY ,
467+ auto_remove = True ,
468+ volumes = {str (sentinel .base_path ): {"bind" : "/project" , "mode" : "rw" }},
469+ stream = True ,
470+ entrypoint = "" ,
471+ user = "root:root" ,
472+ )
473+
474+
475+ # Test _build_docker if geteuid fails
476+ def test__build_docker_no_euid (plugin ):
477+ plugin ._use_docker = True
478+
479+ patch_pip = patch .object (plugin , "_pip_build" , autospec = True )
480+ patch_from_env = patch ("rpdk.python.codegen.docker.from_env" , autospec = True )
481+ # os.geteuid does not exist on Windows so we can not autospec os
482+ patch_os = patch ("rpdk.python.codegen.os" )
483+ patch_os_name = patch ("rpdk.python.codegen.os.name" , "posix" )
484+
485+ with patch_pip as mock_pip , patch_from_env as mock_from_env , patch_os as mock_patch_os : # noqa: B950 pylint: disable=line-too-long
486+ mock_run = mock_from_env .return_value .containers .run
487+ mock_patch_os .geteuid .side_effect = AttributeError ()
488+ with patch_os_name :
489+ plugin ._build (sentinel .base_path )
490+
491+ mock_pip .assert_not_called ()
492+ mock_run .assert_called_once_with (
493+ image = ANY ,
494+ command = ANY ,
495+ auto_remove = True ,
496+ volumes = {str (sentinel .base_path ): {"bind" : "/project" , "mode" : "rw" }},
497+ stream = True ,
498+ entrypoint = "" ,
499+ user = "root:root" ,
500+ )
501+
502+
425503def test__docker_build_good_path (plugin , tmp_path ):
426504 patch_from_env = patch ("rpdk.python.codegen.docker.from_env" , autospec = True )
427505
0 commit comments