Skip to content

Add tests for Training job & Transform job in visualizer #2171

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
Feb 23, 2021
Merged
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
208 changes: 70 additions & 138 deletions tests/unit/sagemaker/lineage/test_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,64 +49,17 @@ def test_trial_component_name(viz, sagemaker_session):
"TrialComponentArn": "tc-arn",
}

sagemaker_session.sagemaker_client.list_associations.side_effect = [
{
"AssociationSummaries": [
{
"SourceArn": "a:b:c:d:e:artifact/src-arn-1",
"SourceName": "source-name-1",
"SourceType": "source-type-1",
"DestinationArn": "a:b:c:d:e:artifact/dest-arn-1",
"DestinationName": "dest-name-1",
"DestinationType": "dest-type-1",
"AssociationType": "type-1",
}
]
},
{
"AssociationSummaries": [
{
"SourceArn": "a:b:c:d:e:artifact/src-arn-2",
"SourceName": "source-name-2",
"SourceType": "source-type-2",
"DestinationArn": "a:b:c:d:e:artifact/dest-arn-2",
"DestinationName": "dest-name-2",
"DestinationType": "dest-type-2",
"AssociationType": "type-2",
}
]
},
]
get_list_associations_side_effect(sagemaker_session)

df = viz.show(trial_component_name=name)

sagemaker_session.sagemaker_client.describe_trial_component.assert_called_with(
TrialComponentName=name,
)

expected_calls = [
unittest.mock.call(
DestinationArn="tc-arn",
),
unittest.mock.call(
SourceArn="tc-arn",
),
]
assert expected_calls == sagemaker_session.sagemaker_client.list_associations.mock_calls
assert_list_associations_mock_calls(sagemaker_session)

expected_dataframe = pd.DataFrame.from_dict(
OrderedDict(
[
("Name/Source", ["source-name-1", "dest-name-2"]),
("Direction", ["Input", "Output"]),
("Type", ["source-type-1", "dest-type-2"]),
("Association Type", ["type-1", "type-2"]),
("Lineage Type", ["artifact", "artifact"]),
]
)
)

pd.testing.assert_frame_equal(expected_dataframe, df)
pd.testing.assert_frame_equal(get_expected_dataframe(), df)


def test_model_package_arn(viz, sagemaker_session):
Expand All @@ -116,34 +69,7 @@ def test_model_package_arn(viz, sagemaker_session):
"ArtifactSummaries": [{"ArtifactArn": "artifact-arn"}]
}

sagemaker_session.sagemaker_client.list_associations.side_effect = [
{
"AssociationSummaries": [
{
"SourceArn": "a:b:c:d:e:artifact/src-arn-1",
"SourceName": "source-name-1",
"SourceType": "source-type-1",
"DestinationArn": "a:b:c:d:e:artifact/dest-arn-1",
"DestinationName": "dest-name-1",
"DestinationType": "dest-type-1",
"AssociationType": "type-1",
}
]
},
{
"AssociationSummaries": [
{
"SourceArn": "a:b:c:d:e:artifact/src-arn-2",
"SourceName": "source-name-2",
"SourceType": "source-type-2",
"DestinationArn": "a:b:c:d:e:artifact/dest-arn-2",
"DestinationName": "dest-name-2",
"DestinationType": "dest-type-2",
"AssociationType": "type-2",
}
]
},
]
get_list_associations_side_effect(sagemaker_session)

df = viz.show(model_package_arn=name)

Expand All @@ -161,19 +87,7 @@ def test_model_package_arn(viz, sagemaker_session):
]
assert expected_calls == sagemaker_session.sagemaker_client.list_associations.mock_calls

expected_dataframe = pd.DataFrame.from_dict(
OrderedDict(
[
("Name/Source", ["source-name-1", "dest-name-2"]),
("Direction", ["Input", "Output"]),
("Type", ["source-type-1", "dest-type-2"]),
("Association Type", ["type-1", "type-2"]),
("Lineage Type", ["artifact", "artifact"]),
]
)
)

pd.testing.assert_frame_equal(expected_dataframe, df)
pd.testing.assert_frame_equal(get_expected_dataframe(), df)


def test_endpoint_arn(viz, sagemaker_session):
Expand All @@ -183,34 +97,7 @@ def test_endpoint_arn(viz, sagemaker_session):
"ContextSummaries": [{"ContextArn": "context-arn"}]
}

