From b6e1fceedcef06814e38aac65c559caeb81181f0 Mon Sep 17 00:00:00 2001 From: xiefangqi Date: Thu, 6 May 2021 19:08:55 +0800 Subject: [PATCH] minddata modify dir validation --- mindspore/dataset/core/validator_helpers.py | 9 ++++++--- tests/ut/python/dataset/test_bucket_batch_by_length.py | 6 +++--- tests/ut/python/dataset/test_dataset_numpy_slices.py | 2 +- tests/ut/python/dataset/test_datasets_coco.py | 2 +- tests/ut/python/dataset/test_random_affine.py | 4 ++-- tests/ut/python/dataset/test_random_color.py | 2 +- tests/ut/python/dataset/test_random_crop_and_resize.py | 2 +- tests/ut/python/dataset/test_random_posterize.py | 3 ++- tests/ut/python/dataset/test_random_solarize_op.py | 2 +- tests/ut/python/dataset/test_slice_op.py | 4 ++-- 10 files changed, 20 insertions(+), 16 deletions(-) diff --git a/mindspore/dataset/core/validator_helpers.py b/mindspore/dataset/core/validator_helpers.py index 33632c66169..4ab8b6c0733 100644 --- a/mindspore/dataset/core/validator_helpers.py +++ b/mindspore/dataset/core/validator_helpers.py @@ -265,9 +265,11 @@ def type_check(arg, types, arg_name): if int in types and bool not in types: if isinstance(arg, bool): - raise TypeError("Argument {0} with value {1} is not of type {2}.".format(arg_name, print_value, types)) + raise TypeError("Argument {0} with value {1} is not of type {2}, but got {3}.".format(arg_name, print_value, + types, type(arg))) if not isinstance(arg, types): - raise TypeError("Argument {0} with value {1} is not of type {2}.".format(arg_name, print_value, list(types))) + raise TypeError("Argument {0} with value {1} is not of type {2}, but got {3}.".format(arg_name, print_value, + list(types), type(arg))) def check_filename(path): @@ -299,8 +301,9 @@ def check_filename(path): def check_dir(dataset_dir): + type_check(dataset_dir, (str,), "dataset_dir") if not os.path.isdir(dataset_dir) or not os.access(dataset_dir, os.R_OK): - raise ValueError("The folder {} does not exist or permission denied!".format(dataset_dir)) + raise ValueError("The folder {} does not exist or is not a directory or permission denied!".format(dataset_dir)) def check_file(dataset_file): diff --git a/tests/ut/python/dataset/test_bucket_batch_by_length.py b/tests/ut/python/dataset/test_bucket_batch_by_length.py index d5aa85f742e..d103d0992d7 100644 --- a/tests/ut/python/dataset/test_bucket_batch_by_length.py +++ b/tests/ut/python/dataset/test_bucket_batch_by_length.py @@ -65,7 +65,7 @@ def test_bucket_batch_invalid_input(): with pytest.raises(TypeError) as info: _ = dataset.bucket_batch_by_length(invalid_column_names, bucket_boundaries, bucket_batch_sizes) - assert "Argument column_names[0] with value 1 is not of type []." in str(info.value) + assert "Argument column_names[0] with value 1 is not of type []" in str(info.value) with pytest.raises(ValueError) as info: _ = dataset.bucket_batch_by_length(column_names, empty_bucket_boundaries, bucket_batch_sizes) @@ -110,12 +110,12 @@ def test_bucket_batch_invalid_input(): with pytest.raises(TypeError) as info: _ = dataset.bucket_batch_by_length(column_names, bucket_boundaries, bucket_batch_sizes, None, None, invalid_type_pad_to_bucket_boundary) - assert "Argument pad_to_bucket_boundary with value \"\" is not of type []." in str(info.value) + assert "Argument pad_to_bucket_boundary with value \"\" is not of type []" in str(info.value) with pytest.raises(TypeError) as info: _ = dataset.bucket_batch_by_length(column_names, bucket_boundaries, bucket_batch_sizes, None, None, False, invalid_type_drop_remainder) - assert "Argument drop_remainder with value \"\" is not of type []." in str(info.value) + assert "Argument drop_remainder with value \"\" is not of type []" in str(info.value) def test_bucket_batch_multi_bucket_no_padding(): diff --git a/tests/ut/python/dataset/test_dataset_numpy_slices.py b/tests/ut/python/dataset/test_dataset_numpy_slices.py index 178f46d3ccf..f61c8db903b 100644 --- a/tests/ut/python/dataset/test_dataset_numpy_slices.py +++ b/tests/ut/python/dataset/test_dataset_numpy_slices.py @@ -209,7 +209,7 @@ def test_numpy_slices_invalid_column_names_type(): with pytest.raises(TypeError) as err: de.NumpySlicesDataset(np_data, column_names=[1], shuffle=False) - assert "Argument column_names[0] with value 1 is not of type []." in str(err.value) + assert "Argument column_names[0] with value 1 is not of type []" in str(err.value) def test_numpy_slices_invalid_column_names_string(): diff --git a/tests/ut/python/dataset/test_datasets_coco.py b/tests/ut/python/dataset/test_datasets_coco.py index df1bc9c9145..8c8368fb8e8 100644 --- a/tests/ut/python/dataset/test_datasets_coco.py +++ b/tests/ut/python/dataset/test_datasets_coco.py @@ -234,7 +234,7 @@ def test_coco_case_exception(): pass assert False except ValueError as e: - assert "does not exist or permission denied" in str(e) + assert "does not exist or is not a directory or permission denied" in str(e) try: data1 = ds.CocoDataset(DATA_DIR, annotation_file="./file_not_exist", task="Detection") diff --git a/tests/ut/python/dataset/test_random_affine.py b/tests/ut/python/dataset/test_random_affine.py index 2826fbeafdc..2199b6bb916 100644 --- a/tests/ut/python/dataset/test_random_affine.py +++ b/tests/ut/python/dataset/test_random_affine.py @@ -307,7 +307,7 @@ def test_random_affine_exception_translate_size(): logger.info("Got an exception in DE: {}".format(str(e))) assert str( e) == "Argument translate with value 0.1 is not of type [," \ - " ]." + " ], but got ." def test_random_affine_exception_scale_size(): @@ -321,7 +321,7 @@ def test_random_affine_exception_scale_size(): except TypeError as e: logger.info("Got an exception in DE: {}".format(str(e))) assert str(e) == "Argument scale with value 0.5 is not of type [," \ - " ]." + " ], but got ." def test_random_affine_exception_shear_size(): diff --git a/tests/ut/python/dataset/test_random_color.py b/tests/ut/python/dataset/test_random_color.py index 4335f338390..7866923b3e0 100644 --- a/tests/ut/python/dataset/test_random_color.py +++ b/tests/ut/python/dataset/test_random_color.py @@ -221,7 +221,7 @@ def test_random_color_c_errors(): with pytest.raises(TypeError) as error_info: vision.RandomColor(("col", 3)) - assert "Argument degrees[0] with value col is not of type [, ]." in str( + assert "Argument degrees[0] with value col is not of type [, ]" in str( error_info.value) with pytest.raises(ValueError) as error_info: diff --git a/tests/ut/python/dataset/test_random_crop_and_resize.py b/tests/ut/python/dataset/test_random_crop_and_resize.py index c6139b873f0..5fdaf6c6e77 100644 --- a/tests/ut/python/dataset/test_random_crop_and_resize.py +++ b/tests/ut/python/dataset/test_random_crop_and_resize.py @@ -403,7 +403,7 @@ def test_random_crop_and_resize_06(): data.map(operations=random_crop_and_resize_op, input_columns=["image"]) except TypeError as e: logger.info("Got an exception in DE: {}".format(str(e))) - assert "Argument scale[1] with value 2 is not of type [, ]." in str(e) + assert "Argument scale[1] with value 2 is not of type [, ]" in str(e) if __name__ == "__main__": diff --git a/tests/ut/python/dataset/test_random_posterize.py b/tests/ut/python/dataset/test_random_posterize.py index 21d180246dd..fdb53f2c87a 100644 --- a/tests/ut/python/dataset/test_random_posterize.py +++ b/tests/ut/python/dataset/test_random_posterize.py @@ -186,7 +186,8 @@ def test_random_posterize_exception_bit(): _ = c_vision.RandomPosterize(1.1) except TypeError as e: logger.info("Got an exception in DE: {}".format(str(e))) - assert str(e) == "Argument bits with value 1.1 is not of type [, , ]." + assert str(e) == ("Argument bits with value 1.1 is not of type [, , " + "], but got .") # Test wrong number of bits try: _ = c_vision.RandomPosterize((1, 1, 1)) diff --git a/tests/ut/python/dataset/test_random_solarize_op.py b/tests/ut/python/dataset/test_random_solarize_op.py index ea88d47042e..dfe72ba598a 100644 --- a/tests/ut/python/dataset/test_random_solarize_op.py +++ b/tests/ut/python/dataset/test_random_solarize_op.py @@ -114,7 +114,7 @@ def test_random_solarize_errors(): with pytest.raises(TypeError) as error_info: vision.RandomSolarize((122.1, 140)) - assert "Argument threshold[0] with value 122.1 is not of type []." in str(error_info.value) + assert "Argument threshold[0] with value 122.1 is not of type []" in str(error_info.value) with pytest.raises(ValueError) as error_info: vision.RandomSolarize((122, 100, 30)) diff --git a/tests/ut/python/dataset/test_slice_op.py b/tests/ut/python/dataset/test_slice_op.py index b88eeef70b8..ae71139f379 100644 --- a/tests/ut/python/dataset/test_slice_op.py +++ b/tests/ut/python/dataset/test_slice_op.py @@ -299,12 +299,12 @@ def test_slice_exceptions(): with pytest.raises(TypeError) as info: slice_compare([b"1", b"2", b"3", b"4", b"5"], [[[0, 1]]], [b"1", b"2", b"3", b"4", b"5"]) assert "Argument slice_option[0] with value [0, 1] is not of type " \ - "[]." in str(info.value) + "[]" in str(info.value) with pytest.raises(TypeError) as info: slice_compare([b"1", b"2", b"3", b"4", b"5"], [[slice(3)]], [b"1", b"2", b"3", b"4", b"5"]) assert "Argument slice_option[0] with value slice(None, 3, None) is not of type " \ - "[]." in str(info.value) + "[]" in str(info.value) if __name__ == "__main__":