def test_parse_aliases(self): parser = make_configparser(""" [aliases] first = app-* job-* second = none """) aliases = parse_aliases(parser) self.assertEqual(aliases, {"first": ["app-*", "job-*"], "second": ["none"]})
def test_default(self): parser = make_configparser(""" [section] """) config = rollingpin.config.coerce_and_validate_config(parser, { "section": { "key": rollingpin.config.Option(int, default=3), }, }) self.assertEqual(config["section"]["key"], 3)
def test_parse_aliases(self): parser = make_configparser(""" [aliases] first = app-* job-* second = none """) aliases = parse_aliases(parser) self.assertEqual(aliases, { "first": ["app-*", "job-*"], "second": ["none"] })
def test_optional_section_present(self): parser = make_configparser(""" [optional-section] key = value """) config = rollingpin.config.coerce_and_validate_config(parser, { "optional-section": rollingpin.config.OptionalSection({ "key": rollingpin.config.Option(str, default=None), }) }) self.assertEqual(config["optional-section"]["key"], "value")
def setUp(self): self.parser = make_configparser(""" [section] int = 42 str = this is a test """) self.spec = { "section": { "int": rollingpin.config.Option(int), "str": rollingpin.config.Option(str), }, }
def test_missing_key(self): parser = ConfigParser.ConfigParser() parser = make_configparser(""" [section] other = not what we want """) with self.assertRaises(rollingpin.config.ConfigurationError) as info: rollingpin.config.coerce_and_validate_config(parser, { "section": { "key": rollingpin.config.Option(str), }, }) errors = info.exception.errors self.assertEqual(len(errors), 1) self.assertIsInstance(errors[0], rollingpin.config.MissingItemError)
def test_no_aliases(self): section_only = make_configparser("[aliases]") aliases = parse_aliases(section_only) self.assertEqual(aliases, {})