Skip to content
Snippets Groups Projects
Commit 6864128b authored by Fahad Khalid's avatar Fahad Khalid
Browse files

A bit of cleanup, and also, removed assert statements; exceptions are raised instead.

parent 713cda03
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,10 @@ ...@@ -9,6 +9,10 @@
import os import os
class DatasetNotFoundError(Exception):
""" Raised when the requested dataset cannot be located. """
class DataValidator: class DataValidator:
""" """
This class provides functions for validation of input data. This class provides functions for validation of input data.
...@@ -16,7 +20,7 @@ class DataValidator: ...@@ -16,7 +20,7 @@ class DataValidator:
""" """
def __init__(self): def __init__(self):
pass """ No-op constructor. """
@staticmethod @staticmethod
def validated_data_dir(filename): def validated_data_dir(filename):
...@@ -52,12 +56,16 @@ class DataValidator: ...@@ -52,12 +56,16 @@ class DataValidator:
print('Using {} as the data directory.'.format(data_dir)) print('Using {} as the data directory.'.format(data_dir))
# Check if the directory exists # Check if the directory exists
assert os.path.exists(data_dir), \ if not os.path.exists(data_dir):
data_dir + ' refers to a non-existing directory. '\ raise DatasetNotFoundError(
'Please either correctly set the DL_TEST_DATA_HOME environment variable, ' \ '{} refers to a non-existing directory. Please either correctly set '
'or make sure the datasets are available in the project root.' 'the DL_TEST_DATA_HOME environment variable, or make sure the datasets are '
'available in the project root.'.format(data_dir)
assert os.path.exists(os.path.join(data_dir, filename)), \ )
'Unable to locate ' + filename + ' in ' + 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 return data_dir
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment