Skip to content

Mock time.sleep in unit tests #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions tests/unit/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,8 @@ def test_endpoint_from_production_variants_with_tags(sagemaker_session):
Tags=tags)


def test_wait_for_tuning_job(sagemaker_session):
@patch('time.sleep')
def test_wait_for_tuning_job(sleep, sagemaker_session):
hyperparameter_tuning_job_desc = {'HyperParameterTuningJobStatus': 'Completed'}
sagemaker_session.sagemaker_client.describe_hyper_parameter_tuning_job = Mock(
name='describe_hyper_parameter_tuning_job', return_value=hyperparameter_tuning_job_desc)
Expand Down Expand Up @@ -661,15 +662,17 @@ def test_tune_job_status_none(sagemaker_session):
assert result is None


def test_wait_for_transform_job_completed(sagemaker_session):
@patch('time.sleep')
def test_wait_for_transform_job_completed(sleep, sagemaker_session):
transform_job_desc = {'TransformJobStatus': 'Completed'}
sagemaker_session.sagemaker_client.describe_transform_job = Mock(
name='describe_transform_job', return_value=transform_job_desc)

assert sagemaker_session.wait_for_transform_job(JOB_NAME)['TransformJobStatus'] == 'Completed'


def test_wait_for_transform_job_in_progress(sagemaker_session):
@patch('time.sleep')
def test_wait_for_transform_job_in_progress(sleep, sagemaker_session):
transform_job_desc_in_progress = {'TransformJobStatus': 'InProgress'}
transform_job_desc_in_completed = {'TransformJobStatus': 'Completed'}
sagemaker_session.sagemaker_client.describe_transform_job = Mock(
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/test_tf_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ def test_run_tensorboard_locally_without_awscli_binary(time, strftime, popen, ca
@patch('subprocess.Popen')
@patch('time.strftime', return_value=TIMESTAMP)
@patch('time.time', return_value=TIME)
def test_run_tensorboard_locally(time, strftime, popen, call, access, rmtree, mkdtemp, sync, sagemaker_session):
@patch('time.sleep')
def test_run_tensorboard_locally(sleep, time, strftime, popen, call, access, rmtree, mkdtemp, sync, sagemaker_session):
tf = TensorFlow(entry_point=SCRIPT_PATH, role=ROLE, sagemaker_session=sagemaker_session,
train_instance_count=INSTANCE_COUNT, train_instance_type=INSTANCE_TYPE)

Expand All @@ -322,8 +323,7 @@ def test_run_tensorboard_locally(time, strftime, popen, call, access, rmtree, mk

popen.assert_called_with(['tensorboard', '--logdir', '/my/temp/folder', '--host', 'localhost', '--port', '6006'],
stderr=-1,
stdout=-1
)
stdout=-1)


@patch('sagemaker.tensorflow.estimator.Tensorboard._sync_directories')
Expand All @@ -335,7 +335,8 @@ def test_run_tensorboard_locally(time, strftime, popen, call, access, rmtree, mk
@patch('subprocess.Popen')
@patch('time.strftime', return_value=TIMESTAMP)
@patch('time.time', return_value=TIME)
def test_run_tensorboard_locally_port_in_use(time, strftime, popen, call, access, socket, rmtree, mkdtemp, sync,
@patch('time.sleep')
def test_run_tensorboard_locally_port_in_use(sleep, time, strftime, popen, call, access, socket, rmtree, mkdtemp, sync,
sagemaker_session):
tf = TensorFlow(entry_point=SCRIPT_PATH, role=ROLE, sagemaker_session=sagemaker_session,
train_instance_count=INSTANCE_COUNT, train_instance_type=INSTANCE_TYPE)
Expand Down