def test_get_option(self): """Test `get_option` function.""" with self.assertRaises(ValueError): get_option('no_existing_option') option_name = list(CONFIG_OPTIONS)[0] option = get_option(option_name) self.assertIsInstance(option, Option) self.assertEqual(option.name, option_name)
def test_get_option(self): """Test `get_option` function.""" with self.assertRaises(ConfigurationError): get_option('no_existing_option') option_name = get_option_names()[0] option = get_option(option_name) self.assertIsInstance(option, Option) self.assertEqual(option.name, option_name)
def convert(self, value, param, ctx): from aiida.manage.configuration.options import get_option, get_option_names if value not in get_option_names(): raise click.BadParameter('{} is not a valid configuration option'.format(value)) return get_option(value)
def test_get_config_option_default(self): """Tests that `get_option` return option default if not specified globally or for current profile.""" option_name = 'logging.aiida_loglevel' option = get_option(option_name) # If we haven't set the option explicitly, `get_config_option` should return the option default option_value = get_config_option(option_name) self.assertEqual(option_value, option.default)
def test_options(self): """Test that all defined options can be converted into Option namedtuples.""" for option_name in get_option_names(): option = get_option(option_name) self.assertEqual(option.name, option_name) self.assertIsInstance(option.description, str) option.valid_type # pylint: disable=pointless-statement option.default # pylint: disable=pointless-statement
def test_options(self): """Test that all defined options can be converted into Option namedtuples.""" for option_name, set_optiontings in CONFIG_OPTIONS.items(): option = get_option(option_name) self.assertEqual(option.name, option_name) self.assertEqual(option.key, set_optiontings['key']) self.assertEqual(option.valid_type, set_optiontings['valid_type']) self.assertEqual(option.valid_values, set_optiontings['valid_values']) self.assertEqual(option.default, set_optiontings['default']) self.assertEqual(option.description, set_optiontings['description'])
def test_option(self): """Test the setter, unsetter and getter of configuration options.""" option_value = 131 option_name = 'daemon.timeout' option = get_option(option_name) config = Config(self.config_filepath, self.config_dictionary) # Getting option that does not exist, should simply return the option default self.assertEqual(config.get_option(option_name, scope=self.profile_name), option.default) self.assertEqual(config.get_option(option_name, scope=None), option.default) # Unless we set default=False, in which case it should return None self.assertEqual(config.get_option(option_name, scope=self.profile_name, default=False), None) self.assertEqual(config.get_option(option_name, scope=None, default=False), None) # Setting an option profile configuration wide config.set_option(option_name, option_value) # Getting configuration wide should get new value but None for profile specific self.assertEqual(config.get_option(option_name, scope=None, default=False), option_value) self.assertEqual(config.get_option(option_name, scope=self.profile_name, default=False), None) # Setting an option profile specific config.set_option(option_name, option_value, scope=self.profile_name) self.assertEqual(config.get_option(option_name, scope=self.profile_name), option_value) # Unsetting profile specific config.unset_option(option_name, scope=self.profile_name) self.assertEqual(config.get_option(option_name, scope=self.profile_name, default=False), None) # Unsetting configuration wide config.unset_option(option_name, scope=None) self.assertEqual(config.get_option(option_name, scope=None, default=False), None) self.assertEqual(config.get_option(option_name, scope=None, default=True), option.default) # Setting a `None` like option option_value = 0 config.set_option(option_name, option_value) self.assertEqual(config.get_option(option_name, scope=None, default=False), option_value)