Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MindSpore
mindinsight
提交
a807c45a
M
mindinsight
项目概览
MindSpore
/
mindinsight
通知
7
Star
3
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindinsight
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a807c45a
编写于
3月 30, 2020
作者:
O
ougongchang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add some exceptions, such as TrainJobNotExistError, GraphNotExistError and so on
上级
bf31095f
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
144 addition
and
66 deletion
+144
-66
mindinsight/datavisual/common/exceptions.py
mindinsight/datavisual/common/exceptions.py
+48
-0
mindinsight/datavisual/common/validation.py
mindinsight/datavisual/common/validation.py
+3
-3
mindinsight/datavisual/data_transform/data_manager.py
mindinsight/datavisual/data_transform/data_manager.py
+5
-5
mindinsight/datavisual/processors/graph_processor.py
mindinsight/datavisual/processors/graph_processor.py
+2
-2
mindinsight/datavisual/processors/images_processor.py
mindinsight/datavisual/processors/images_processor.py
+10
-3
mindinsight/datavisual/processors/scalars_processor.py
mindinsight/datavisual/processors/scalars_processor.py
+6
-1
mindinsight/datavisual/processors/train_task_manager.py
mindinsight/datavisual/processors/train_task_manager.py
+1
-1
mindinsight/datavisual/utils/tools.py
mindinsight/datavisual/utils/tools.py
+1
-1
mindinsight/utils/constant.py
mindinsight/utils/constant.py
+5
-1
mindinsight/utils/exceptions.py
mindinsight/utils/exceptions.py
+9
-0
tests/st/func/datavisual/image/test_single_image_restful_api.py
...st/func/datavisual/image/test_single_image_restful_api.py
+8
-9
tests/st/func/datavisual/taskmanager/test_plugins_restful_api.py
...t/func/datavisual/taskmanager/test_plugins_restful_api.py
+2
-3
tests/ut/backend/datavisual/test_task_manager_api.py
tests/ut/backend/datavisual/test_task_manager_api.py
+3
-3
tests/ut/datavisual/data_transform/test_data_manager.py
tests/ut/datavisual/data_transform/test_data_manager.py
+3
-1
tests/ut/datavisual/processors/test_graph_processor.py
tests/ut/datavisual/processors/test_graph_processor.py
+8
-6
tests/ut/datavisual/processors/test_images_processor.py
tests/ut/datavisual/processors/test_images_processor.py
+18
-15
tests/ut/datavisual/processors/test_scalars_processor.py
tests/ut/datavisual/processors/test_scalars_processor.py
+7
-6
tests/ut/datavisual/processors/test_train_task_manager.py
tests/ut/datavisual/processors/test_train_task_manager.py
+5
-6
未找到文件。
mindinsight/datavisual/common/exceptions.py
浏览文件 @
a807c45a
...
...
@@ -90,3 +90,51 @@ class MaxCountExceededError(MindInsightException):
super
(
MaxCountExceededError
,
self
).
__init__
(
DataVisualErrors
.
MAX_COUNT_EXCEEDED_ERROR
,
error_msg
,
http_code
=
400
)
class
TrainJobNotExistError
(
MindInsightException
):
"""Can not find the given train job."""
def
__init__
(
self
,
error_detail
=
None
):
if
error_detail
is
None
:
error_msg
=
f
"Train job is not exist."
else
:
error_msg
=
f
"Train job is not exist. Detail:
{
error_detail
}
"
super
(
TrainJobNotExistError
,
self
).
__init__
(
DataVisualErrors
.
TRAIN_JOB_NOT_EXIST
,
error_msg
,
http_code
=
400
)
class
PluginNotAvailableError
(
MindInsightException
):
"""The given plugin is not available."""
def
__init__
(
self
,
error_detail
):
error_msg
=
f
"Plugin is not available. Detail:
{
error_detail
}
"
super
(
PluginNotAvailableError
,
self
).
__init__
(
DataVisualErrors
.
PLUGIN_NOT_AVAILABLE
,
error_msg
,
http_code
=
400
)
class
GraphNotExistError
(
MindInsightException
):
"""Can not found the given graph."""
def
__init__
(
self
):
error_msg
=
'Graph is not exist.'
super
(
GraphNotExistError
,
self
).
__init__
(
DataVisualErrors
.
GRAPH_NOT_EXIST
,
error_msg
,
http_code
=
400
)
class
ImageNotExistError
(
MindInsightException
):
"""Unable to get a image based on a given condition."""
def
__init__
(
self
,
error_detail
):
error_msg
=
f
'Image is not exist. Detail:
{
error_detail
}
'
super
(
ImageNotExistError
,
self
).
__init__
(
DataVisualErrors
.
IMAGE_NOT_EXIST
,
error_msg
,
http_code
=
400
)
class
ScalarNotExistError
(
MindInsightException
):
"""Unable to get scalar values based on a given condition."""
def
__init__
(
self
,
error_detail
):
error_msg
=
f
'Scalar value is not exist. Detail:
{
error_detail
}
'
super
(
ScalarNotExistError
,
self
).
__init__
(
DataVisualErrors
.
SCALAR_NOT_EXIST
,
error_msg
,
http_code
=
400
)
mindinsight/datavisual/common/validation.py
浏览文件 @
a807c45a
...
...
@@ -16,6 +16,7 @@
from
numbers
import
Number
from
mindinsight.utils.exceptions
import
ParamValueError
from
mindinsight.utils.exceptions
import
ParamMissError
from
mindinsight.datavisual.common.exceptions
import
PluginNotAvailableError
from
mindinsight.datavisual.common.enums
import
PluginNameEnum
from
mindinsight.datavisual.utils.tools
import
to_int
...
...
@@ -94,9 +95,8 @@ class Validation:
plugin_name (str): The plugin name.
Raises:
P
aramValu
eError: When plugin name is not valid.
P
luginNotAvailabl
eError: When plugin name is not valid.
"""
plugin_name_list
=
PluginNameEnum
.
list_members
()
if
plugin_name
not
in
plugin_name_list
:
raise
ParamValueError
(
"'plugin_name' only can be one of {}"
""
.
format
(
plugin_name_list
))
raise
PluginNotAvailableError
(
f
"'plugin_name' only can be one of
{
plugin_name_list
}
"
)
mindinsight/datavisual/data_transform/data_manager.py
浏览文件 @
a807c45a
...
...
@@ -30,6 +30,7 @@ from mindinsight.datavisual.common import exceptions
from
mindinsight.datavisual.common.log
import
logger
from
mindinsight.datavisual.common.enums
import
DataManagerStatus
from
mindinsight.datavisual.common.enums
import
PluginNameEnum
from
mindinsight.datavisual.common.exceptions
import
TrainJobNotExistError
from
mindinsight.datavisual.data_transform.loader_generators.loader_generator
import
MAX_DATA_LOADER_SIZE
from
mindinsight.datavisual.data_transform.loader_generators.data_loader_generator
import
DataLoaderGenerator
from
mindinsight.utils.exceptions
import
MindInsightException
...
...
@@ -343,7 +344,7 @@ class DataManager:
self
.
_check_status_valid
()
loader_pool
=
self
.
_get_snapshot_loader_pool
()
if
not
self
.
_is_loader_in_loader_pool
(
train_id
,
loader_pool
):
raise
ParamValueError
(
"Can not find any data in loader pool about the train job
."
)
raise
TrainJobNotExistError
(
"Can not find the given train job in cache
."
)
data_loader
=
loader_pool
[
train_id
].
data_loader
events_data
=
data_loader
.
get_events_data
()
...
...
@@ -365,7 +366,7 @@ class DataManager:
loader_pool (dict[str, LoaderStruct]): Refer to self._loader_pool.
Raises:
ParamValueError: Can not fou
nd train job in data manager.
TrainJobNotExistError: Can not fi
nd train job in data manager.
"""
is_exist
=
False
if
train_id
in
loader_pool
:
...
...
@@ -375,7 +376,7 @@ class DataManager:
is_exist
=
True
break
if
not
is_exist
:
raise
ParamValue
Error
(
"Can not find the train job in data manager."
)
raise
TrainJobNotExist
Error
(
"Can not find the train job in data manager."
)
def
_is_loader_in_loader_pool
(
self
,
train_id
,
loader_pool
):
"""
...
...
@@ -406,8 +407,7 @@ class DataManager:
"""Check if the status is valid to load data."""
if
self
.
status
==
DataManagerStatus
.
INIT
.
value
:
raise
exceptions
.
SummaryLogIsLoading
(
"Data is being loaded, "
"current status: %s."
%
self
.
_status
)
raise
exceptions
.
SummaryLogIsLoading
(
"Data is being loaded, current status: %s."
%
self
.
_status
)
def
get_single_train_job
(
self
,
train_id
,
manual_update
=
False
):
"""
...
...
mindinsight/datavisual/processors/graph_processor.py
浏览文件 @
a807c45a
...
...
@@ -40,9 +40,9 @@ class GraphProcessor(BaseProcessor):
train_job
=
self
.
_data_manager
.
get_train_job_by_plugin
(
train_id
,
PluginNameEnum
.
GRAPH
.
value
)
if
train_job
is
None
:
raise
exceptions
.
SummaryLogPathInvalid
()
raise
exceptions
.
TrainJobNotExistError
()
if
not
train_job
[
'tags'
]:
raise
ParamValueError
(
"Can not find any graph data in the train job."
)
raise
exceptions
.
GraphNotExistError
(
)
if
tag
is
None
:
tag
=
train_job
[
'tags'
][
0
]
...
...
mindinsight/datavisual/processors/images_processor.py
浏览文件 @
a807c45a
...
...
@@ -16,6 +16,7 @@
from
mindinsight.datavisual.utils.tools
import
to_int
from
mindinsight.utils.exceptions
import
ParamValueError
from
mindinsight.datavisual.common.validation
import
Validation
from
mindinsight.datavisual.common.exceptions
import
ImageNotExistError
from
mindinsight.datavisual.processors.base_processor
import
BaseProcessor
...
...
@@ -46,7 +47,10 @@ class ImageProcessor(BaseProcessor):
"""
Validation
.
check_param_empty
(
train_id
=
train_id
,
tag
=
tag
)
result
=
[]
tensors
=
self
.
_data_manager
.
list_tensors
(
train_id
,
tag
)
try
:
tensors
=
self
.
_data_manager
.
list_tensors
(
train_id
,
tag
)
except
ParamValueError
as
ex
:
raise
ImageNotExistError
(
ex
.
message
)
for
tensor
in
tensors
:
# no tensor_proto in TensorEvent
...
...
@@ -75,7 +79,10 @@ class ImageProcessor(BaseProcessor):
Validation
.
check_param_empty
(
train_id
=
train_id
,
tag
=
tag
,
step
=
step
)
step
=
to_int
(
step
,
"step"
)
tensors
=
self
.
_data_manager
.
list_tensors
(
train_id
,
tag
)
try
:
tensors
=
self
.
_data_manager
.
list_tensors
(
train_id
,
tag
)
except
ParamValueError
as
ex
:
raise
ImageNotExistError
(
ex
.
message
)
image
=
None
for
tensor
in
tensors
:
...
...
@@ -87,6 +94,6 @@ class ImageProcessor(BaseProcessor):
break
if
image
is
None
:
raise
ParamValue
Error
(
"Can not find the step with given train job id and tag."
)
raise
ImageNotExist
Error
(
"Can not find the step with given train job id and tag."
)
return
image
mindinsight/datavisual/processors/scalars_processor.py
浏览文件 @
a807c45a
...
...
@@ -13,6 +13,8 @@
# limitations under the License.
# ============================================================================
"""Scalar Processor APIs."""
from
mindinsight.utils.exceptions
import
ParamValueError
from
mindinsight.datavisual.common.exceptions
import
ScalarNotExistError
from
mindinsight.datavisual.common.validation
import
Validation
from
mindinsight.datavisual.processors.base_processor
import
BaseProcessor
...
...
@@ -33,7 +35,10 @@ class ScalarsProcessor(BaseProcessor):
"""
Validation
.
check_param_empty
(
train_id
=
train_id
,
tag
=
tag
)
job_response
=
[]
tensors
=
self
.
_data_manager
.
list_tensors
(
train_id
,
tag
)
try
:
tensors
=
self
.
_data_manager
.
list_tensors
(
train_id
,
tag
)
except
ParamValueError
as
ex
:
raise
ScalarNotExistError
(
ex
.
message
)
for
tensor
in
tensors
:
job_response
.
append
({
...
...
mindinsight/datavisual/processors/train_task_manager.py
浏览文件 @
a807c45a
...
...
@@ -38,7 +38,7 @@ class TrainTaskManager(BaseProcessor):
Validation
.
check_plugin_name
(
plugin_name
=
plugin_name
)
train_job
=
self
.
_data_manager
.
get_train_job_by_plugin
(
train_id
=
train_id
,
plugin_name
=
plugin_name
)
if
train_job
is
None
:
raise
exceptions
.
SummaryLogPathInvalid
()
raise
exceptions
.
TrainJobNotExistError
()
return
dict
(
train_jobs
=
[
train_job
])
def
get_plugins
(
self
,
train_id
,
manual_update
=
True
):
...
...
mindinsight/datavisual/utils/tools.py
浏览文件 @
a807c45a
...
...
@@ -133,7 +133,7 @@ def get_train_id(request):
try
:
train_id
=
unquote
(
train_id
,
errors
=
'strict'
)
except
UnicodeDecodeError
:
raise
exceptions
.
ParamValueError
(
'Unquote
error with strict mode'
)
raise
exceptions
.
UrlDecodeError
(
'Unquote train id
error with strict mode'
)
return
train_id
...
...
mindinsight/utils/constant.py
浏览文件 @
a807c45a
...
...
@@ -40,6 +40,7 @@ class GeneralErrors(Enum):
PATH_NOT_EXISTS_ERROR
=
4
FILE_SYSTEM_PERMISSION_ERROR
=
8
PORT_NOT_AVAILABLE_ERROR
=
9
URL_DECODE_ERROR
=
10
class
LineageMgrErrors
(
Enum
):
...
...
@@ -55,6 +56,9 @@ class DataVisualErrors(Enum):
TRAIN_JOB_NOT_EXIST
=
5
SUMMARY_LOG_PATH_INVALID
=
6
SUMMARY_LOG_IS_LOADING
=
7
SUMMARY_LOG_LOAD_FAILED
=
8
NODE_NOT_IN_GRAPH_ERROR
=
9
PATH_NOT_DIRECTORY_ERROR
=
10
PLUGIN_NOT_AVAILABLE
=
11
GRAPH_NOT_EXIST
=
12
IMAGE_NOT_EXIST
=
13
SCALAR_NOT_EXIST
=
14
mindinsight/utils/exceptions.py
浏览文件 @
a807c45a
...
...
@@ -176,3 +176,12 @@ class UnknownError(MindInsightException):
GeneralErrors
.
UNKNOWN_ERROR
,
error_msg
,
http_code
=
500
)
class
UrlDecodeError
(
MindInsightException
):
"""Url decoding failed"""
def
__init__
(
self
,
error_detail
):
error_msg
=
f
"Url decode failed. Detail:
{
error_detail
}
"
super
(
UrlDecodeError
,
self
).
__init__
(
GeneralErrors
.
URL_DECODE_ERROR
,
error_msg
,
http_code
=
400
)
tests/st/func/datavisual/image/test_single_image_restful_api.py
浏览文件 @
a807c45a
...
...
@@ -127,9 +127,8 @@ class TestSingleImage:
assert
response
.
status_code
==
400
response
=
response
.
get_json
()
assert
response
[
'error_code'
]
==
'50540002'
assert
response
[
'error_msg'
]
==
"Invalid parameter value. Can not find any data "
\
"in loader pool about the train job."
assert
response
[
'error_code'
]
==
'50545005'
assert
response
[
'error_msg'
]
==
"Train job is not exist. Detail: Can not find the given train job in cache."
@
pytest
.
mark
.
level1
@
pytest
.
mark
.
env_single
...
...
@@ -149,9 +148,9 @@ class TestSingleImage:
assert
response
.
status_code
==
400
response
=
response
.
get_json
()
assert
response
[
'error_code'
]
==
'5054
0002
'
assert
response
[
'error_msg'
]
==
"I
nvalid parameter value. Can not find any data
"
\
"in this train job by given tag."
assert
response
[
'error_code'
]
==
'5054
500D
'
assert
response
[
'error_msg'
]
==
"I
mage is not exist. Detail: Invalid parameter value.
"
\
"
Can not find any data
in this train job by given tag."
@
pytest
.
mark
.
level1
@
pytest
.
mark
.
env_single
...
...
@@ -170,9 +169,9 @@ class TestSingleImage:
assert
response
.
status_code
==
400
response
=
response
.
get_json
()
assert
response
[
'error_code'
]
==
'5054
0002
'
assert
response
[
'error_msg'
]
==
"I
nvalid parameter value. Can not find the step
"
\
"with given train job id and tag."
assert
response
[
'error_code'
]
==
'5054
500D
'
assert
response
[
'error_msg'
]
==
"I
mage is not exist. Detail:
"
\
"
Can not find the step
with given train job id and tag."
@
pytest
.
mark
.
level1
@
pytest
.
mark
.
env_single
...
...
tests/st/func/datavisual/taskmanager/test_plugins_restful_api.py
浏览文件 @
a807c45a
...
...
@@ -89,9 +89,8 @@ class TestPlugins:
assert
response
.
status_code
==
400
response
=
response
.
get_json
()
assert
response
[
'error_code'
]
==
'50540002'
assert
response
[
'error_msg'
]
==
"Invalid parameter value. Can not find "
\
"the train job in data manager."
assert
response
[
'error_code'
]
==
'50545005'
assert
response
[
'error_msg'
]
==
"Train job is not exist. Detail: Can not find the train job in data manager."
@
pytest
.
mark
.
level1
@
pytest
.
mark
.
env_single
...
...
tests/ut/backend/datavisual/test_task_manager_api.py
浏览文件 @
a807c45a
...
...
@@ -64,9 +64,9 @@ class TestTrainTask:
assert
response
.
status_code
==
400
response
=
response
.
get_json
()
assert
response
[
'error_code'
]
==
'5054
0002
'
assert
response
[
'error_msg'
]
==
"Invalid parameter value. 'plugin_name'
"
\
"only can be one of {}"
.
format
(
plugin_name_list
)
assert
response
[
'error_code'
]
==
'5054
500B
'
assert
response
[
'error_msg'
]
==
f
"Plugin is not available.
"
\
f
"Detail: 'plugin_name' only can be one of
{
plugin_name_list
}
"
@
patch
.
object
(
TrainTaskManager
,
'get_single_train_task'
)
def
test_query_single_train_task_with_plugin_name_exists
(
self
,
mock_train_task_manager
,
client
):
...
...
tests/ut/datavisual/data_transform/test_data_manager.py
浏览文件 @
a807c45a
...
...
@@ -28,6 +28,7 @@ from unittest.mock import Mock, patch
import
pytest
from
mindinsight.datavisual.common.enums
import
DataManagerStatus
,
PluginNameEnum
from
mindinsight.datavisual.common.exceptions
import
TrainJobNotExistError
from
mindinsight.datavisual.data_transform
import
data_manager
,
ms_data_loader
from
mindinsight.datavisual.data_transform.data_loader
import
DataLoader
from
mindinsight.datavisual.data_transform.data_manager
import
DataManager
...
...
@@ -185,9 +186,10 @@ class TestDataManager:
d_manager
.
_status
=
DataManagerStatus
.
LOADING
.
value
tag
=
'image'
train_job_01
=
'train_01'
with
pytest
.
raises
(
ParamValueError
)
:
with
pytest
.
raises
(
TrainJobNotExistError
)
as
ex_info
:
d_manager
.
list_tensors
(
train_job_01
,
tag
)
shutil
.
rmtree
(
summary_base_dir
)
assert
ex_info
.
value
.
message
==
'Train job is not exist. Detail: Can not find the given train job in cache.'
@
patch
.
object
(
data_manager
.
DataLoaderGenerator
,
"generate_loaders"
)
def
test_caching
(
self
,
mock_generate_loaders
):
...
...
tests/ut/datavisual/processors/test_graph_processor.py
浏览文件 @
a807c45a
...
...
@@ -26,6 +26,7 @@ import pytest
from
mindinsight.datavisual.common
import
exceptions
from
mindinsight.datavisual.common.enums
import
PluginNameEnum
from
mindinsight.datavisual.common.exceptions
import
GraphNotExistError
from
mindinsight.datavisual.data_transform
import
data_manager
from
mindinsight.datavisual.data_transform.data_manager
import
DataManager
from
mindinsight.datavisual.data_transform.loader_generators.data_loader_generator
import
DataLoaderGenerator
...
...
@@ -102,16 +103,16 @@ class TestGraphProcessor:
def
test_get_nodes_with_not_exist_train_id
(
self
):
"""Test getting nodes with not exist train id."""
test_train_id
=
"not_exist_train_id"
with
pytest
.
raises
(
ParamValue
Error
)
as
exc_info
:
with
pytest
.
raises
(
exceptions
.
TrainJobNotExist
Error
)
as
exc_info
:
GraphProcessor
(
test_train_id
,
self
.
_mock_data_manager
)
assert
"
Can not find the train job in data manager."
in
exc_info
.
value
.
message
assert
"
Train job is not exist. Detail: Can not find the train job in data manager."
==
exc_info
.
value
.
message
@
pytest
.
mark
.
usefixtures
(
'load_graph_record'
)
@
patch
.
object
(
DataManager
,
'get_train_job_by_plugin'
)
def
test_get_nodes_with_loader_is_none
(
self
,
mock_get_train_job_by_plugin
):
"""Test get nodes with loader is None."""
mock_get_train_job_by_plugin
.
return_value
=
None
with
pytest
.
raises
(
exceptions
.
SummaryLogPathInvalid
):
with
pytest
.
raises
(
exceptions
.
TrainJobNotExistError
):
GraphProcessor
(
self
.
_train_id
,
self
.
_mock_data_manager
)
assert
mock_get_train_job_by_plugin
.
called
...
...
@@ -223,7 +224,8 @@ class TestGraphProcessor:
@
pytest
.
mark
.
usefixtures
(
'load_no_graph_record'
)
def
test_check_graph_status_no_graph
(
self
):
"""Test checking graph status no graph."""
with
pytest
.
raises
(
ParamValue
Error
)
as
exc_info
:
with
pytest
.
raises
(
GraphNotExist
Error
)
as
exc_info
:
GraphProcessor
(
self
.
_train_id
,
self
.
_mock_data_manager
)
assert
exc_info
.
value
.
message
==
"Invalid parameter value. Can not find any graph data "
\
"in the train job."
assert
exc_info
.
value
.
error_code
==
'5054500C'
assert
exc_info
.
value
.
message
==
"Graph is not exist."
tests/ut/datavisual/processors/test_images_processor.py
浏览文件 @
a807c45a
...
...
@@ -24,6 +24,8 @@ from unittest.mock import Mock
import
pytest
from
mindinsight.datavisual.common.enums
import
PluginNameEnum
from
mindinsight.datavisual.common.exceptions
import
TrainJobNotExistError
from
mindinsight.datavisual.common.exceptions
import
ImageNotExistError
from
mindinsight.datavisual.data_transform
import
data_manager
from
mindinsight.datavisual.data_transform.loader_generators.data_loader_generator
import
DataLoaderGenerator
from
mindinsight.datavisual.processors.images_processor
import
ImageProcessor
...
...
@@ -107,11 +109,11 @@ class TestImagesProcessor:
"""Test getting metadata list with not exist id."""
test_train_id
=
'not_exist_id'
image_processor
=
ImageProcessor
(
self
.
_mock_data_manager
)
with
pytest
.
raises
(
ParamValue
Error
)
as
exc_info
:
with
pytest
.
raises
(
TrainJobNotExist
Error
)
as
exc_info
:
image_processor
.
get_metadata_list
(
test_train_id
,
self
.
_tag_name
)
assert
exc_info
.
value
.
error_code
==
'5054
0002
'
assert
"
Can not find any data in loader pool about the train job."
in
exc_info
.
value
.
message
assert
exc_info
.
value
.
error_code
==
'5054
5005
'
assert
"
Train job is not exist. Detail: Can not find the given train job in cache."
==
exc_info
.
value
.
message
@
pytest
.
mark
.
usefixtures
(
'load_image_record'
)
def
test_get_metadata_list_with_not_exist_tag
(
self
):
...
...
@@ -120,10 +122,10 @@ class TestImagesProcessor:
image_processor
=
ImageProcessor
(
self
.
_mock_data_manager
)
with
pytest
.
raises
(
ParamValue
Error
)
as
exc_info
:
with
pytest
.
raises
(
ImageNotExist
Error
)
as
exc_info
:
image_processor
.
get_metadata_list
(
self
.
_train_id
,
test_tag_name
)
assert
exc_info
.
value
.
error_code
==
'5054
0002
'
assert
exc_info
.
value
.
error_code
==
'5054
500D
'
assert
"Can not find any data in this train job by given tag."
in
exc_info
.
value
.
message
@
pytest
.
mark
.
usefixtures
(
'load_image_record'
)
...
...
@@ -144,11 +146,11 @@ class TestImagesProcessor:
test_step
=
self
.
_steps_list
[
0
]
image_processor
=
ImageProcessor
(
self
.
_mock_data_manager
)
with
pytest
.
raises
(
ParamValue
Error
)
as
exc_info
:
with
pytest
.
raises
(
TrainJobNotExist
Error
)
as
exc_info
:
image_processor
.
get_single_image
(
test_train_id
,
test_tag_name
,
test_step
)
assert
exc_info
.
value
.
error_code
==
'5054
0002
'
assert
"
Can not find any data in loader pool about the train job."
in
exc_info
.
value
.
message
assert
exc_info
.
value
.
error_code
==
'5054
5005
'
assert
"
Train job is not exist. Detail: Can not find the given train job in cache."
==
exc_info
.
value
.
message
@
pytest
.
mark
.
usefixtures
(
'load_image_record'
)
def
test_get_single_image_with_not_exist_tag
(
self
):
...
...
@@ -158,10 +160,10 @@ class TestImagesProcessor:
image_processor
=
ImageProcessor
(
self
.
_mock_data_manager
)
with
pytest
.
raises
(
ParamValue
Error
)
as
exc_info
:
with
pytest
.
raises
(
ImageNotExist
Error
)
as
exc_info
:
image_processor
.
get_single_image
(
self
.
_train_id
,
test_tag_name
,
test_step
)
assert
exc_info
.
value
.
error_code
==
'5054
0002
'
assert
exc_info
.
value
.
error_code
==
'5054
500D
'
assert
"Can not find any data in this train job by given tag."
in
exc_info
.
value
.
message
@
pytest
.
mark
.
usefixtures
(
'load_image_record'
)
...
...
@@ -172,11 +174,12 @@ class TestImagesProcessor:
image_processor
=
ImageProcessor
(
self
.
_mock_data_manager
)
with
pytest
.
raises
(
ParamValue
Error
)
as
exc_info
:
with
pytest
.
raises
(
ImageNotExist
Error
)
as
exc_info
:
image_processor
.
get_single_image
(
self
.
_train_id
,
test_tag_name
,
test_step
)
assert
exc_info
.
value
.
error_code
==
'50540002'
assert
"Can not find the step with given train job id and tag."
in
exc_info
.
value
.
message
assert
exc_info
.
value
.
error_code
==
'5054500D'
assert
"Image is not exist. "
\
"Detail: Can not find the step with given train job id and tag."
==
exc_info
.
value
.
message
@
pytest
.
mark
.
usefixtures
(
'load_image_record'
)
def
test_get_single_image_success
(
self
):
...
...
@@ -206,7 +209,7 @@ class TestImagesProcessor:
try
:
image_processor
.
get_single_image
(
self
.
_train_id
,
test_tag_name
,
test_step
)
except
ParamValue
Error
:
except
ImageNotExist
Error
:
cnt
+=
1
assert
len
(
self
.
_more_steps_list
)
-
cnt
==
10
...
...
@@ -233,7 +236,7 @@ class TestImagesProcessor:
try
:
image_processor
.
get_single_image
(
self
.
_train_id
,
test_tag_name
,
test_step
)
current_step_list
.
append
(
test_step
)
except
ParamValue
Error
:
except
ImageNotExist
Error
:
not_found_step_list
.
append
(
test_step
)
assert
current_step_list
==
[
1
,
2
,
3
,
4
,
15
]
...
...
tests/ut/datavisual/processors/test_scalars_processor.py
浏览文件 @
a807c45a
...
...
@@ -24,11 +24,12 @@ from unittest.mock import Mock
import
pytest
from
mindinsight.datavisual.common.enums
import
PluginNameEnum
from
mindinsight.datavisual.common.exceptions
import
TrainJobNotExistError
from
mindinsight.datavisual.common.exceptions
import
ScalarNotExistError
from
mindinsight.datavisual.data_transform
import
data_manager
from
mindinsight.datavisual.data_transform.loader_generators.data_loader_generator
import
DataLoaderGenerator
from
mindinsight.datavisual.processors.scalars_processor
import
ScalarsProcessor
from
mindinsight.datavisual.utils
import
crc32
from
mindinsight.utils.exceptions
import
ParamValueError
from
....utils.log_operations
import
LogOperations
from
....utils.tools
import
check_loading_done
,
delete_files_or_dirs
...
...
@@ -84,11 +85,11 @@ class TestScalarsProcessor:
"""Get metadata list with not exist id."""
test_train_id
=
'not_exist_id'
scalar_processor
=
ScalarsProcessor
(
self
.
_mock_data_manager
)
with
pytest
.
raises
(
ParamValue
Error
)
as
exc_info
:
with
pytest
.
raises
(
TrainJobNotExist
Error
)
as
exc_info
:
scalar_processor
.
get_metadata_list
(
test_train_id
,
self
.
_tag_name
)
assert
exc_info
.
value
.
error_code
==
'5054
0002
'
assert
"
Can not find any data in loader pool about the train job."
in
exc_info
.
value
.
message
assert
exc_info
.
value
.
error_code
==
'5054
5005
'
assert
"
Train job is not exist. Detail: Can not find the given train job in cache."
==
exc_info
.
value
.
message
@
pytest
.
mark
.
usefixtures
(
'load_scalar_record'
)
def
test_get_metadata_list_with_not_exist_tag
(
self
):
...
...
@@ -97,10 +98,10 @@ class TestScalarsProcessor:
scalar_processor
=
ScalarsProcessor
(
self
.
_mock_data_manager
)
with
pytest
.
raises
(
ParamValue
Error
)
as
exc_info
:
with
pytest
.
raises
(
ScalarNotExist
Error
)
as
exc_info
:
scalar_processor
.
get_metadata_list
(
self
.
_train_id
,
test_tag_name
)
assert
exc_info
.
value
.
error_code
==
'5054
0002
'
assert
exc_info
.
value
.
error_code
==
'5054
500E
'
assert
"Can not find any data in this train job by given tag."
in
exc_info
.
value
.
message
@
pytest
.
mark
.
usefixtures
(
'load_scalar_record'
)
...
...
tests/ut/datavisual/processors/test_train_task_manager.py
浏览文件 @
a807c45a
...
...
@@ -25,11 +25,11 @@ from unittest.mock import Mock
import
pytest
from
mindinsight.datavisual.common.enums
import
PluginNameEnum
from
mindinsight.datavisual.common.exceptions
import
TrainJobNotExistError
from
mindinsight.datavisual.data_transform
import
data_manager
from
mindinsight.datavisual.data_transform.loader_generators.data_loader_generator
import
DataLoaderGenerator
from
mindinsight.datavisual.processors.train_task_manager
import
TrainTaskManager
from
mindinsight.datavisual.utils
import
crc32
from
mindinsight.utils.exceptions
import
ParamValueError
from
....utils.log_operations
import
LogOperations
from
....utils.tools
import
check_loading_done
,
delete_files_or_dirs
...
...
@@ -109,12 +109,11 @@ class TestTrainTaskManager:
train_task_manager
=
TrainTaskManager
(
self
.
_mock_data_manager
)
for
plugin_name
in
PluginNameEnum
.
list_members
():
test_train_id
=
"not_exist_id"
with
pytest
.
raises
(
ParamValue
Error
)
as
exc_info
:
with
pytest
.
raises
(
TrainJobNotExist
Error
)
as
exc_info
:
_
=
train_task_manager
.
get_single_train_task
(
plugin_name
,
test_train_id
)
assert
exc_info
.
type
==
ParamValueError
assert
exc_info
.
value
.
message
==
"Invalid parameter value. Can not find "
\
"the train job in data manager."
assert
exc_info
.
value
.
error_code
==
'50540002'
assert
exc_info
.
value
.
message
==
"Train job is not exist. "
\
"Detail: Can not find the train job in data manager."
assert
exc_info
.
value
.
error_code
==
'50545005'
@
pytest
.
mark
.
usefixtures
(
'load_data'
)
def
test_get_single_train_task_with_params
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录