diff options
-rw-r--r-- | gbp/config.py | 11 | ||||
-rw-r--r-- | tests/18_test_Config.py | 21 |
2 files changed, 26 insertions, 6 deletions
diff --git a/gbp/config.py b/gbp/config.py index 9469f0b8..2ca72278 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -16,15 +16,18 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """handles command line and config file option parsing for the gbp commands""" +import sys from optparse import OptionParser, OptionGroup, Option, OptionValueError from ConfigParser import SafeConfigParser, NoSectionError from copy import copy import os.path + try: from gbp.version import gbp_version except ImportError: gbp_version = "[Unknown version]" import gbp.tristate +import gbp.log from gbp.git import GitRepositoryError, GitRepository no_upstream_branch_msg = """ @@ -385,16 +388,20 @@ class GbpOptionParser(OptionParser): # section i.e. read [gbp-pull] prior to [pull] if (self.command.startswith('gbp-') or self.command.startswith('git-')): + cmd = self.command[4:] oldcmd = self.command if parser.has_section(oldcmd): self.config.update(dict(parser.items(oldcmd, raw=True))) - cmd = self.command[4:] + gbp.log.warn("Old style config section [%s] found " + "please rename to [%s]" % (oldcmd, cmd)) else: + cmd = self.command for prefix in ['gbp', 'git']: oldcmd = '%s-%s' % (prefix, self.command) if parser.has_section(oldcmd): self.config.update(dict(parser.items(oldcmd, raw=True))) - cmd = self.command + gbp.log.warn("Old style config section [%s] found " + "please rename to [%s]" % (oldcmd, cmd)) # Update with command specific settings if parser.has_section(cmd): diff --git a/tests/18_test_Config.py b/tests/18_test_Config.py index f7ba8c9c..1560ece4 100644 --- a/tests/18_test_Config.py +++ b/tests/18_test_Config.py @@ -1,20 +1,27 @@ # vim: set fileencoding=utf-8 : import os +import sys import unittest from gbp.config import GbpOptionParser, GbpOptionGroup -from . import context +from . testutils import GbpLogTester + +class TestConfigParser(unittest.TestCase, GbpLogTester): + def __init__(self, methodName='runTest'): + unittest.TestCase.__init__(self, methodName) + GbpLogTester.__init__(self) -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 + self._capture_log(True) def tearDown(self): if self.conffiles_save: os.environ['GBP_CONF_FILES'] = self.conffiles_save + self._capture_log(False) def test_default(self): """ @@ -32,6 +39,8 @@ class TestConfigParser(unittest.TestCase): for prefix in [ '', 'git-', 'gbp-' ]: parser = GbpOptionParser('%scmd1' % prefix) self.assertEqual(parser.config['single_override_option1'], 'single_override_value1') + # No deprecation warning since we test1.conf section is [cmd1] + self.assertEqual(self._get_log(), []) def test_single_git_override(self): """ @@ -40,6 +49,8 @@ class TestConfigParser(unittest.TestCase): for prefix in [ '', 'git-' ]: parser = GbpOptionParser('%scmd2' % prefix) self.assertEqual(parser.config['single_git_override_option1'], 'single_git_override_value1') + for line in range(0,2): + self._check_log(line, ".*Old style config section \[git-cmd2\] found please rename to \[cmd2\]") def test_single_gbp_override(self): """ @@ -48,7 +59,9 @@ class TestConfigParser(unittest.TestCase): for prefix in [ '', 'gbp-' ]: parser = GbpOptionParser('%scmd3' % prefix) self.assertEqual(parser.config['single_gbp_override_option1'], 'single_gbp_override_value1') - # FIXME: for all prefixes + for line in range(0,2): + self._check_log(line, ".*Old style config section \[gbp-cmd3\] found please rename to \[cmd3\]") + def test_new_overrides_git(self): """ @@ -65,7 +78,7 @@ class TestConfigParser(unittest.TestCase): def test_get_config_file_value(self): """ - Read a single value from the parse config + Read a single value from the parsed config """ parser = GbpOptionParser('cmd4') self.assertEqual(parser.get_config_file_value('new_overrides_git_option1'), |