From eca70404c03dbe289dcbfaf67430a4d46ecee414 Mon Sep 17 00:00:00 2001
From: "Mads M. Pedersen" <mmpe@dtu.dk>
Date: Fri, 4 May 2018 12:05:36 +0200
Subject: [PATCH] ignore fuga test if lib missing

---
 tests/test_fuga/test_pyfuga.py      |  4 ++++
 topfarm/cost_models/fuga/py_fuga.py | 16 ++++++++++------
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/tests/test_fuga/test_pyfuga.py b/tests/test_fuga/test_pyfuga.py
index aaa304cf..2053c33f 100644
--- a/tests/test_fuga/test_pyfuga.py
+++ b/tests/test_fuga/test_pyfuga.py
@@ -45,12 +45,14 @@ class Test(unittest.TestCase):
                       farms_dir=fuga_path + 'LUT/Farms/', wind_atlas_path='Horns Rev 1/hornsrev_north_only.lib', climate_interpolation=False)
 
     def testCheckVersion(self):
+        if self.lib_missing(): return
         lib = PascalDLL(fuga_path + "FugaLib/FugaLib.%s" % ('so', 'dll')[os.name == 'nt'])
         self.assertRaisesRegex(Exception, "This version of FugaLib supports interface version ", lib.CheckInterfaceVersion, 1)
         pyFuga = self.get_fuga()  # check that current interface version match
         pyFuga.cleanup()
 
     def testSetup(self):
+        if self.lib_missing(): return
         pyFuga = self.get_fuga()
         self.assertEqual(pyFuga.get_no_tubines(), 2)
         self.assertIn("Loading", pyFuga.log)
@@ -61,11 +63,13 @@ class Test(unittest.TestCase):
         pyFuga.cleanup()
 
     def testAEP_one_tb(self):
+        if self.lib_missing(): return
         pyFuga = self.get_fuga([0], [0])
         np.testing.assert_array_almost_equal(pyFuga.get_aep(np.array([[0], [0]]).T), [7.44121, 7.44121, 0.424962, 1.])
         pyFuga.cleanup()
 
     def testAEP(self):
+        if self.lib_missing(): return
         pyFuga = self.get_fuga()
 
         np.testing.assert_array_almost_equal(pyFuga.get_aep(np.array([[0, 200], [0, 0]]).T), [14.848055, 14.882419, 0.423981, 0.997691])
diff --git a/topfarm/cost_models/fuga/py_fuga.py b/topfarm/cost_models/fuga/py_fuga.py
index a026b8ff..b9a3d55d 100644
--- a/topfarm/cost_models/fuga/py_fuga.py
+++ b/topfarm/cost_models/fuga/py_fuga.py
@@ -31,8 +31,12 @@ class PyFuga(object):
         atexit.register(self.cleanup)
         with NamedTemporaryFile() as f:
             self.stdout_filename = f.name + "pyfuga.txt"
-            
-        self.lib = PascalDLL(os.path.dirname(__file__) + "/Colonel/FugaLib/FugaLib.%s" % ('so', 'dll')[os.name == 'nt'])
+
+        lib_path = os.path.dirname(__file__) + "/Colonel/FugaLib/FugaLib.%s" % ('so', 'dll')[os.name == 'nt']
+        if os.path.isfile(lib_path):
+            raise Exception("Fuga lib cannot be found: '%s'" % lib_path)
+
+        self.lib = PascalDLL(lib_path)
         self.lib.CheckInterfaceVersion(self.interface_version)
         self.lib.Setup(self.stdout_filename, float(mast_position[0]), float(mast_position[1]), float(mast_position[2]),
                        float(z0), float(zi), float(zeta0))
@@ -93,8 +97,8 @@ class PyFuga(object):
 
     def get_aep(self, turbine_positions=None):
         if turbine_positions is not None:
-            self.move_turbines(turbine_positions[:,0], turbine_positions[:,1])
-        
+            self.move_turbines(turbine_positions[:, 0], turbine_positions[:, 1])
+
         AEPNet_p = c_double_p(c_double(0))
         AEPGros_p = c_double_p(c_double(0))
         capacity_p = c_double_p(c_double(0))
@@ -105,8 +109,8 @@ class PyFuga(object):
 
     def get_aep_gradients(self, turbine_positions=None):
         if turbine_positions is not None:
-            self.move_turbines(turbine_positions[:,0], turbine_positions[:,1])
-    
+            self.move_turbines(turbine_positions[:, 0], turbine_positions[:, 1])
+
         n_wt = self.get_no_tubines()
         dAEPdxyz = np.zeros(n_wt), np.zeros(n_wt), np.zeros(n_wt)
         dAEPdxyz_ctype = [dAEP.ctypes for dAEP in dAEPdxyz]
-- 
GitLab