def setUpModule(): for cfgfile in (GLOBAL_CONFIG_FILE, OLD_CONFIG_FILE, LOCAL_CONFIG_FILE): if os.path.exists(cfgfile): os.rename(cfgfile, cfgfile + ".bak_test") if cfgfile == GLOBAL_CONFIG_FILE: yt.utilities.configure.CONFIG = YTConfig() if not yt.utilities.configure.CONFIG.has_section("yt"): yt.utilities.configure.CONFIG.add_section("yt")
import configparser import os import sys from yt.config import YTConfig, old_config_file, ytcfg_defaults CONFIG = YTConfig() def _cast_bool_helper(value): if value == "True": return True elif value == "False": return False else: raise ValueError("Cannot safely cast to bool") def _expand_all(s): return os.path.expandvars(os.path.expanduser(s)) def _cast_value_helper(value, types=(_cast_bool_helper, int, float, _expand_all)): for t in types: try: retval = t(value) return retval except ValueError: pass