|
28 | 28 | import pytest
|
29 | 29 | import yaml
|
30 | 30 | from mock import patch, Mock, MagicMock
|
31 |
| - |
32 | 31 | import sagemaker
|
33 | 32 | from sagemaker.local.image import _SageMakerContainer, _Volume, _aws_credentials
|
34 | 33 |
|
@@ -91,6 +90,38 @@ def sagemaker_session():
|
91 | 90 | return sms
|
92 | 91 |
|
93 | 92 |
|
| 93 | +@patch("subprocess.check_output", Mock(return_value="Docker Compose version v2.0.0-rc.3")) |
| 94 | +def test_get_compose_cmd_prefix_with_docker_cli(): |
| 95 | + compose_cmd_prefix = _SageMakerContainer._get_compose_cmd_prefix() |
| 96 | + assert compose_cmd_prefix == ["docker", "compose"] |
| 97 | + |
| 98 | + |
| 99 | +@patch( |
| 100 | + "subprocess.check_output", |
| 101 | + side_effect=subprocess.CalledProcessError(returncode=1, cmd="docker compose version"), |
| 102 | +) |
| 103 | +@patch("sagemaker.local.image.find_executable", Mock(return_value="/usr/bin/docker-compose")) |
| 104 | +def test_get_compose_cmd_prefix_with_docker_compose_cli(check_output): |
| 105 | + compose_cmd_prefix = _SageMakerContainer._get_compose_cmd_prefix() |
| 106 | + assert compose_cmd_prefix == ["docker-compose"] |
| 107 | + |
| 108 | + |
| 109 | +@patch( |
| 110 | + "subprocess.check_output", |
| 111 | + side_effect=subprocess.CalledProcessError(returncode=1, cmd="docker compose version"), |
| 112 | +) |
| 113 | +@patch("sagemaker.local.image.find_executable", Mock(return_value=None)) |
| 114 | +def test_get_compose_cmd_prefix_raises_import_error(check_output): |
| 115 | + with pytest.raises(ImportError) as e: |
| 116 | + _SageMakerContainer._get_compose_cmd_prefix() |
| 117 | + assert ( |
| 118 | + "Docker Compose is not installed. " |
| 119 | + "Local Mode features will not work without docker compose. " |
| 120 | + "For more information on how to install 'docker compose', please, see " |
| 121 | + "https://docs.docker.com/compose/install/" in str(e) |
| 122 | + ) |
| 123 | + |
| 124 | + |
94 | 125 | def test_sagemaker_container_hosts_should_have_lowercase_names():
|
95 | 126 | random.seed(a=42)
|
96 | 127 |
|
@@ -333,6 +364,10 @@ def test_check_output():
|
333 | 364 | @patch("sagemaker.local.image._stream_output", Mock())
|
334 | 365 | @patch("sagemaker.local.image._SageMakerContainer._cleanup")
|
335 | 366 | @patch("sagemaker.local.image._SageMakerContainer.retrieve_artifacts")
|
| 367 | +@patch( |
| 368 | + "sagemaker.local.image._SageMakerContainer._get_compose_cmd_prefix", |
| 369 | + Mock(return_value=["docker-compose"]), |
| 370 | +) |
336 | 371 | @patch("sagemaker.local.data.get_data_source_instance")
|
337 | 372 | @patch("subprocess.Popen")
|
338 | 373 | def test_train(
|
@@ -438,6 +473,10 @@ def test_train_with_hyperparameters_without_job_name(
|
438 | 473 | @patch("sagemaker.local.image._stream_output", side_effect=RuntimeError("this is expected"))
|
439 | 474 | @patch("sagemaker.local.image._SageMakerContainer._cleanup")
|
440 | 475 | @patch("sagemaker.local.image._SageMakerContainer.retrieve_artifacts")
|
| 476 | +@patch( |
| 477 | + "sagemaker.local.image._SageMakerContainer._get_compose_cmd_prefix", |
| 478 | + Mock(return_value=["docker-compose"]), |
| 479 | +) |
441 | 480 | @patch("sagemaker.local.data.get_data_source_instance")
|
442 | 481 | @patch("subprocess.Popen", Mock())
|
443 | 482 | def test_train_error(
|
@@ -475,6 +514,10 @@ def test_train_error(
|
475 | 514 | @patch("sagemaker.local.local_session.LocalSession", Mock())
|
476 | 515 | @patch("sagemaker.local.image._stream_output", Mock())
|
477 | 516 | @patch("sagemaker.local.image._SageMakerContainer._cleanup", Mock())
|
| 517 | +@patch( |
| 518 | + "sagemaker.local.image._SageMakerContainer._get_compose_cmd_prefix", |
| 519 | + Mock(return_value=["docker-compose"]), |
| 520 | +) |
478 | 521 | @patch("sagemaker.local.data.get_data_source_instance")
|
479 | 522 | @patch("subprocess.Popen", Mock())
|
480 | 523 | def test_train_local_code(get_data_source_instance, tmpdir, sagemaker_session):
|
@@ -528,6 +571,10 @@ def test_train_local_code(get_data_source_instance, tmpdir, sagemaker_session):
|
528 | 571 | @patch("sagemaker.local.local_session.LocalSession", Mock())
|
529 | 572 | @patch("sagemaker.local.image._stream_output", Mock())
|
530 | 573 | @patch("sagemaker.local.image._SageMakerContainer._cleanup", Mock())
|
| 574 | +@patch( |
| 575 | + "sagemaker.local.image._SageMakerContainer._get_compose_cmd_prefix", |
| 576 | + Mock(return_value=["docker-compose"]), |
| 577 | +) |
531 | 578 | @patch("sagemaker.local.data.get_data_source_instance")
|
532 | 579 | @patch("subprocess.Popen", Mock())
|
533 | 580 | def test_train_local_intermediate_output(get_data_source_instance, tmpdir, sagemaker_session):
|
|
0 commit comments