From cecf3c23aa5866d12716ffcd67d47b831b28aa9b Mon Sep 17 00:00:00 2001
From: dave <dave@dtu.dk>
Date: Wed, 3 Feb 2016 16:12:39 +0100
Subject: [PATCH] ugly hack: FileNotFoundError absent in PY2

---
 wetb/dlc/high_level.py            |  8 ++++++++
 wetb/dlc/tests/test_high_level.py | 10 ++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/wetb/dlc/high_level.py b/wetb/dlc/high_level.py
index ffdd0b5..26b976f 100644
--- a/wetb/dlc/high_level.py
+++ b/wetb/dlc/high_level.py
@@ -24,6 +24,14 @@ from wetb.utils.caching import cache_function
 from collections import OrderedDict
 #HOURS_PR_20YEAR = 20 * 365 * 24
 
+# hack around FileNotFoundError not being in Python2
+try:
+    FileNotFoundError
+except NameError as e:
+    class FileNotFoundError(OSError):
+        pass
+
+
 def Weibull(u, k, start, stop, step):
     C = 2 * u / np.sqrt(np.pi)
     cdf = lambda x :-np.exp(-(x / C) ** k)
diff --git a/wetb/dlc/tests/test_high_level.py b/wetb/dlc/tests/test_high_level.py
index 48b8f37..f209f3b 100644
--- a/wetb/dlc/tests/test_high_level.py
+++ b/wetb/dlc/tests/test_high_level.py
@@ -74,8 +74,14 @@ class TestDLCHighLevel(unittest.TestCase):
             self.assertTrue(k in self.dlc_hl.sensor_info().keys(), k)
 
     def test_fail_on_res_not_fount(self):
-        self.dlc_hl = DLCHighLevel(testfilepath + 'DLC_test.xlsx', fail_on_resfile_not_found=True)
-        self.assertRaisesRegex(FileNotFoundError, "Result files for dlc='12', wsp='6', wdir='-10' not found")
+        # hack around FileNotFoundError not being in Python2.7
+        try:
+            self.dlc_hl = DLCHighLevel(testfilepath + 'DLC_test.xlsx',
+                                       fail_on_resfile_not_found=True)
+        except Exception as e:
+            # FileNotFoundError on Py3.3+ inherits from IOError
+            assert isinstance(e.__cause__, IOError)
+#        self.assertRaises(FileNotFoundError, "Result files for dlc='12', wsp='6', wdir='-10' not found")
 
 
 
-- 
GitLab