mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-23 18:50:24 +00:00
Some further test_configutil improvements
This commit is contained in:
parent
34714d5f6b
commit
021615bdff
@ -128,13 +128,15 @@ enabled = false
|
|||||||
self.failUnlessEqual(config.get("node", "descriptor"), descriptor)
|
self.failUnlessEqual(config.get("node", "descriptor"), descriptor)
|
||||||
|
|
||||||
def test_config_validation_success(self):
|
def test_config_validation_success(self):
|
||||||
fname = self.create_tahoe_cfg('[node]\nvalid = foo\n')
|
"""
|
||||||
|
``configutil.validate_config`` returns ``None`` when the configuration it
|
||||||
config = configutil.get_config(fname)
|
is given has nothing more than the static sections and items defined
|
||||||
|
by the validator.
|
||||||
|
"""
|
||||||
# should succeed, no exceptions
|
# should succeed, no exceptions
|
||||||
configutil.validate_config(
|
configutil.validate_config(
|
||||||
fname,
|
"<test_config_validation_success>",
|
||||||
config,
|
to_configparser({"node": {"valid": "foo"}}),
|
||||||
self.static_valid_config,
|
self.static_valid_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -144,24 +146,20 @@ enabled = false
|
|||||||
validation but are matched by the dynamic validation is considered
|
validation but are matched by the dynamic validation is considered
|
||||||
valid.
|
valid.
|
||||||
"""
|
"""
|
||||||
fname = self.create_tahoe_cfg('[node]\nvalid = foo\n')
|
|
||||||
|
|
||||||
config = configutil.get_config(fname)
|
|
||||||
# should succeed, no exceptions
|
# should succeed, no exceptions
|
||||||
configutil.validate_config(
|
configutil.validate_config(
|
||||||
fname,
|
"<test_config_dynamic_validation_success>",
|
||||||
config,
|
to_configparser({"node": {"valid": "foo"}}),
|
||||||
self.dynamic_valid_config,
|
self.dynamic_valid_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_config_validation_invalid_item(self):
|
def test_config_validation_invalid_item(self):
|
||||||
fname = self.create_tahoe_cfg('[node]\nvalid = foo\ninvalid = foo\n')
|
config = to_configparser({"node": {"valid": "foo", "invalid": "foo"}})
|
||||||
|
|
||||||
config = configutil.get_config(fname)
|
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
configutil.UnknownConfigError,
|
configutil.UnknownConfigError,
|
||||||
configutil.validate_config,
|
configutil.validate_config,
|
||||||
fname, config,
|
"<test_config_validation_invalid_item>",
|
||||||
|
config,
|
||||||
self.static_valid_config,
|
self.static_valid_config,
|
||||||
)
|
)
|
||||||
self.assertIn("section [node] contains unknown option 'invalid'", str(e))
|
self.assertIn("section [node] contains unknown option 'invalid'", str(e))
|
||||||
@ -171,13 +169,12 @@ enabled = false
|
|||||||
A configuration with a section that is matched by neither the static nor
|
A configuration with a section that is matched by neither the static nor
|
||||||
dynamic validators is rejected.
|
dynamic validators is rejected.
|
||||||
"""
|
"""
|
||||||
fname = self.create_tahoe_cfg('[node]\nvalid = foo\n[invalid]\n')
|
config = to_configparser({"node": {"valid": "foo"}, "invalid": {}})
|
||||||
|
|
||||||
config = configutil.get_config(fname)
|
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
configutil.UnknownConfigError,
|
configutil.UnknownConfigError,
|
||||||
configutil.validate_config,
|
configutil.validate_config,
|
||||||
fname, config,
|
"<test_config_validation_invalid_section>",
|
||||||
|
config,
|
||||||
self.static_valid_config,
|
self.static_valid_config,
|
||||||
)
|
)
|
||||||
self.assertIn("contains unknown section [invalid]", str(e))
|
self.assertIn("contains unknown section [invalid]", str(e))
|
||||||
@ -187,13 +184,12 @@ enabled = false
|
|||||||
A configuration with a section that is matched by neither the static nor
|
A configuration with a section that is matched by neither the static nor
|
||||||
dynamic validators is rejected.
|
dynamic validators is rejected.
|
||||||
"""
|
"""
|
||||||
fname = self.create_tahoe_cfg('[node]\nvalid = foo\n[invalid]\n')
|
config = to_configparser({"node": {"valid": "foo"}, "invalid": {}})
|
||||||
|
|
||||||
config = configutil.get_config(fname)
|
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
configutil.UnknownConfigError,
|
configutil.UnknownConfigError,
|
||||||
configutil.validate_config,
|
configutil.validate_config,
|
||||||
fname, config,
|
"<test_config_dynamic_validation_invalid_section>",
|
||||||
|
config,
|
||||||
self.dynamic_valid_config,
|
self.dynamic_valid_config,
|
||||||
)
|
)
|
||||||
self.assertIn("contains unknown section [invalid]", str(e))
|
self.assertIn("contains unknown section [invalid]", str(e))
|
||||||
@ -203,13 +199,12 @@ enabled = false
|
|||||||
A configuration with a section, item pair that is matched by neither the
|
A configuration with a section, item pair that is matched by neither the
|
||||||
static nor dynamic validators is rejected.
|
static nor dynamic validators is rejected.
|
||||||
"""
|
"""
|
||||||
fname = self.create_tahoe_cfg('[node]\nvalid = foo\ninvalid = foo\n')
|
config = to_configparser({"node": {"valid": "foo", "invalid": "foo"}})
|
||||||
|
|
||||||
config = configutil.get_config(fname)
|
|
||||||
e = self.assertRaises(
|
e = self.assertRaises(
|
||||||
configutil.UnknownConfigError,
|
configutil.UnknownConfigError,
|
||||||
configutil.validate_config,
|
configutil.validate_config,
|
||||||
fname, config,
|
"<test_config_dynamic_validation_invalid_item>",
|
||||||
|
config,
|
||||||
self.dynamic_valid_config,
|
self.dynamic_valid_config,
|
||||||
)
|
)
|
||||||
self.assertIn("section [node] contains unknown option 'invalid'", str(e))
|
self.assertIn("section [node] contains unknown option 'invalid'", str(e))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user