def test_default_configuration_creation(self): c = config.DefaultConfiguration() self.assertFalse(c.has_option('a')) c = config.DefaultConfiguration({'test-option': config.StringOption('test-option')}) self.assertTrue(c.has_option('test-option')) self.assertEqual(c.options()['test-option'].short_name(), None) c = config.DefaultConfiguration({'test-option': config.StringOption('test-option', 't')}) self.assertTrue(c.has_option('test-option')) self.assertEqual(c.options()['test-option'].short_name(), 't')
def _config(opts): """ @param opts: List of Option:s. @return A corresponding Configuration instance. """ return config.DefaultConfiguration( dict([(opt.name(), opt) for opt in opts]))
def test_default_configuration_merge(self): c1 = config.DefaultConfiguration({'o1': config.StringOption('o1')}) c2 = config.DefaultConfiguration({'o2': config.StringOption('o2')}) c3 = c1.merge(c2) self.assertTrue(c3.has_option('o1')) self.assertTrue(c3.has_option('o2')) c4 = config.DefaultConfiguration({'o2': config.StringOption('o2', 'o')}) self.assertRaises(config.ConflictingMergeError, lambda: c4.merge(c3)) c5 = c3.merge(c4, allow_override=True) self.assertEqual(c5.get_option('o2').short_name(), 'o')
def test_default_configuration_option_getter(self): opt = config.StringOption('o-1') opt2 = config.StringOption('non-specified-option') c = config.DefaultConfiguration({'o-1': opt, 'non-specified-option': opt2}) opt.set('value') self.assertEqual(opt.get(), c.opts.o_1) # caller asked for non-existent option self.assertRaises(AttributeError, lambda: c.opts.nonexistent_option) # user did not provide a value for an existing option self.assertRaises(config.RequiredOptionMissingError, lambda: c.opts.non_specified_option)