def test_invalid_line(self): self.tmpfile.write('justkey\n'.encode('utf8')) self.tmpfile.flush() assert_raises( errors.ConfigurationError, loader.PropertiesConfiguration, self.tmpfile.name)
def test_build_loader_optional(self): err_msg = "Failed to do" loader_func = mock.Mock() loader_func.side_effect = ValueError(err_msg) config_loader = loader.build_loader(loader_func) config_loader(optional=True) assert_raises(ValueError, config_loader)
def test_read_config_failed(self): self.namespace.get.return_value = proxy.UndefToken assert_raises( errors.ConfigurationError, readers._read_config, 'some_key', self.namespace, None)
def test_mock_configuration_context_manager(self): one = self.getters.get('one') three = self.getters.get_int('three', default=3) with testing.MockConfiguration(dict(one=7), namespace=self.namespace): assert_equal(one, 7) assert_equal(three, 3) assert_raises(errors.ConfigurationError, self.getters.get('one'))
def test_has_duplicate_keys_raises(self): config_data = dict(fear=123) assert_raises( errors.ConfigurationError, config.has_duplicate_keys, config_data, self.base_conf, True)
def test_validate_value_token(self): class ExampleSchema(schema.Schema): namespace = 'DEFAULT' thing = schema.int() assert_raises(errors.ConfigurationError, config.validate, all_names=True)
def test_mock_configuration(self): two = self.getters.get_string('two') stars = self.getters.get_bool('stars') mock_config = testing.MockConfiguration( dict(two=2, stars=False), namespace=self.namespace) mock_config.setup() assert_equal(two, '2') assert not stars mock_config.teardown() assert_raises(errors.ConfigurationError, self.getters.get('two'))
def test_xml_configuration_safe_value_tag(self): content = """ <config> <sometag value="snazz">E</sometag> </config> """ self.write_content_to_file(content) assert_raises(errors.ConfigurationError, loader.XMLConfiguration, self.tmpfile.name, safe=True)
def test_mock_configuration(self): two = self.getters.get_string('two') stars = self.getters.get_bool('stars') mock_config = testing.MockConfiguration(dict(two=2, stars=False), namespace=self.namespace) mock_config.setup() assert_equal(two, '2') assert not stars mock_config.teardown() assert_raises(errors.ConfigurationError, self.getters.get('two'))
def test_xml_configuration_safe_value_tag(self): content = """ <config> <sometag value="snazz">E</sometag> </config> """ self.write_content_to_file(content) assert_raises( errors.ConfigurationError, loader.XMLConfiguration, self.tmpfile.name, safe=True)
def test_xml_configuration_safe_override(self): content = """ <config> <sometag foo="bar"> <foo>E</foo> </sometag> </config> """ self.write_content_to_file(content) assert_raises(errors.ConfigurationError, loader.XMLConfiguration, self.tmpfile.name, safe=True)
def test_xml_configuration_safe_override(self): content = """ <config> <sometag foo="bar"> <foo>E</foo> </sometag> </config> """ self.write_content_to_file(content) assert_raises( errors.ConfigurationError, loader.XMLConfiguration, self.tmpfile.name, safe=True)
def test_get_namespace_missing(self, meta_schema): meta, _, _ = meta_schema assert_raises(errors.ConfigurationError, meta.get_namespace, {})
def test_auto_failed(self): assert_raises(errors.ConfigurationError, loader.AutoConfiguration)
def test_read_config_failed(self): self.namespace.get.return_value = proxy.UndefToken assert_raises(errors.ConfigurationError, readers._read_config, 'some_key', self.namespace, None)
def test_validate_keys_unknown_raise(self): assert_raises(errors.ConfigurationError, self.namespace.validate_keys, self.config_data, True)
def test_validate_all_fails(self): name = 'yan' _ = staticconf.get_string('foo', namespace=name) # flake8: noqa assert_raises(errors.ConfigurationError, config.validate, all_names=True)
def test_invalid_line(self): self.tmpfile.write('justkey\n'.encode('utf8')) self.tmpfile.flush() assert_raises(errors.ConfigurationError, loader.PropertiesConfiguration, self.tmpfile.name)
def test_validate_all_fails(self): name = 'yan' _ = staticconf.get_string('foo', namespace=name) # noqa: F841 assert_raises(errors.ConfigurationError, config.validate, all_names=True)
def test_validate_single_fails(self): _ = staticconf.get_int('one.two') # noqa: F841 assert_raises(errors.ConfigurationError, config.validate)
def test_validate_single_fails(self): _ = staticconf.get_int('one.two') assert_raises(errors.ConfigurationError, config.validate)