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)
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')
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
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())
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')
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')
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)
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')
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')
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')