def setUpClass(cls): cls.xdg_config_home = os.environ.get("XDG_CONFIG_HOME") cls.tmpdir = tempfile.mkdtemp() os.mkdir(os.path.join(cls.tmpdir, "yt")) os.environ["XDG_CONFIG_HOME"] = cls.tmpdir with open(YTConfig.get_global_config_file(), mode="w") as fh: fh.write(_DUMMY_CFG_TOML) cls.plugin_path = os.path.join(config_dir(), ytcfg.get("yt", "plugin_filename")) with open(cls.plugin_path, mode="w") as fh: fh.write(TEST_PLUGIN_FILE)
def testConfigCommands(self): def remove_spaces_and_breaks(s): return "".join(s.split()) self.assertFalse(os.path.exists(YTConfig.get_global_config_file())) info = self._runYTConfig(["--help"]) self.assertEqual(info["rc"], 0) self.assertEqual(info["stderr"], "") self.assertIn( remove_spaces_and_breaks("Get and set configuration values for yt"), remove_spaces_and_breaks(info["stdout"]), ) info = self._runYTConfig(["list"]) self.assertEqual(info["rc"], 0) self.assertEqual(info["stdout"], "") self._testKeyValue("internals.parallel", True, True) self._testKeyValue( "test_data_dir", "~/yt-data", os.path.expanduser("~/yt-data") ) self._testKeyValue( "test_data_dir", "$HOME/yt-data", os.path.expandvars("$HOME/yt-data") ) with self.assertRaises(KeyError): self._runYTConfig(["get", "yt", "foo"]) # Check TypeErrors are raised when changing the type of an entry self._testKeyTypeError("foo.bar", "test", 10, expect_error=True) self._testKeyTypeError("foo.bar", "test", False, expect_error=True) # Check no type error are raised when *not* changing the type self._testKeyTypeError("foo.bar", 10, 20, expect_error=False) self._testKeyTypeError("foo.bar", "foo", "bar", expect_error=False)
parallel=False, strict_requires=False, global_parallel_rank=0, global_parallel_size=1, topcomm_parallel_rank=0, topcomm_parallel_size=1, command_line=False, ), ) # For backward compatibility, do not use these vars internally in yt CONFIG_DIR = config_dir() _global_config_file = YTConfig.get_global_config_file() _local_config_file = YTConfig.get_local_config_file() # Load the config ytcfg = YTConfig() ytcfg.update(ytcfg_defaults, metadata={"source": "defaults"}) # Try loading the local config first, otherwise fall back to global config if os.path.exists(_local_config_file): ytcfg.read(_local_config_file) elif os.path.exists(_global_config_file): ytcfg.read(_global_config_file) def _setup_postinit_configuration(): """This is meant to be run last in yt.__init__"""
def setUp(self): super().setUp() with open(YTConfig.get_local_config_file(), mode="w") as f: f.writelines("[yt]\n") with open(YTConfig.get_global_config_file(), mode="w") as f: f.writelines("[yt]\n")
def tearDown(self): if os.path.exists(YTConfig.get_global_config_file()): os.remove(YTConfig.get_global_config_file()) super().tearDown()