climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject svn commit: r1523013 - /incubator/climate/trunk/ocw/tests/
Date Fri, 13 Sep 2013 16:57:46 GMT
Author: joyce
Date: Fri Sep 13 16:57:46 2013
New Revision: 1523013

CLIMATE-297 - Fix test_local breaking if run outside of tests directory

- This is a pretty hacky way of fixing this problem. It uses the inspect
  module to get the location of the test_local module (which we also
  have to import in test_local, which is hideous). The path is then
  manipulated so that it points to the /trunk/examples folder. So, it
  doesn't break if you run outside of the tests folder but it does
  depend on the repo layout present at Apache. Ultimately, the outside
  dependencies should be removed if possible.


Modified: incubator/climate/trunk/ocw/tests/
--- incubator/climate/trunk/ocw/tests/ (original)
+++ incubator/climate/trunk/ocw/tests/ Fri Sep 13 16:57:46 2013
@@ -21,6 +21,8 @@ import as ma
 import os
 import netCDF4
 import datetime
+import inspect
+import test_local # Import test_local so we can use inspect to get the path 
 import ocw.data_source.local as local
@@ -62,8 +64,11 @@ class test_load_file(unittest.TestCase):
         self.assertTrue(numpy.allclose(local.load_file(self.file_path, "value").values, new_values))
 class test_get_netcdf_variable_names(unittest.TestCase):
+    path_leader = inspect.getfile(test_local).split('ocw/')
     def setUp(self):
-        self.netcdf_path = os.path.abspath("../../examples/")
+        file_path = os.path.join(self.path_leader[0], "examples/")
+        self.netcdf_path = os.path.abspath(file_path)
         self.invalid_netcdf_path = create_invalid_dimensions_netcdf_object()
         self.netcdf = netCDF4.Dataset(self.netcdf_path, mode='r')

View raw message