def setUp(self): self.current_dir_output = None if self.reset_env: env.reset() if self.create_dir: self.current_dir_output = self.get_temporary_output_directory() env.DIR_OUTPUT = self.current_dir_output
def setUp(self): if self._reset_env: env.reset() if self._create_dir: self._test_dir = tempfile.mkdtemp(prefix='ocgis_test_') env.DIR_OUTPUT = self._test_dir else: self._create_dir = None
def test_np_int(self): try: self.assertEqual(env.NP_INT, env.NP_INT) env.NP_INT = np.int16 self.assertEqual(env.NP_INT, np.int16) finally: env.reset()
def _run_(): ocgis_lh.configure() self.assertTrue(ocgis_lh.null) env.SUPPRESS_WARNINGS = True ocgis_lh(level=logging.WARNING, exc=RuntimeWarning('show me'), force=True) env.reset()
def test_reset(self): # Test netCDF MPI is reset appropriately. if env.USE_NETCDF4_MPI: raise SkipTest("requires a non-netcdf4 parallel environment") env.USE_NETCDF4_MPI = True self.assertTrue(env.USE_NETCDF4_MPI) env.reset() self.assertFalse(env.USE_NETCDF4_MPI)
def test_reference_projection(self): self.assertIsInstance(env.REFERENCE_PROJECTION,WGS84) ## the reference projection must be set at runtime. os.environ['OCGIS_REFERENCE_PROJECTION'] = 'foo' with self.assertRaises(OcgisEnvironmentError): env.reset() os.environ.pop('OCGIS_REFERENCE_PROJECTION')
def test_np_float(self): try: self.assertEqual(env.NP_FLOAT, env.NP_FLOAT) env.NP_FLOAT = np.int16 self.assertEqual(env.NP_FLOAT, np.int16) finally: env.reset() self.assertEqual(env.NP_FLOAT, constants.DEFAULT_NP_FLOAT)
def test_reference_projection(self): self.assertIsInstance(env.REFERENCE_PROJECTION, WGS84) ## the reference projection must be set at runtime. os.environ['OCGIS_REFERENCE_PROJECTION'] = 'foo' with self.assertRaises(OcgisEnvironmentError): env.reset() os.environ.pop('OCGIS_REFERENCE_PROJECTION')
def test_netcdf_file_format(self): try: self.assertEqual(env.NETCDF_FILE_FORMAT, constants.NETCDF_DEFAULT_DATA_MODEL) self.assertEqual(env.NP_INT, env.NP_INT) actual = 'NETCDF3_CLASSIC' env.NETCDF_FILE_FORMAT = actual finally: env.reset()
def tearDown(self): try: if self.create_dir: shutil.rmtree(self.current_dir_output) finally: if self.reset_env: env.reset() if self.shutdown_logging: ocgis_lh.shutdown()
def test_import_attributes(self): ## with both modules installed, these are expected to be true self.assertEqual(env.USE_CFUNITS,self.get_is_available('cfunits')) self.assertEqual(env.USE_SPATIAL_INDEX,self.get_is_available('rtree')) ## turn off the spatial index env.USE_SPATIAL_INDEX = False self.assertEqual(env.USE_SPATIAL_INDEX,False) env.reset() self.assertEqual(env.USE_SPATIAL_INDEX,self.get_is_available('rtree'))
def test_init(self): self.assertIsNone(env.MELTED) self.assertEqual(env.DEFAULT_GEOM_UID, constants.OCGIS_UNIQUE_GEOMETRY_IDENTIFIER) self.assertEqual(env.NETCDF_FILE_FORMAT, constants.NETCDF_DEFAULT_DATA_MODEL) self.assertEqual(env.NP_INT, env.NP_INT) self.assertEqual(env.NP_FLOAT, env.NP_FLOAT) self.assertIsInstance(env.USE_NETCDF4_MPI, bool) env.reset() self.assertIsInstance(env.USE_NETCDF4_MPI, bool)
def test_env_overload(self): # check env overload out = tempfile.mkdtemp() try: env.DIR_OUTPUT = out env.PREFIX = 'my_prefix' rd = self.test_data.get_rd('daymet_tmax') ops = OcgOperations(dataset=rd, snippet=True) self.assertEqual(env.DIR_OUTPUT, ops.dir_output) self.assertEqual(env.PREFIX, ops.prefix) finally: os.rmdir(out) env.reset()
def test_import_attributes_overloaded(self): try: import rtree av = True except ImportError: av = False self.assertEqual(env.USE_SPATIAL_INDEX, av) os.environ['OCGIS_USE_SPATIAL_INDEX'] = 'False' env.reset() self.assertFalse(env.USE_SPATIAL_INDEX) os.environ['OCGIS_USE_SPATIAL_INDEX'] = 't' env.reset() self.assertTrue(env.USE_SPATIAL_INDEX) # this cannot be transformed into a boolean value, and it is also not a realistic module name, so it will # evaluate to false os.environ['OCGIS_USE_SPATIAL_INDEX'] = 'False' env.reset() self.assertFalse(env.USE_SPATIAL_INDEX) os.environ['OCGIS_USE_SPATIAL_INDEX'] = 'f' env.reset() self.assertFalse(env.USE_SPATIAL_INDEX)
def test_simple(self): self.assertEqual(env.OVERWRITE, False) env.reset() os.environ['OCGIS_OVERWRITE'] = 't' self.assertEqual(env.OVERWRITE, True) env.OVERWRITE = False self.assertEqual(env.OVERWRITE, False) with self.assertRaises(AttributeError): env.FOO = 1 env.OVERWRITE = True self.assertEqual(env.OVERWRITE, True) env.reset() os.environ.pop('OCGIS_OVERWRITE') self.assertEqual(env.OVERWRITE, False)
def test_import_attributes(self): try: # With both modules installed, these are expected to be true. self.assertEqual(env.USE_CFUNITS, self.get_is_available('cf_units')) except AssertionError: # Try the other unit conversion library. self.assertEqual(env.USE_CFUNITS, self.get_is_available('cfunits')) self.assertEqual(env.USE_SPATIAL_INDEX, self.get_is_available('rtree')) # Turn off the spatial index. env.USE_SPATIAL_INDEX = False self.assertEqual(env.USE_SPATIAL_INDEX, False) env.reset() self.assertEqual(env.USE_SPATIAL_INDEX, self.get_is_available('rtree'))
def __iter__(self): its = [p().__iter__() for p in self.get_parameters()] for ii,values in enumerate(itertools.product(*its)): if self.n_only: yield(ii) continue if self.target_combo is not None: if self.target_combo > ii: continue yield(ii) kwds = {} for val in values: ## check for environmental parameters if val.keys()[0].isupper(): setattr(env,val.keys()[0],val.values()[0]) else: kwds.update(val) if not self.ops_only: kwds.update({'dir_output':tempfile.mkdtemp()}) try: try: ops = OcgOperations(**kwds) try: self.check_blocked(ops) except BlockedCombination: continue if self.verbose: print(ii) if self.ops_only: pass else: ret = ops.execute() except Exception as e: raise tb = traceback.format_exc() try: self.check_exception(ii,kwds,e,tb) except: raise finally: if not self.ops_only and self.remove_output: shutil.rmtree(kwds['dir_output']) env.reset()
def __iter__(self): its = [p().__iter__() for p in self.get_parameters()] for ii, values in enumerate(itertools.product(*its)): if self.n_only: yield (ii) continue if self.target_combo is not None: if self.target_combo > ii: continue yield (ii) kwds = {} for val in values: ## check for environmental parameters if val.keys()[0].isupper(): setattr(env, val.keys()[0], val.values()[0]) else: kwds.update(val) if not self.ops_only: kwds.update({'dir_output': tempfile.mkdtemp()}) try: try: ops = OcgOperations(**kwds) try: self.check_blocked(ops) except BlockedCombination: continue if self.verbose: print(ii) if self.ops_only: pass else: ret = ops.execute() except Exception as e: raise tb = traceback.format_exc() try: self.check_exception(ii, kwds, e, tb) except: raise finally: if not self.ops_only and self.remove_output: shutil.rmtree(kwds['dir_output']) env.reset()
def test_reset(self): # Test netCDF MPI is reset appropriately. env.USE_NETCDF4_MPI = True self.assertTrue(env.USE_NETCDF4_MPI) env.reset() self.assertFalse(env.USE_NETCDF4_MPI)
def setUp(self): env.reset() self._new_dir = tempfile.mkdtemp(prefix='ocgis_test_',dir=env.DIR_OUTPUT) env.DIR_OUTPUT = self._new_dir env.OVERWRITE = True
def tearDown(self): try: shutil.rmtree(self._new_dir) finally: env.reset()
def setUp(self): env.reset() self._new_dir = tempfile.mkdtemp(prefix='ocgis_test_', dir=env.DIR_OUTPUT) env.DIR_OUTPUT = self._new_dir env.OVERWRITE = True
def tearDown(self): try: if self._create_dir: shutil.rmtree(self._test_dir) finally: if self._reset_env: env.reset()