Skip to content

Commit

Permalink
remove auto generated aws tag in integ test. fix delete_all exception…
Browse files Browse the repository at this point in the history
… message
  • Loading branch information
yzhu0 committed Jul 25, 2020
1 parent b322f41 commit 7ed08cf
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/smexperiments/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ def delete_all(self, action):
)

delete_count = 0
last_exception_message = None
last_exception = None
while True:
if delete_count == 3:
raise Exception("Fail to delete because" + last_exception_message + ", please try again.")
raise Exception("Fail to delete, please try again.") from last_exception
try:
for trial_summary in self.list_trials():
t = trial.Trial.load(
Expand All @@ -266,6 +266,6 @@ def delete_all(self, action):
self.delete()
break
except Exception as ex:
last_exception_message = ex
last_exception = ex
finally:
delete_count = delete_count + 1
5 changes: 4 additions & 1 deletion tests/integ/test_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def test_create_tags(experiment_obj, sagemaker_boto_client):
actual_tags = sagemaker_boto_client.list_tags(ResourceArn=experiment_obj.experiment_arn)["Tags"]
if actual_tags:
break
for tag in actual_tags:
if "aws:tag" in tag.get("Key"):
actual_tags.remove(tag)
assert actual_tags == experiment_obj.tags


Expand Down Expand Up @@ -133,5 +136,5 @@ def test_delete_all(complex_experiment_obj):


def test_delete_all_fails(experiment_obj):
with pytest.raises(ValueError):
with pytest.raises(Exception):
experiment_obj.delete_all(action="test")
3 changes: 3 additions & 0 deletions tests/integ/test_trial.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def test_create_tags(trial_obj, sagemaker_boto_client):
actual_tags = sagemaker_boto_client.list_tags(ResourceArn=trial_obj.trial_arn)["Tags"]
if actual_tags:
break
for tag in actual_tags:
if "aws:tag" in tag.get("Key"):
actual_tags.remove(tag)
assert actual_tags == trial_obj.tags


Expand Down
3 changes: 3 additions & 0 deletions tests/integ/test_trial_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def test_create_tags(trial_component_obj, sagemaker_boto_client):
actual_tags = sagemaker_boto_client.list_tags(ResourceArn=trial_component_obj.trial_component_arn)["Tags"]
if actual_tags:
break
for tag in actual_tags:
if "aws:tag" in tag.get("Key"):
actual_tags.remove(tag)
assert actual_tags == trial_component_obj.tags


Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,5 +294,6 @@ def test_delete_all(sagemaker_boto_client):
def test_delete_all_fail(sagemaker_boto_client):
obj = experiment.Experiment(sagemaker_boto_client, experiment_name="foo", description="bar")
sagemaker_boto_client.list_trials.side_effect = Exception
with pytest.raises(Exception):
with pytest.raises(Exception) as e:
obj.delete_all(action="--force")
assert str(e.value) == "Fail to delete, please try again."

0 comments on commit 7ed08cf

Please sign in to comment.