Skip to content

Commit 4946c86

Browse files
author
Shegufta Ahsan
committed
Refactoring the global variables
1 parent 651aad5 commit 4946c86

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

src/sagemaker/workflow/emr_step.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -61,42 +61,42 @@ def to_request(self) -> RequestType:
6161
return config
6262

6363

64-
instances = "Instances"
65-
instancegroups = "InstanceGroups"
66-
instancefleets = "InstanceFleets"
67-
err_str_with_name_auto_termination_or_steps = (
64+
INSTANCES = "Instances"
65+
INSTANCEGROUPS = "InstanceGroups"
66+
INSTANCEFLEETS = "InstanceFleets"
67+
ERR_STR_WITH_NAME_AUTO_TERMINATION_OR_STEPS = (
6868
"In EMRStep {step_name}, cluster_config "
6969
"should not contain any of the Name, "
7070
"AutoTerminationPolicy and/or Steps."
7171
)
7272

73-
err_str_without_instance = "In EMRStep {step_name}, cluster_config must contain " + instances + "."
73+
ERR_STR_WITHOUT_INSTANCE = "In EMRStep {step_name}, cluster_config must contain " + INSTANCES + "."
7474

75-
err_str_with_keepjobflow_or_terminationprotected = (
76-
"In EMRStep {step_name}, " + instances + " should not contain "
75+
ERR_STR_WITH_KEEPJOBFLOW_OR_TERMINATIONPROTECTED = (
76+
"In EMRStep {step_name}, " + INSTANCES + " should not contain "
7777
"KeepJobFlowAliveWhenNoSteps or "
7878
"TerminationProtected."
7979
)
8080

81-
err_str_both_or_none_instancegroups_or_instancefleets = (
81+
ERR_STR_BOTH_OR_NONE_INSTANCEGROUPS_OR_INSTANCEFLEETS = (
8282
"In EMRStep {step_name}, "
83-
+ instances
83+
+ INSTANCES
8484
+ " should contain either "
85-
+ instancegroups
85+
+ INSTANCEGROUPS
8686
+ " or "
87-
+ instancefleets
87+
+ INSTANCEFLEETS
8888
+ "."
8989
)
9090

91-
err_str_with_both_cluster_id_and_cluster_cfg = (
91+
ERR_STR_WITH_BOTH_CLUSTER_ID_AND_CLUSTER_CFG = (
9292
"EMRStep {step_name} can not have both cluster_id"
9393
"or cluster_config."
9494
"To use EMRStep with "
9595
"cluster_config, cluster_id "
9696
"must be explicitly set to None."
9797
)
9898

99-
err_str_without_cluster_id_and_cluster_cfg = (
99+
ERR_STR_WITHOUT_CLUSTER_ID_AND_CLUSTER_CFG = (
100100
"EMRStep {step_name} must have either cluster_id or cluster_config"
101101
)
102102

@@ -119,29 +119,29 @@ def _validate_cluster_config(self, cluster_config, step_name):
119119
or "Steps" in cluster_config
120120
):
121121
raise ValueError(
122-
err_str_with_name_auto_termination_or_steps.format(step_name=step_name)
122+
ERR_STR_WITH_NAME_AUTO_TERMINATION_OR_STEPS.format(step_name=step_name)
123123
)
124124

125-
if instances not in cluster_config:
126-
raise ValueError(err_str_without_instance.format(step_name=step_name))
125+
if INSTANCES not in cluster_config:
126+
raise ValueError(ERR_STR_WITHOUT_INSTANCE.format(step_name=step_name))
127127

128128
if (
129-
"KeepJobFlowAliveWhenNoSteps" in cluster_config[instances]
130-
or "TerminationProtected" in cluster_config[instances]
129+
"KeepJobFlowAliveWhenNoSteps" in cluster_config[INSTANCES]
130+
or "TerminationProtected" in cluster_config[INSTANCES]
131131
):
132132
raise ValueError(
133-
err_str_with_keepjobflow_or_terminationprotected.format(step_name=step_name)
133+
ERR_STR_WITH_KEEPJOBFLOW_OR_TERMINATIONPROTECTED.format(step_name=step_name)
134134
)
135135

136136
if (
137-
instancegroups in cluster_config[instances]
138-
and instancefleets in cluster_config[instances]
137+
INSTANCEGROUPS in cluster_config[INSTANCES]
138+
and INSTANCEFLEETS in cluster_config[INSTANCES]
139139
) or (
140-
instancegroups not in cluster_config[instances]
141-
and instancefleets not in cluster_config[instances]
140+
INSTANCEGROUPS not in cluster_config[INSTANCES]
141+
and INSTANCEFLEETS not in cluster_config[INSTANCES]
142142
):
143143
raise ValueError(
144-
err_str_both_or_none_instancegroups_or_instancefleets.format(step_name=step_name)
144+
ERR_STR_BOTH_OR_NONE_INSTANCEGROUPS_OR_INSTANCEFLEETS.format(step_name=step_name)
145145
)
146146

147147
def __init__(
@@ -188,10 +188,10 @@ def __init__(
188188
root_property = Properties(step_name=name, shape_name="Step", service_name="emr")
189189

190190
if cluster_id is None and cluster_config is None:
191-
raise ValueError(err_str_without_cluster_id_and_cluster_cfg.format(step_name=name))
191+
raise ValueError(ERR_STR_WITHOUT_CLUSTER_ID_AND_CLUSTER_CFG.format(step_name=name))
192192

193193
if cluster_id is not None and cluster_config is not None:
194-
raise ValueError(err_str_with_both_cluster_id_and_cluster_cfg.format(step_name=name))
194+
raise ValueError(ERR_STR_WITH_BOTH_CLUSTER_ID_AND_CLUSTER_CFG.format(step_name=name))
195195

196196
if cluster_id is not None:
197197
emr_step_args["ClusterId"] = cluster_id

tests/unit/sagemaker/workflow/test_emr_step.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
from sagemaker.workflow.emr_step import (
1919
EMRStep,
2020
EMRStepConfig,
21-
err_str_with_name_auto_termination_or_steps,
22-
err_str_without_instance,
23-
err_str_with_keepjobflow_or_terminationprotected,
24-
err_str_both_or_none_instancegroups_or_instancefleets,
25-
err_str_with_both_cluster_id_and_cluster_cfg,
26-
err_str_without_cluster_id_and_cluster_cfg,
21+
ERR_STR_WITH_NAME_AUTO_TERMINATION_OR_STEPS,
22+
ERR_STR_WITHOUT_INSTANCE,
23+
ERR_STR_WITH_KEEPJOBFLOW_OR_TERMINATIONPROTECTED,
24+
ERR_STR_BOTH_OR_NONE_INSTANCEGROUPS_OR_INSTANCEFLEETS,
25+
ERR_STR_WITH_BOTH_CLUSTER_ID_AND_CLUSTER_CFG,
26+
ERR_STR_WITHOUT_CLUSTER_ID_AND_CLUSTER_CFG,
2727
)
2828
from sagemaker.workflow.steps import CacheConfig
2929
from sagemaker.workflow.pipeline import Pipeline, PipelineGraph
@@ -212,7 +212,7 @@ def test_emr_step_throws_exception_when_both_cluster_id_and_cluster_config_are_p
212212
depends_on=["TestStep"],
213213
cache_config=CacheConfig(enable_caching=True, expire_after="PT1H"),
214214
)
215-
expected_error_msg = err_str_with_both_cluster_id_and_cluster_cfg.format(
215+
expected_error_msg = ERR_STR_WITH_BOTH_CLUSTER_ID_AND_CLUSTER_CFG.format(
216216
step_name=g_emr_step_name
217217
)
218218
actual_error_msg = exceptionInfo.value.args[0]
@@ -231,7 +231,7 @@ def test_emr_step_throws_exception_when_both_cluster_id_and_cluster_config_are_n
231231
depends_on=["TestStep"],
232232
cache_config=CacheConfig(enable_caching=True, expire_after="PT1H"),
233233
)
234-
expected_error_msg = err_str_without_cluster_id_and_cluster_cfg.format(
234+
expected_error_msg = ERR_STR_WITHOUT_CLUSTER_ID_AND_CLUSTER_CFG.format(
235235
step_name=g_emr_step_name
236236
)
237237
actual_error_msg = exceptionInfo.value.args[0]
@@ -334,7 +334,7 @@ def test_emr_step_with_valid_cluster_config():
334334
],
335335
},
336336
},
337-
err_str_with_name_auto_termination_or_steps.format(step_name=g_emr_step_name),
337+
ERR_STR_WITH_NAME_AUTO_TERMINATION_OR_STEPS.format(step_name=g_emr_step_name),
338338
),
339339
(
340340
{
@@ -347,7 +347,7 @@ def test_emr_step_with_valid_cluster_config():
347347
],
348348
},
349349
},
350-
err_str_with_name_auto_termination_or_steps.format(step_name=g_emr_step_name),
350+
ERR_STR_WITH_NAME_AUTO_TERMINATION_OR_STEPS.format(step_name=g_emr_step_name),
351351
),
352352
(
353353
{
@@ -360,20 +360,20 @@ def test_emr_step_with_valid_cluster_config():
360360
],
361361
},
362362
},
363-
err_str_with_name_auto_termination_or_steps.format(step_name=g_emr_step_name),
363+
ERR_STR_WITH_NAME_AUTO_TERMINATION_OR_STEPS.format(step_name=g_emr_step_name),
364364
),
365365
(
366366
{
367367
"AmiVersion": "3.8.0",
368368
"AdditionalInfo": "MyAdditionalInfo",
369369
},
370-
err_str_without_instance.format(step_name=g_emr_step_name),
370+
ERR_STR_WITHOUT_INSTANCE.format(step_name=g_emr_step_name),
371371
),
372372
(
373373
{
374374
"Instances": {},
375375
},
376-
err_str_both_or_none_instancegroups_or_instancefleets.format(step_name=g_emr_step_name),
376+
ERR_STR_BOTH_OR_NONE_INSTANCEGROUPS_OR_INSTANCEFLEETS.format(step_name=g_emr_step_name),
377377
),
378378
(
379379
{
@@ -390,7 +390,7 @@ def test_emr_step_with_valid_cluster_config():
390390
],
391391
},
392392
},
393-
err_str_both_or_none_instancegroups_or_instancefleets.format(step_name=g_emr_step_name),
393+
ERR_STR_BOTH_OR_NONE_INSTANCEGROUPS_OR_INSTANCEFLEETS.format(step_name=g_emr_step_name),
394394
),
395395
(
396396
{
@@ -403,7 +403,7 @@ def test_emr_step_with_valid_cluster_config():
403403
"KeepJobFlowAliveWhenNoSteps": True,
404404
},
405405
},
406-
err_str_with_keepjobflow_or_terminationprotected.format(step_name=g_emr_step_name),
406+
ERR_STR_WITH_KEEPJOBFLOW_OR_TERMINATIONPROTECTED.format(step_name=g_emr_step_name),
407407
),
408408
(
409409
{
@@ -416,7 +416,7 @@ def test_emr_step_with_valid_cluster_config():
416416
"TerminationProtected": True,
417417
},
418418
},
419-
err_str_with_keepjobflow_or_terminationprotected.format(step_name=g_emr_step_name),
419+
ERR_STR_WITH_KEEPJOBFLOW_OR_TERMINATIONPROTECTED.format(step_name=g_emr_step_name),
420420
),
421421
],
422422
)

0 commit comments

Comments
 (0)