1 # vim: set fileencoding=utf-8 :
6 from gbp.config import GbpOptionParser, GbpOptionGroup
9 class TestConfigParser(unittest.TestCase):
11 self.conffiles_save = os.environ.get('GBP_CONF_FILES')
12 self.confname = 'tests/data/test1.conf'
13 self.assertTrue(os.stat(self.confname))
14 os.environ['GBP_CONF_FILES'] = self.confname
17 if self.conffiles_save:
18 os.environ['GBP_CONF_FILES'] = self.conffiles_save
20 def test_default(self):
22 A value only in the default section should be available in all commands
25 for prefix in [ '', 'git-', 'gbp-' ]:
26 parser = GbpOptionParser('cmd%d' % n)
27 self.assertEqual(parser.config['default_option'], 'default_default1')
29 def test_single_override(self):
31 A value in any command section should override the default
33 for prefix in [ '', 'git-', 'gbp-' ]:
34 parser = GbpOptionParser('%scmd1' % prefix)
35 self.assertEqual(parser.config['single_override_option1'], 'single_override_value1')
37 def test_single_git_override(self):
39 A value in any git-command section should override the default
41 for prefix in [ '', 'git-' ]:
42 parser = GbpOptionParser('%scmd2' % prefix)
43 self.assertEqual(parser.config['single_git_override_option1'], 'single_git_override_value1')
45 def test_single_gbp_override(self):
47 A value in any gbp-command section should override the default
49 for prefix in [ '', 'gbp-' ]:
50 parser = GbpOptionParser('%scmd3' % prefix)
51 self.assertEqual(parser.config['single_gbp_override_option1'], 'single_gbp_override_value1')
52 # FIXME: for all prefixes
54 def test_new_overrides_git(self):
56 A value in the cmd section should override the old git-cmd section independent from
60 for prefix in [ '', 'git-']:
61 cmd = '%scmd%d' % (prefix, n)
62 parser = GbpOptionParser(cmd)
63 actual = parser.config['new_overrides_git_option1']
64 expected = 'new_overrides_git_value1'
65 self.assertEqual(actual, expected, "%s != %s for %s" % (actual, expected, cmd))
67 def test_get_config_file_value(self):
69 Read a single value from the parse config
71 parser = GbpOptionParser('cmd4')
72 self.assertEqual(parser.get_config_file_value('new_overrides_git_option1'),
73 'new_overrides_git_value1')
74 self.assertEqual(parser.get_config_file_value('doesnotexist'), None)
76 def test_param_list(self):
77 parser = GbpOptionParser('cmd4')
79 branch_group = GbpOptionGroup(parser, "branch options", "branch update and layout options")
80 parser.add_option_group(branch_group)
81 branch_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch")
82 branch_group.add_config_file_option("debian-branch", dest="upstream_branch")
83 parser.add_config_file_option(option_name="color", dest="color", type='tristate')
85 params = parser.valid_options
86 self.assertTrue('upstream-branch' in params)
87 self.assertTrue('debian-branch' in params)
88 self.assertTrue('color' in params)