Skip to content

Commit 898ae35

Browse files
author
Dewen Qi
committed
fix: Add more unit tests
1 parent 4af1e4e commit 898ae35

File tree

6 files changed

+94
-10
lines changed

6 files changed

+94
-10
lines changed

src/sagemaker/workflow/entities.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,21 @@ def startswith(
116116
bool: Always return False as Pipeline variables are parsed during execution runtime
117117
"""
118118
return False
119+
120+
def endswith(
121+
self,
122+
suffix: Union[str, tuple], # pylint: disable=unused-argument
123+
start: Optional[int] = None, # pylint: disable=unused-argument
124+
end: Optional[int] = None, # pylint: disable=unused-argument
125+
) -> bool:
126+
"""Simulate the Python string's built-in method: endswith
127+
128+
Args:
129+
suffix (str, tuple): The (tuple of) string to be checked.
130+
start (int): To set the start index of the matching boundary (default: None).
131+
end (int): To set the end index of the matching boundary (default: None).
132+
133+
Return:
134+
bool: Always return False as Pipeline variables are parsed during execution runtime
135+
"""
136+
return False

tests/integ/sagemaker/workflow/test_tuning_steps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_tuning_single_algo(
105105
max_retry_attempts=3,
106106
)
107107

108-
min_batch_size = ParameterString(name="MinBatchSize", default_value="64")
108+
min_batch_size = ParameterInteger(name="MinBatchSize", default_value=64)
109109
max_batch_size = ParameterInteger(name="MaxBatchSize", default_value=128)
110110
hyperparameter_ranges = {
111111
"batch-size": IntegerParameter(min_batch_size, max_batch_size),

tests/unit/sagemaker/workflow/test_execution_variables.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,28 @@ def test_to_string():
2727

2828
assert var.to_string() == var
2929

30+
31+
def test_implicit_value():
32+
var = ExecutionVariables.START_DATETIME
33+
3034
with pytest.raises(TypeError) as error:
3135
str(var)
32-
3336
assert str(error.value) == "Pipeline variables do not support __str__ operation."
3437

38+
with pytest.raises(TypeError) as error:
39+
int(var)
40+
assert str(error.value) == "Pipeline variables do not support __int__ operation."
41+
42+
with pytest.raises(TypeError) as error:
43+
float(var)
44+
assert str(error.value) == "Pipeline variables do not support __float__ operation."
45+
3546

36-
def test_startswith():
47+
def test_string_builtin_funcs_that_return_bool():
3748
prop = ExecutionVariables.PIPELINE_NAME
3849
# The execution var will only be parsed in runtime (Pipeline backend) so not able to tell in SDK
3950
assert not prop.startswith("MyPipeline")
51+
assert not prop.endswith("MyPipeline")
4052

4153

4254
def test_add_func():

tests/unit/sagemaker/workflow/test_functions.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,28 @@ def test_to_string_on_join():
7575

7676
assert func.to_string() == func
7777

78+
79+
def test_implicit_value_on_join():
80+
func = Join(values=[1, "a", False, 1.1])
81+
7882
with pytest.raises(TypeError) as error:
7983
str(func)
80-
8184
assert str(error.value) == "Pipeline variables do not support __str__ operation."
8285

86+
with pytest.raises(TypeError) as error:
87+
int(func)
88+
assert str(error.value) == "Pipeline variables do not support __int__ operation."
89+
90+
with pytest.raises(TypeError) as error:
91+
float(func)
92+
assert str(error.value) == "Pipeline variables do not support __float__ operation."
93+
8394

84-
def test_startswith_on_join():
95+
def test_string_builtin_funcs_that_return_bool_on_join():
8596
func = Join(on=",", values=["s3:/", "my-bucket", "a"])
8697
# The func will only be parsed in runtime (Pipeline backend) so not able to tell in SDK
8798
assert not func.startswith("s3")
99+
assert not func.endswith("s3")
88100

89101

90102
def test_add_func_of_join():
@@ -167,20 +179,36 @@ def test_to_string_on_json_get():
167179
},
168180
}
169181

182+
183+
def test_implicit_value_on_json_get():
184+
func = JsonGet(
185+
step_name="my-step",
186+
property_file="my-property-file",
187+
json_path="my-json-path",
188+
)
189+
170190
with pytest.raises(TypeError) as error:
171191
str(func)
172-
173192
assert str(error.value) == "Pipeline variables do not support __str__ operation."
174193

194+
with pytest.raises(TypeError) as error:
195+
int(func)
196+
assert str(error.value) == "Pipeline variables do not support __int__ operation."
197+
198+
with pytest.raises(TypeError) as error:
199+
float(func)
200+
assert str(error.value) == "Pipeline variables do not support __float__ operation."
201+
175202

176-
def test_startswith_on_json_get():
203+
def test_string_builtin_funcs_that_return_bool_on_json_get():
177204
func = JsonGet(
178205
step_name="my-step",
179206
property_file="my-property-file",
180207
json_path="my-json-path",
181208
)
182209
# The func will only be parsed in runtime (Pipeline backend) so not able to tell in SDK
183210
assert not func.startswith("s3")
211+
assert not func.endswith("s3")
184212

185213

186214
def test_add_func_of_json_get():

tests/unit/sagemaker/workflow/test_parameters.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,31 @@ def test_parsable_parameter_string():
102102
assert urlparse(param).scheme == "s3"
103103

104104

105-
def test_startswith_on_parameter_string():
105+
def test_string_builtin_funcs_that_return_bool_on_parameter_string():
106106
param = ParameterString("MyString", default_value="s3://foo/bar/baz.csv")
107107
# The param will only be parsed in runtime (Pipeline backend) so not able to tell in SDK
108108
assert not param.startswith("s3")
109+
assert not param.endswith("s3")
109110

110111

111112
def test_add_func():
112113
param_str = ParameterString(name="MyString", default_value="s3://foo/bar/baz.csv")
113114
param_int = ParameterInteger(name="MyInteger", default_value=3)
115+
param_float = ParameterFloat(name="MyFloat", default_value=1.5)
116+
param_bool = ParameterBoolean(name="MyBool")
114117

115118
with pytest.raises(TypeError) as error:
116119
param_str + param_int
120+
assert str(error.value) == "Pipeline variables do not support concatenation."
121+
122+
with pytest.raises(TypeError) as error:
123+
param_int + param_float
124+
assert str(error.value) == "Pipeline variables do not support concatenation."
117125

126+
with pytest.raises(TypeError) as error:
127+
param_float + param_bool
128+
assert str(error.value) == "Pipeline variables do not support concatenation."
129+
130+
with pytest.raises(TypeError) as error:
131+
param_bool + param_str
118132
assert str(error.value) == "Pipeline variables do not support concatenation."

tests/unit/sagemaker/workflow/test_properties.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,28 @@ def test_to_string():
105105
},
106106
}
107107

108+
109+
def test_implicit_value():
110+
prop = Properties("Steps.MyStep", "DescribeTrainingJobResponse")
111+
108112
with pytest.raises(TypeError) as error:
109113
str(prop.CreationTime)
110-
111114
assert str(error.value) == "Pipeline variables do not support __str__ operation."
112115

116+
with pytest.raises(TypeError) as error:
117+
int(prop.CreationTime)
118+
assert str(error.value) == "Pipeline variables do not support __int__ operation."
119+
120+
with pytest.raises(TypeError) as error:
121+
float(prop.CreationTime)
122+
assert str(error.value) == "Pipeline variables do not support __float__ operation."
123+
113124

114-
def test_startswith():
125+
def test_string_builtin_funcs_that_return_bool():
115126
prop = Properties("Steps.MyStep", "DescribeModelPackageOutput")
116127
# The prop will only be parsed in runtime (Pipeline backend) so not able to tell in SDK
117128
assert not prop.startswith("s3")
129+
assert not prop.endswith("s3")
118130

119131

120132
def test_add_func():

0 commit comments

Comments
 (0)