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 testConfig(self):
            """Validate the config against the schema.

            All errors in the config are displayed when it is invalid.
            """
            schema = ConfigSchema(lazr_schema_file)
            config = schema.load(config_file)
            try:
                config.validate()
            except ConfigErrors as error:
                message = '\n'.join([str(e) for e in error.errors])
                self.fail(message)
Esempio n. 4
0
    def test_lp1397779(self):
        # Fix DuplicateSectionErrors when you .push() a config that has a
        # section already defined in the config.
        schema = ConfigSchema(self._testfile('base.conf'))
        config = schema.load(self._testfile('local.conf'))
        self.assertEqual(config['section_1']['key1'], 'foo')
        config.push('dupsec', """\
[section_1]
key1: baz
[section_1]
key1: qux
""")
        self.assertEqual(config['section_1']['key1'], 'qux')
Esempio n. 5
0
 def load(self, filename=None):
     """Load the configuration from config files.
     """
     schema_file = resource_filename('papergit.config', 'schema.cfg')
     schema = ConfigSchema(schema_file)
     config_file = resource_filename('papergit.config', 'paper-git.cfg')
     self._config = schema.load(config_file)
     if filename is None:
         self._post_process()
     else:
         self.filename = filename
         with open(filename, 'r', encoding='utf-8') as user_config:
             self.push(filename, user_config.read())
     self.initialized = True
Esempio n. 6
0
 def load(self, filename=None):
     """Load the configuration from the schema and config files."""
     schema_file = resource_filename('mailman.config', 'schema.cfg')
     schema = ConfigSchema(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_filename('mailman.config', 'mailman.cfg')
     self._config = schema.load(config_file)
     if filename is None:
         self._post_process()
     else:
         self.filename = filename
         with open(filename, 'r', encoding='utf-8') as user_config:
             self.push(filename, user_config.read())
Esempio n. 7
0
 def load(self, filename=None):
     """Load the configuration from the schema and config files."""
     schema_file = resource_filename('mailman.config', 'schema.cfg')
     schema = ConfigSchema(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_filename('mailman.config', 'mailman.cfg')
     self._config = schema.load(config_file)
     if filename is None:
         self._post_process()
     else:
         self.filename = filename
         with open(filename, 'r', encoding='utf-8') as user_config:
             self.push(filename, user_config.read())
Esempio n. 8
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()
Esempio n. 9
0
    def test_no_name_argument(self):
        config = """
[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
"""
        schema = ConfigSchema(self._testfile('base.conf'))
        self.assertRaises(AttributeError, schema.loadFile, StringIO(config))
Esempio n. 10
0
 def test_load_missing_file(self):
     schema = ConfigSchema(self._testfile('base.conf'))
     self.assertRaises(IOError, schema.load, '/no/such/file.conf')
Esempio n. 11
0
 def test_missing_category(self):
     schema = ConfigSchema(self._testfile('base.conf'))
     self.assertRaises(NoCategoryError, schema.getByCategory, 'non-section')
Esempio n. 12
0
 def test_missing_schema_section(self):
     schema = ConfigSchema(self._testfile('base.conf'))
     self.assertRaises(NoSectionError, schema.__getitem__, 'section-4')
Esempio n. 13
0
 def test_cannot_pop_bottom(self):
     schema = ConfigSchema(self._testfile('base.conf'))
     config = schema.load(self._testfile('local.conf'))
     config.pop('local.conf')
     self.assertRaises(NoConfigError, config.pop, 'base.conf')
Esempio n. 14
0
 def test_nonexistent_category_name(self):
     schema = ConfigSchema(self._testfile('base.conf'))
     config = schema.load(self._testfile('local.conf'))
     self.assertRaises(NoCategoryError,
                       config.getByCategory, 'non-section')
Esempio n. 15
0
 def test_not_stackable(self):
     schema = ConfigSchema(self._testfile('base.conf'))
     config = schema.load(self._testfile('local.conf'))
     self.assertRaises(DoesNotImplement,
                       verifyObject, IStackableConfig, config.extends)
Esempio n. 16
0
 def test_bad_pop(self):
     schema = ConfigSchema(self._testfile('base.conf'))
     config = schema.load(self._testfile('local.conf'))
     config.push('one', '')
     config.push('two', '')
     self.assertRaises(NoConfigError, config.pop, 'bad-name')
Esempio n. 17
0
 def test_not_stackable(self):
     schema = ConfigSchema(self._testfile('base.conf'))
     config = schema.load(self._testfile('local.conf'))
     self.assertRaises(DoesNotImplement,
                       verifyObject, IStackableConfig, config.extends)
Esempio n. 18
0
 def test_nonexistent_category_name(self):
     schema = ConfigSchema(self._testfile('base.conf'))
     config = schema.load(self._testfile('local.conf'))
     self.assertRaises(NoCategoryError,
                       config.getByCategory, 'non-section')
Esempio n. 19
0
 def test_undeclared_optional_section(self):
     schema = ConfigSchema(self._testfile('base.conf'))
     config = schema.load(self._testfile('local.conf'))
     self.assertRaises(NoSectionError,
                       config.__getitem__, 'section_3.app_a')
Esempio n. 20
0
 def test_bad_pop(self):
     schema = ConfigSchema(self._testfile('base.conf'))
     config = schema.load(self._testfile('local.conf'))
     config.push('one', '')
     config.push('two', '')
     self.assertRaises(NoConfigError, config.pop, 'bad-name')
Esempio n. 21
0
 def test_cannot_pop_bottom(self):
     schema = ConfigSchema(self._testfile('base.conf'))
     config = schema.load(self._testfile('local.conf'))
     config.pop('local.conf')
     self.assertRaises(NoConfigError, config.pop, 'base.conf')
Esempio n. 22
0
 def test_undeclared_optional_section(self):
     schema = ConfigSchema(self._testfile('base.conf'))
     config = schema.load(self._testfile('local.conf'))
     self.assertRaises(NoSectionError,
                       config.__getitem__, 'section_3.app_a')
Esempio n. 23
0
 def test_missing_section(self):
     schema = ConfigSchema(self._testfile('base.conf'))
     config = schema.load(self._testfile('local.conf'))
     self.assertRaises(NoSectionError, config.__getitem__, 'section-4')