提交 5657491a 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!165 Add more profiler ut

Merge pull request !165 from yuximiao/master
......@@ -14,7 +14,7 @@
# ============================================================================
"""Validate the profiler parameters."""
from mindinsight.profiler.common.exceptions.exceptions import ProfilerParamTypeErrorException, \
ProfilerParamValueErrorException, ProfilerDeviceIdException, ProfilerOpTypeException, \
ProfilerDeviceIdException, ProfilerOpTypeException, \
ProfilerSortConditionException, ProfilerFilterConditionException, ProfilerGroupConditionException
from mindinsight.profiler.common.log import logger as log
......@@ -63,6 +63,24 @@ def validate_condition(search_condition):
raise ProfilerOpTypeException("The op_type must in ['aicpu', 'aicore_type', 'aicore_detail']")
if "group_condition" in search_condition:
validata_group_condition(search_condition)
if "sort_condition" in search_condition:
validate_sort_condition(search_condition, search_scope)
if "filter_condition" in search_condition:
validate_filter_condition(search_condition)
def validata_group_condition(search_condition):
"""
Verify the group_condition in search_condition is valid or not.
Args:
search_condition (dict): The search condition.
Raises:
ProfilerGroupConditionException: If the group_condition param in search_condition is invalid.
"""
group_condition = search_condition.get("group_condition")
if not isinstance(group_condition, dict):
raise ProfilerGroupConditionException("The group condition must be dict.")
......@@ -87,7 +105,18 @@ def validate_condition(search_condition):
if offset > 1000000:
raise ProfilerGroupConditionException("The offset must le 1000000.")
if "sort_condition" in search_condition:
def validate_sort_condition(search_condition, search_scope):
"""
Verify the sort_condition in search_condition is valid or not.
Args:
search_condition (dict): The search condition.
search_scope (list): The search scope.
Raises:
ProfilerSortConditionException: If the sort_condition param in search_condition is invalid.
"""
sort_condition = search_condition.get("sort_condition")
if not isinstance(sort_condition, dict):
raise ProfilerSortConditionException("The sort condition must be dict.")
......@@ -107,10 +136,29 @@ def validate_condition(search_condition):
if sorted_type not in sorted_type_param:
err_msg = "The sorted type must be ascending or descending."
log.error(err_msg)
raise ProfilerParamValueErrorException(err_msg)
raise ProfilerSortConditionException(err_msg)
if "filter_condition" in search_condition:
def validate_filter_condition(search_condition):
"""
Verify the filter_condition in search_condition is valid or not.
Args:
search_condition (dict): The search condition.
Raises:
ProfilerFilterConditionException: If the filter_condition param in search_condition is invalid.
"""
def validate_op_filter_condition(op_condition):
"""
Verify the op_condition in filter_condition is valid or not.
Args:
op_condition (dict): The op_condition in search_condition.
Raises:
ProfilerFilterConditionException: If the filter_condition param in search_condition is invalid.
"""
if not isinstance(op_condition, dict):
raise ProfilerFilterConditionException("Wrong op_type filter condition.")
for key, value in op_condition.items():
......
......@@ -78,3 +78,44 @@ class TestProfilerRestfulApi(TestCase):
result = response.get_json()
del result["error_msg"]
self.assertDictEqual(expect_result, result)
body_data = {"op_type": "aicore_type", "device_id": 1}
response = self.app_client.post(self.url, data=json.dumps(body_data))
self.assertEqual(400, response.status_code)
expect_result = {
'error_code': '50546182',
}
result = response.get_json()
del result["error_msg"]
self.assertDictEqual(expect_result, result)
body_data = {"op_type": "aicore_type", "device_id": "1", "group_condition": 1}
response = self.app_client.post(self.url, data=json.dumps(body_data))
self.assertEqual(400, response.status_code)
expect_result = {
'error_code': '50546184',
}
result = response.get_json()
del result["error_msg"]
self.assertDictEqual(expect_result, result)
body_data = {"op_type": "aicore_type", "device_id": "1", "sort_condition": {"type": 1}}
response = self.app_client.post(self.url, data=json.dumps(body_data))
self.assertEqual(400, response.status_code)
expect_result = {
'error_code': '50546185',
}
result = response.get_json()
del result["error_msg"]
self.assertDictEqual(expect_result, result)
body_data = {"op_type": "aicore_type", "device_id": "1",
"filter_condition": {"op_type": {"in": ["1", 2]}}}
response = self.app_client.post(self.url, data=json.dumps(body_data))
self.assertEqual(400, response.status_code)
expect_result = {
'error_code': '50546186',
}
result = response.get_json()
del result["error_msg"]
self.assertDictEqual(expect_result, result)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册