def test_config_vals_match_properties_in_wrapper(self): with TemporaryDirectory() as td: self.config_inst.cfg_dir = td self.assertEqual(self.config_inst.cfg_dir, td) from pyemma import config as config_module assert hasattr(config_module, 'default_config_file') my_cfg = os.path.join(td, 'pyemma.cfg') self.assertEqual(pkg_resources.resource_filename('pyemma', 'pyemma.cfg'), config_module.default_config_file) reader = configparser.ConfigParser() reader.read(my_cfg) opts = sorted(reader.options('pyemma')) actual = sorted(config_module.keys()) self.assertEqual(opts, actual)
def settings(**kwargs): """ apply given PyEMMA config values temporarily within the given context.""" from pyemma import config # validate: valid_keys = config.keys() for k in kwargs.keys(): if k not in valid_keys: raise ValueError("not a valid settings: {key}".format(key=k)) old_settings = {} for k, v in kwargs.items(): old_settings[k] = getattr(config, k) setattr(config, k, v) yield # restore old settings for k, v in old_settings.items(): setattr(config, k, v)