sagemaker_session.sagemaker_client.list_associations.side_effect = [
{
"AssociationSummaries": [
{
"SourceArn": "a:b:c:d:e:context/src-arn-1",
"SourceName": "source-name-1",
"SourceType": "source-type-1",
"DestinationArn": "a:b:c:d:e:context/dest-arn-1",
"DestinationName": "dest-name-1",
"DestinationType": "dest-type-1",
"AssociationType": "type-1",
}
]
},
{
"AssociationSummaries": [
{
"SourceArn": "a:b:c:d:e:context/src-arn-2",
"SourceName": "source-name-2",
"SourceType": "source-type-2",
"DestinationArn": "a:b:c:d:e:context/dest-arn-2",
"DestinationName": "dest-name-2",
"DestinationType": "dest-type-2",
"AssociationType": "type-2",
}
]
},
]
get_list_associations_side_effect(sagemaker_session)

df = viz.show(endpoint_arn=name)

Expand All @@ -228,27 +115,74 @@ def test_endpoint_arn(viz, sagemaker_session):
]
assert expected_calls == sagemaker_session.sagemaker_client.list_associations.mock_calls

expected_dataframe = pd.DataFrame.from_dict(
OrderedDict(
[
("Name/Source", ["source-name-1", "dest-name-2"]),
("Direction", ["Input", "Output"]),
("Type", ["source-type-1", "dest-type-2"]),
("Association Type", ["type-1", "type-2"]),
("Lineage Type", ["context", "context"]),
]
)
pd.testing.assert_frame_equal(get_expected_dataframe(), df)


def test_processing_job_pipeline_execution_step(viz, sagemaker_session):

sagemaker_session.sagemaker_client.list_trial_components.return_value = {
"TrialComponentSummaries": [{"TrialComponentArn": "tc-arn"}]
}

get_list_associations_side_effect(sagemaker_session)

step = {"Metadata": {"ProcessingJob": {"Arn": "proc-job-arn"}}}

df = viz.show(pipeline_execution_step=step)

sagemaker_session.sagemaker_client.list_trial_components.assert_called_with(
SourceArn="proc-job-arn",
)

pd.testing.assert_frame_equal(expected_dataframe, df)
assert_list_associations_mock_calls(sagemaker_session)

pd.testing.assert_frame_equal(get_expected_dataframe(), df)

def test_processing_job_pipeline_execution_step(viz, sagemaker_session):

def test_training_job_pipeline_execution_step(viz, sagemaker_session):

sagemaker_session.sagemaker_client.list_trial_components.return_value = {
"TrialComponentSummaries": [{"TrialComponentArn": "tc-arn"}]
}

get_list_associations_side_effect(sagemaker_session)

step = {"Metadata": {"TrainingJob": {"Arn": "training-job-arn"}}}

df = viz.show(pipeline_execution_step=step)

sagemaker_session.sagemaker_client.list_trial_components.assert_called_with(
SourceArn="training-job-arn",
)

assert_list_associations_mock_calls(sagemaker_session)

pd.testing.assert_frame_equal(get_expected_dataframe(), df)


def test_transform_job_pipeline_execution_step(viz, sagemaker_session):

sagemaker_session.sagemaker_client.list_trial_components.return_value = {
"TrialComponentSummaries": [{"TrialComponentArn": "tc-arn"}]
}

get_list_associations_side_effect(sagemaker_session)

step = {"Metadata": {"TransformJob": {"Arn": "transform-job-arn"}}}

df = viz.show(pipeline_execution_step=step)

sagemaker_session.sagemaker_client.list_trial_components.assert_called_with(
SourceArn="transform-job-arn",
)

assert_list_associations_mock_calls(sagemaker_session)

pd.testing.assert_frame_equal(get_expected_dataframe(), df)


def get_list_associations_side_effect(sagemaker_session):

sagemaker_session.sagemaker_client.list_associations.side_effect = [
{
"AssociationSummaries": [
Expand Down Expand Up @@ -278,13 +212,8 @@ def test_processing_job_pipeline_execution_step(viz, sagemaker_session):
},
]

step = {"Metadata": {"ProcessingJob": {"Arn": "proc-job-arn"}}}

df = viz.show(pipeline_execution_step=step)

sagemaker_session.sagemaker_client.list_trial_components.assert_called_with(
SourceArn="proc-job-arn",
)
def assert_list_associations_mock_calls(sagemaker_session):

expected_calls = [
unittest.mock.call(
Expand All @@ -296,6 +225,9 @@ def test_processing_job_pipeline_execution_step(viz, sagemaker_session):
]
assert expected_calls == sagemaker_session.sagemaker_client.list_associations.mock_calls


def get_expected_dataframe():

expected_dataframe = pd.DataFrame.from_dict(
OrderedDict(
[
Expand All @@ -308,4 +240,4 @@ def test_processing_job_pipeline_execution_step(viz, sagemaker_session):
)
)

pd.testing.assert_frame_equal(expected_dataframe, df)
return expected_dataframe