diff options
author | Guido Günther <agx@sigxcpu.org> | 2014-04-01 10:03:35 +0200 |
---|---|---|
committer | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2014-04-03 11:31:43 +0300 |
commit | a064d2a8fc6f5437c6d2660167c3f779fbd21897 (patch) | |
tree | 4cf51052f03770ebefd0ea28113fa1c49796471f | |
parent | 5d4f9cef82e420954cf7e6e1c957c6eda45ebc74 (diff) | |
download | git-buildpackage-a064d2a8fc6f5437c6d2660167c3f779fbd21897.tar.gz git-buildpackage-a064d2a8fc6f5437c6d2660167c3f779fbd21897.tar.bz2 git-buildpackage-a064d2a8fc6f5437c6d2660167c3f779fbd21897.zip |
Test option parser fallbacks more thoroughly
revealing another bug where we overwrote parsed values with defaults
Closes: #733759
(cherry picked from commit 14f6ded0143a3e82d04cad2614d705ca3a5b5c7e)
-rw-r--r-- | gbp/config.py | 1 | ||||
-rw-r--r-- | tests/18_test_Config.py | 64 | ||||
-rw-r--r-- | tests/data/test1.conf | 35 |
3 files changed, 99 insertions, 1 deletions
diff --git a/gbp/config.py b/gbp/config.py index 902b64cd..00a67ac8 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -391,7 +391,6 @@ class GbpOptionParser(OptionParser): # Update with command specific settings if parser.has_section(cmd): - self.config.update(dict(parser.items(cmd, raw=True))) # Don't use items() until we got rid of the compat sections # since this pulls in the defaults again self.config.update(dict(parser._sections[cmd].items())) diff --git a/tests/18_test_Config.py b/tests/18_test_Config.py new file mode 100644 index 00000000..701288b4 --- /dev/null +++ b/tests/18_test_Config.py @@ -0,0 +1,64 @@ +# vim: set fileencoding=utf-8 : + +import os +import unittest +from gbp.config import GbpOptionParser +from . import context + +class TestConfigParser(unittest.TestCase): + def setUp(self): + self.conffiles_save = os.environ.get('GBP_CONF_FILES') + self.confname = 'tests/data/test1.conf' + self.assertTrue(os.stat(self.confname)) + os.environ['GBP_CONF_FILES'] = self.confname + + def tearDown(self): + if self.conffiles_save: + os.environ['GBP_CONF_FILES'] = self.conffiles_save + + def test_default(self): + """ + A value only in the default section should be available in all commands + """ + for n in range(1,5): + for prefix in [ '', 'git-', 'gbp-' ]: + parser = GbpOptionParser('cmd%d' % n) + self.assertEqual(parser.config['default_option'], 'default_default1') + + def test_single_override(self): + """ + A value in any command section should override the default + """ + for prefix in [ '', 'git-', 'gbp-' ]: + parser = GbpOptionParser('%scmd1' % prefix) + self.assertEqual(parser.config['single_override_option1'], 'single_override_value1') + + def test_single_git_override(self): + """ + A value in any git-command section should override the default + """ + for prefix in [ '', 'git-' ]: + parser = GbpOptionParser('%scmd2' % prefix) + self.assertEqual(parser.config['single_git_override_option1'], 'single_git_override_value1') + + def test_single_gbp_override(self): + """ + A value in any gbp-command section should override the default + """ + for prefix in [ '', 'gbp-' ]: + parser = GbpOptionParser('%scmd3' % prefix) + self.assertEqual(parser.config['single_gbp_override_option1'], 'single_gbp_override_value1') + # FIXME: for all prefixes + + def test_new_overrides_git(self): + """ + A value in the cmd section should override the old git-cmd section independent from + how we're invoked + """ + for n in range(4, 6): + for prefix in [ '', 'git-']: + cmd = '%scmd%d' % (prefix, n) + parser = GbpOptionParser(cmd) + actual = parser.config['new_overrides_git_option1'] + expected = 'new_overrides_git_value1' + self.assertEqual(actual, expected, "%s != %s for %s" % (actual, expected, cmd)) diff --git a/tests/data/test1.conf b/tests/data/test1.conf new file mode 100644 index 00000000..e7ffeb4f --- /dev/null +++ b/tests/data/test1.conf @@ -0,0 +1,35 @@ +# Data for TestConfigParser + +[DEFAULT] +default_option = default_default1 +single_override_option1 = single_override_default1 +single_git_override_option1 = single_git_override_default1 +single_gbp_override_option1 = single_gbp_override_default1 +new_overrides_git_option1 = new_overrides_git_default1 + +# These commands only have a single section overriding defaults. +# There are no alterntive old or new names +[cmd1] +single_override_option1 = single_override_value1 + +[git-cmd2] +single_git_override_option1 = single_git_override_value1 + +[gbp-cmd3] +single_gbp_override_option1 = single_gbp_override_value1 + +# This commands have a new name overriding the old git- section +# The order of the sections differs though +[git-cmd4] +new_overrides_git_option1 = new_overrides_git_overridden1 + +[cmd4] +new_overrides_git_option1 = new_overrides_git_value1 + +[cmd5] +new_overrides_git_option1 = new_overrides_git_value1 + +[git-cmd5] +new_overrides_git_option1 = new_overrides_git_overridden1 + + |