aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/18_test_Config.py
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2014-04-01 10:03:35 +0200
committerGuido Günther <agx@sigxcpu.org>2014-04-01 11:33:06 +0200
commit14f6ded0143a3e82d04cad2614d705ca3a5b5c7e (patch)
treeb5c6c56d5495e75acd48cb6aa00f6d98d5a64125 /tests/18_test_Config.py
parent8f7a64eb08bdf1a8e04db8cf07cf74e88b90e9e4 (diff)
Test option parser fallbacks more thoroughly
revealing another bug where we overwrote parsed values with defaults Closes: #733759
Diffstat (limited to 'tests/18_test_Config.py')
-rw-r--r--tests/18_test_Config.py64
1 files changed, 64 insertions, 0 deletions
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))