summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2014-04-01 20:29:22 +0200
committerGuido Günther <agx@sigxcpu.org>2014-04-01 22:42:13 +0200
commit4c6b06773876a35f55f8f5667af65a917f823757 (patch)
tree8623bdccf7d7d1a0d559bdb8f38dae4af0e652f0 /tests
parent03ada72d54480917c75e05568844e3f596e2cb64 (diff)
Add minimal 'config' command
This only allows to print single config values so far. Closes: #733470
Diffstat (limited to 'tests')
-rw-r--r--tests/01_test_help.py1
-rw-r--r--tests/18_test_Config.py9
-rw-r--r--tests/19_test_gbp_scripts_config.py56
-rw-r--r--tests/data/gbp_config.conf4
-rw-r--r--tests/test_Config.py6
5 files changed, 73 insertions, 3 deletions
diff --git a/tests/01_test_help.py b/tests/01_test_help.py
index 0e4cf1d2..673d8708 100644
--- a/tests/01_test_help.py
+++ b/tests/01_test_help.py
@@ -12,6 +12,7 @@ class TestHelp(unittest.TestCase):
def testHelp(self):
for script in ['buildpackage',
'clone',
+ 'config',
'create_remote_repo',
'dch',
'import_orig',
diff --git a/tests/18_test_Config.py b/tests/18_test_Config.py
index 701288b4..ae39b5a2 100644
--- a/tests/18_test_Config.py
+++ b/tests/18_test_Config.py
@@ -62,3 +62,12 @@ class TestConfigParser(unittest.TestCase):
actual = parser.config['new_overrides_git_option1']
expected = 'new_overrides_git_value1'
self.assertEqual(actual, expected, "%s != %s for %s" % (actual, expected, cmd))
+
+ def test_get_config_file_value(self):
+ """
+ Read a single value from the parse config
+ """
+ parser = GbpOptionParser('cmd4')
+ self.assertEqual(parser.get_config_file_value('new_overrides_git_option1'),
+ 'new_overrides_git_value1')
+ self.assertEqual(parser.get_config_file_value('doesnotexist'), None)
diff --git a/tests/19_test_gbp_scripts_config.py b/tests/19_test_gbp_scripts_config.py
new file mode 100644
index 00000000..1c3369bd
--- /dev/null
+++ b/tests/19_test_gbp_scripts_config.py
@@ -0,0 +1,56 @@
+# vim: set fileencoding=utf-8 :
+# (C) 2014 Guido Günther <agx@sigxcpu.org>
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""Test L{gbp} config"""
+
+import os
+import sys
+import unittest
+import gbp.scripts.config
+
+class TestGbpConfigCommand(unittest.TestCase):
+
+ def setUp(self):
+ self.conffiles_save = os.environ.get('GBP_CONF_FILES')
+ self.confname = 'tests/data/gbp_config.conf'
+ self.assertTrue(os.stat(self.confname))
+ os.environ['GBP_CONF_FILES'] = self.confname
+
+ def test_invocation_single_value(self):
+ """Test if we an invoke it without error"""
+ ret = gbp.scripts.config.main(['doesnotmatter', 'coolcommand.branchname'])
+ self.assertEqual(ret, 0)
+
+ def test_invocation_missing_value(self):
+ """Test if we an invoke it without error"""
+ ret = gbp.scripts.config.main(['doesnotmatter', 'coolcommand.doesnotexist'])
+ self.assertEqual(ret, 1)
+
+ def test_invocation_parse_error(self):
+ """Test if we an invoke it without error"""
+ ret = gbp.scripts.config.main(['doesnotmatter', 'mustcontaindot'])
+ self.assertEqual(ret, 2)
+
+ def test_print_single_value(self):
+ class Printstub(object):
+ result = None
+ def __call__(self, arg):
+ self.result = arg
+
+ printstub = Printstub()
+ ret = gbp.scripts.config.print_single_value('coolcommand.branchname', printstub)
+ self.assertEqual(printstub.result, 'abranch')
+ self.assertEqual(ret, 0)
+
diff --git a/tests/data/gbp_config.conf b/tests/data/gbp_config.conf
new file mode 100644
index 00000000..468e0ba4
--- /dev/null
+++ b/tests/data/gbp_config.conf
@@ -0,0 +1,4 @@
+# Data for TestGbpConfig
+
+[coolcommand]
+branchname = abranch \ No newline at end of file
diff --git a/tests/test_Config.py b/tests/test_Config.py
index 2bae7653..cfdefd8b 100644
--- a/tests/test_Config.py
+++ b/tests/test_Config.py
@@ -74,7 +74,7 @@ def test_parser_fallback():
>>> f = open(confname, 'w')
>>> f.write('[DEFAULT]\\nthere = was\\n[foo]\\nthere = is\\n[git-foo]\\nno = truth\\n')
>>> f.close()
- >>> parser._parse_config_files()
+ >>> parser.parse_config_files()
>>> parser.config['there']
'is'
>>> parser.config['no']
@@ -93,13 +93,13 @@ def test_filter():
>>> f = open(confname, 'w')
>>> f.write('[bar]\\nfilter = asdf\\n')
>>> f.close()
- >>> parser._parse_config_files()
+ >>> parser.parse_config_files()
>>> parser.config['filter']
['asdf']
>>> f = open(confname, 'w')
>>> f.write("[bar]\\nfilter = ['this', 'is', 'a', 'list']\\n")
>>> f.close()
- >>> parser._parse_config_files()
+ >>> parser.parse_config_files()
>>> parser.config['filter']
['this', 'is', 'a', 'list']
"""