!9862 Fix the bug of ImageNetToMR

From: @shenwei41
Reviewed-by: @pandoublefeng,@liucunwei
Signed-off-by: @liucunwei
pull/9862/MERGE
mindspore-ci-bot 4 years ago committed by Gitee
commit 3a803b3c18

@ -81,6 +81,8 @@ def check_filename(path):
raise ParamValueError('File path is not allowed None or empty!') raise ParamValueError('File path is not allowed None or empty!')
if not isinstance(path, str): if not isinstance(path, str):
raise ParamValueError("File path: {} is not string.".format(path)) raise ParamValueError("File path: {} is not string.".format(path))
if path.endswith("/"):
raise ParamValueError("File path can not end with '/'")
file_name = os.path.basename(path) file_name = os.path.basename(path)
# '#', ':', '|', ' ', '}', '"', '+', '!', ']', '[', '\\', '`', # '#', ':', '|', ' ', '}', '"', '+', '!', ']', '[', '\\', '`',

@ -114,3 +114,15 @@ def test_imagenet_to_mindrecord_illegal_filename(fixture_file):
IMAGENET_IMAGE_DIR, filename, IMAGENET_IMAGE_DIR, filename,
PARTITION_NUMBER) PARTITION_NUMBER)
imagenet_transformer.transform() imagenet_transformer.transform()
def test_imagenet_to_mindrecord_illegal_1_filename(fixture_file):
"""
test transform imagenet dataset to mindrecord
when file name end with '/'.
"""
filename = "test/path/"
with pytest.raises(Exception, match="File path can not end with '/'"):
imagenet_transformer = ImageNetToMR(IMAGENET_MAP_FILE,
IMAGENET_IMAGE_DIR, filename,
PARTITION_NUMBER)
imagenet_transformer.transform()

Loading…
Cancel
Save