Esempio n. 1
0
    def test_all_config_errors(self):
        schema = ConfigSchema(self._testfile('base.conf'))
        config = schema.loadFile(StringIO("""
[meta]
metakey: unsupported
[unknown-section]
key1 = value1
[section_1]
keyn: unknown key
key1: bad character in caf\xc3)
[section_3.template]
key1: schema suffixes are not permitted
"""), 'bad config')
        try:
            config.validate()
        except ConfigErrors as errors:
            sorted_errors = sorted(
                errors.errors, key=attrgetter('__class__.__name__'))
            self.assertEqual(str(errors),
                             'ConfigErrors: bad config is not valid.')
        else:
            self.fail('ConfigErrors expected')
        self.assertEqual(len(sorted_errors), 4)
        self.assertEqual([error.__class__ for error in sorted_errors],
                         [UnicodeEncodeError, UnknownKeyError,
                          UnknownKeyError, UnknownSectionError])
Esempio n. 2
0
    def test_all_config_errors(self):
        schema = ConfigSchema(self._testfile('base.conf'))
        config = schema.loadFile(StringIO("""
[meta]
metakey: unsupported
[unknown-section]
key1 = value1
[section_1]
keyn: unknown key
key1: bad character in caf\xc3)
[section_3.template]
key1: schema suffixes are not permitted
"""), 'bad config')
        try:
            config.validate()
        except ConfigErrors as errors:
            sorted_errors = sorted(
                errors.errors, key=attrgetter('__class__.__name__'))
            self.assertEqual(str(errors),
                             'ConfigErrors: bad config is not valid.')
        else:
            self.fail('ConfigErrors expected')
        self.assertEqual(len(sorted_errors), 4)
        self.assertEqual([error.__class__ for error in sorted_errors],
                         [UnicodeEncodeError, UnknownKeyError,
                          UnknownKeyError, UnknownSectionError])
Esempio n. 3
0
 def load(self, filename=None):
     """Load the configuration from the schema and config files."""
     schema_file = config_file = None
     try:
         schema_file = resource_stream("mailman.config", "schema.cfg")
         schema = ConfigSchema("schema.cfg", schema_file)
         # If a configuration file was given, load it now too.  First, load
         # the absolute minimum default configuration, then if a
         # configuration filename was given by the user, push it.
         config_file = resource_stream("mailman.config", "mailman.cfg")
         self._config = schema.loadFile(config_file, "mailman.cfg")
         if filename is not None:
             self.filename = filename
             with open(filename) as user_config:
                 self._config.push(filename, user_config.read())
     finally:
         if schema_file:
             schema_file.close()
         if config_file:
             config_file.close()
     self._post_process()