Skip to content

Commit b27e495

Browse files
author
Dan Choi
committed
simplifiy unit test
1 parent 0964220 commit b27e495

File tree

1 file changed

+2
-23
lines changed

1 file changed

+2
-23
lines changed

tests/unit/test_image.py

+2-23
Original file line numberDiff line numberDiff line change
@@ -266,47 +266,26 @@ def test_train(_download_folder, _cleanup, popen, _stream_output, LocalSession,
266266

267267
@patch('sagemaker.local.local_session.LocalSession')
268268
@patch('sagemaker.local.image._stream_output')
269-
@patch('subprocess.Popen')
270269
@patch('sagemaker.local.image._SageMakerContainer._cleanup')
271270
@patch('sagemaker.local.image._SageMakerContainer._download_folder')
272-
def test_train_with_hyperparameters_without_job_name(_download_folder, _cleanup, popen, _stream_output, LocalSession,
273-
tmpdir, sagemaker_session):
271+
def test_train_with_hyperparameters_without_job_name(_download_folder, _cleanup, _stream_output, LocalSession, tmpdir):
274272

275273
directories = [str(tmpdir.mkdir('container-root')), str(tmpdir.mkdir('data'))]
276274
with patch('sagemaker.local.image._SageMakerContainer._create_tmp_folder',
277275
side_effect=directories):
278276

279277
instance_count = 2
280278
image = 'my-image'
281-
sagemaker_container = _SageMakerContainer('local', instance_count, image, sagemaker_session=sagemaker_session)
279+
sagemaker_container = _SageMakerContainer('local', instance_count, image, sagemaker_session=LocalSession)
282280
sagemaker_container.train(INPUT_DATA_CONFIG, HYPERPARAMETERS_WITHOUT_JOB_NAME, TRAINING_JOB_NAME)
283281

284-
channel_dir = os.path.join(directories[1], 'b')
285-
download_folder_calls = [call('my-own-bucket', 'prefix', channel_dir)]
286-
_download_folder.assert_has_calls(download_folder_calls)
287-
288282
docker_compose_file = os.path.join(sagemaker_container.container_root, 'docker-compose.yaml')
289283

290-
call_args = popen.call_args[0][0]
291-
assert call_args is not None
292-
293-
expected = ['docker-compose', '-f', docker_compose_file, 'up', '--build', '--abort-on-container-exit']
294-
for i, v in enumerate(expected):
295-
assert call_args[i] == v
296-
297284
with open(docker_compose_file, 'r') as f:
298285
config = yaml.load(f)
299-
assert len(config['services']) == instance_count
300286
for h in sagemaker_container.hosts:
301-
assert config['services'][h]['image'] == image
302-
assert config['services'][h]['command'] == 'train'
303-
assert 'AWS_REGION={}'.format(REGION) in config['services'][h]['environment']
304287
assert 'TRAINING_JOB_NAME={}'.format(TRAINING_JOB_NAME) in config['services'][h]['environment']
305288

306-
# assert that expected by sagemaker container output directories exist
307-
assert os.path.exists(os.path.join(sagemaker_container.container_root, 'output'))
308-
assert os.path.exists(os.path.join(sagemaker_container.container_root, 'output/data'))
309-
310289

311290
@patch('sagemaker.local.local_session.LocalSession')
312291
@patch('sagemaker.local.image._stream_output', side_effect=RuntimeError('this is expected'))

0 commit comments

Comments
 (0)