forked from mindspore-Ecosystem/mindspore
!16019 If dataset_dir is not a dir or something else validation is not right somehow
From: @xiefangqi Reviewed-by: @ms_yan,@liucunwei,@jonyguo Signed-off-by: @liucunwei
This commit is contained in:
commit
e0422e972e
|
@ -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):
|
||||
|
|
|
@ -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 [<class 'str'>]." in str(info.value)
|
||||
assert "Argument column_names[0] with value 1 is not of type [<class 'str'>]" 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 [<class \'bool\'>]." in str(info.value)
|
||||
assert "Argument pad_to_bucket_boundary with value \"\" is not of type [<class \'bool\'>]" 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 [<class 'bool'>]." in str(info.value)
|
||||
assert "Argument drop_remainder with value \"\" is not of type [<class 'bool'>]" in str(info.value)
|
||||
|
||||
|
||||
def test_bucket_batch_multi_bucket_no_padding():
|
||||
|
|
|
@ -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 [<class 'str'>]." in str(err.value)
|
||||
assert "Argument column_names[0] with value 1 is not of type [<class 'str'>]" in str(err.value)
|
||||
|
||||
|
||||
def test_numpy_slices_invalid_column_names_string():
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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 [<class 'list'>," \
|
||||
" <class 'tuple'>]."
|
||||
" <class 'tuple'>], but got <class 'float'>."
|
||||
|
||||
|
||||
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 [<class 'tuple'>," \
|
||||
" <class 'list'>]."
|
||||
" <class 'list'>], but got <class 'float'>."
|
||||
|
||||
|
||||
def test_random_affine_exception_shear_size():
|
||||
|
|
|
@ -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 [<class 'int'>, <class 'float'>]." in str(
|
||||
assert "Argument degrees[0] with value col is not of type [<class 'int'>, <class 'float'>]" in str(
|
||||
error_info.value)
|
||||
|
||||
with pytest.raises(ValueError) as error_info:
|
||||
|
|
|
@ -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 [<class 'float'>, <class 'int'>]." in str(e)
|
||||
assert "Argument scale[1] with value 2 is not of type [<class 'float'>, <class 'int'>]" in str(e)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -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 [<class 'list'>, <class 'tuple'>, <class 'int'>]."
|
||||
assert str(e) == ("Argument bits with value 1.1 is not of type [<class 'list'>, <class 'tuple'>, "
|
||||
"<class 'int'>], but got <class 'float'>.")
|
||||
# Test wrong number of bits
|
||||
try:
|
||||
_ = c_vision.RandomPosterize((1, 1, 1))
|
||||
|
|
|
@ -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 [<class 'int'>]." in str(error_info.value)
|
||||
assert "Argument threshold[0] with value 122.1 is not of type [<class 'int'>]" in str(error_info.value)
|
||||
|
||||
with pytest.raises(ValueError) as error_info:
|
||||
vision.RandomSolarize((122, 100, 30))
|
||||
|
|
|
@ -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 " \
|
||||
"[<class 'int'>]." in str(info.value)
|
||||
"[<class 'int'>]" 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 " \
|
||||
"[<class 'int'>]." in str(info.value)
|
||||
"[<class 'int'>]" in str(info.value)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in New Issue