def setUp(self, verbose=0): util_mdtf.check_required_dirs( already_exist=[], create_if_nec=[self.MODEL_WK_DIR, self.MODEL_DATA_DIR], verbose=verbose) self.envvars.update({ "DATADIR": self.MODEL_DATA_DIR, "variab_dir": self.MODEL_WK_DIR, "CASENAME": self.case_name, "model": self.model_name, "FIRSTYR": self.firstyr.format(precision=1), "LASTYR": self.lastyr.format(precision=1) }) # set env vars for unit conversion factors (TODO: honest unit conversion) translate = util_mdtf.VariableTranslator() if self.convention not in translate.units: raise AssertionError( ("Variable name translation doesn't recognize " "{}.").format(self.convention)) temp = translate.variables[self.convention].to_dict() for key, val in iter(temp.items()): util_mdtf.setenv(key, val, self.envvars, verbose=verbose) temp = translate.units[self.convention].to_dict() for key, val in iter(temp.items()): util_mdtf.setenv(key, val, self.envvars, verbose=verbose) for pod in self.iter_pods(): self._setup_pod(pod) self._build_data_dicts()
def test_check_required_dirs_not_found_created(self, mock_makedirs, mock_exists): # don't exit() and call os.makedirs if in create_if_nec try: util.check_required_dirs([], ['DIR2']) except SystemExit: self.fail() mock_makedirs.assert_called_once_with('DIR2')
def test_check_required_dirs_found(self, mock_makedirs, mock_exists): # exit function normally if all directories found try: util.check_required_dirs(['DIR1'], []) util.check_required_dirs([], ['DIR2']) except SystemExit: self.fail() mock_makedirs.assert_not_called()
def verify_paths(self, config): # clean out WORKING_DIR if we're not keeping temp files if os.path.exists(config.paths.WORKING_DIR) and not \ (config.config.get('keep_temp', False) \ or config.paths.WORKING_DIR == config.paths.OUTPUT_DIR): shutil.rmtree(config.paths.WORKING_DIR) util_mdtf.check_required_dirs( already_exist=[config.paths.CODE_ROOT, config.paths.OBS_DATA_ROOT], create_if_nec=[ config.paths.MODEL_DATA_ROOT, config.paths.WORKING_DIR, config.paths.OUTPUT_DIR ])
def _setup_pod_directories(self, verbose=0): """Private method called by :meth:`~shared_diagnostic.Diagnostic.setUp`. Args: verbose (:py:obj:`int`, optional): Logging verbosity level. Default 0. """ util_mdtf.check_required_dirs( already_exist=[self.POD_CODE_DIR, self.POD_OBS_DATA], create_if_nec=[self.POD_WK_DIR], verbose=verbose) dirs = [ '', 'model', 'model/PS', 'model/netCDF', 'obs', 'obs/PS', 'obs/netCDF' ] for d in dirs: if not os.path.exists(os.path.join(self.POD_WK_DIR, d)): os.makedirs(os.path.join(self.POD_WK_DIR, d))
def verify_paths(self, config): # clean out WORKING_DIR if we're not keeping temp files if os.path.exists(config.paths.WORKING_DIR) and not \ (config.config.get('keep_temp', False) \ or config.paths.WORKING_DIR == config.paths.OUTPUT_DIR): shutil.rmtree(config.paths.WORKING_DIR) util_mdtf.check_required_dirs(already_exist=[ config.paths.CODE_ROOT, config.paths.OBS_DATA_REMOTE ], create_if_nec=[ config.paths.MODEL_DATA_ROOT, config.paths.WORKING_DIR, config.paths.OBS_DATA_ROOT ]) # Use GCP to create OUTPUT_DIR on a volume that may be read-only if not os.path.exists(config.paths.OUTPUT_DIR): gfdl.make_remote_dir(config.paths.OUTPUT_DIR, self.timeout, self.dry_run)