diff options
author | Guido Günther <agx@sigxcpu.org> | 2016-07-04 20:03:26 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2016-07-04 21:02:54 +0200 |
commit | f545010462b9a313fe3bf160bca9e44c3ea77b55 (patch) | |
tree | 31c7f3a7d469b113c60b71d0f4d15bc459ea7c4c /tests/25_test_broken_gbp_conf.py | |
parent | f2ad919cb98b3e1b1a537e2a43ece88961006b29 (diff) |
Give more instructions when config is unparseable
and make return codes and messages consistent. This allows us to move
some test code from the component tests to the unit tests which is
always nice.
Closes: #733640
Diffstat (limited to 'tests/25_test_broken_gbp_conf.py')
-rw-r--r-- | tests/25_test_broken_gbp_conf.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/25_test_broken_gbp_conf.py b/tests/25_test_broken_gbp_conf.py new file mode 100644 index 00000000..79d551f8 --- /dev/null +++ b/tests/25_test_broken_gbp_conf.py @@ -0,0 +1,58 @@ +# vim: set fileencoding=utf-8 : + +"""Check if we fail correcdtly on broken gbp.conf""" + +from . import context + +from . testutils.data import TestCaseWithData +from . testutils.gbplogtester import GbpLogTester + +import os +import unittest + + +class TestBrokenConfig(TestCaseWithData, GbpLogTester): + """Test that broken config gives a sensible error for all commands""" + + cmds = ['buildpackage', + 'clone', + 'config', + 'create_remote_repo', + 'dch', + 'import_orig', + 'import_dsc', + 'pull', + 'pq', + 'import_srpm', + 'buildpackage_rpm', + 'pq_rpm', + 'rpm_ch'] + + def __init__(self, methodName='runTest'): + unittest.TestCase.__init__(self, methodName) + GbpLogTester.__init__(self) + + def setUp(self): + tmpdir = str(context.new_tmpdir('bar')) + confname = os.path.join(tmpdir, 'gbp.conf') + with open(confname, 'w') as f: + f.write("this is a broken config\n") + os.environ['GBP_CONF_FILES'] = confname + self._capture_log(True) + + def tearDown(self): + del os.environ['GBP_CONF_FILES'] + + @TestCaseWithData.feed(cmds) + def testBrokenConf(self, cmd): + module = 'gbp.scripts.%s' % cmd + try: + m = __import__(module, globals(), locals(), ['main'], 0) + ret = m.main([cmd, '--help']) + self.assertEquals(ret, 3) + except Exception as e: + self.assertTrue(False, "Caught '%s'" % e) + self._check_log(-1, "See 'man gbp.conf' for the format.") + self._clear_log() + +# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: |