Ejemplo n.º 1
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)
Ejemplo n.º 2
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')
Ejemplo n.º 3
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
Ejemplo n.º 4
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())
Ejemplo n.º 5
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())
Ejemplo n.º 6
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')
Ejemplo n.º 7
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')
Ejemplo n.º 8
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)
Ejemplo n.º 9
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')
Ejemplo n.º 10
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')
Ejemplo n.º 11
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')
Ejemplo n.º 12
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')
Ejemplo n.º 13
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')
Ejemplo n.º 14
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)
Ejemplo n.º 15
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')
Ejemplo n.º 16
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')
Ejemplo n.º 17
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')