diff --git a/utils/data_utils.py b/utils/data_utils.py index 6394fd9623ecc632847632ff73e0276fda12b67b..048885633c636c08a14ce04e3519f7ead932a7e1 100644 --- a/utils/data_utils.py +++ b/utils/data_utils.py @@ -9,6 +9,10 @@ import os +class DatasetNotFoundError(Exception): + """ Raised when the requested dataset cannot be located. """ + + class DataValidator: """ This class provides functions for validation of input data. @@ -16,7 +20,7 @@ class DataValidator: """ def __init__(self): - pass + """ No-op constructor. """ @staticmethod def validated_data_dir(filename): @@ -52,12 +56,16 @@ class DataValidator: print('Using {} as the data directory.'.format(data_dir)) # Check if the directory exists - assert os.path.exists(data_dir), \ - data_dir + ' refers to a non-existing directory. '\ - 'Please either correctly set the DL_TEST_DATA_HOME environment variable, ' \ - 'or make sure the datasets are available in the project root.' - - assert os.path.exists(os.path.join(data_dir, filename)), \ - 'Unable to locate ' + filename + ' in ' + data_dir + if not os.path.exists(data_dir): + raise DatasetNotFoundError( + '{} refers to a non-existing directory. Please either correctly set ' + 'the DL_TEST_DATA_HOME environment variable, or make sure the datasets are ' + 'available in the project root.'.format(data_dir) + ) + + if not os.path.exists(os.path.join(data_dir, filename)): + raise DatasetNotFoundError( + 'Unable to locate {} in {}'.format(filename, data_dir) + ) return data_dir