From 6864128b3e18af14b7ad165d6015c9fada9d41f2 Mon Sep 17 00:00:00 2001
From: Fahad Khalid <f.khalid@fz-juelich.de>
Date: Mon, 2 Sep 2019 14:38:54 +0200
Subject: [PATCH] A bit of cleanup, and also, removed assert statements;
 exceptions are raised instead.

---
 utils/data_utils.py | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/utils/data_utils.py b/utils/data_utils.py
index 6394fd9..0488856 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
-- 
GitLab