25_test_broken_gbp_conf.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # vim: set fileencoding=utf-8 :
  2. """Check if we fail correcdtly on broken gbp.conf"""
  3. from . import context
  4. from . testutils.data import TestCaseWithData
  5. from . testutils.gbplogtester import GbpLogTester
  6. import os
  7. import unittest
  8. class TestBrokenConfig(TestCaseWithData, GbpLogTester):
  9. """Test that broken config gives a sensible error for all commands"""
  10. cmds = ['buildpackage',
  11. 'clone',
  12. 'config',
  13. 'create_remote_repo',
  14. 'dch',
  15. 'import_orig',
  16. 'import_dsc',
  17. 'pull',
  18. 'pq',
  19. 'import_srpm',
  20. 'buildpackage_rpm',
  21. 'pq_rpm',
  22. 'rpm_ch']
  23. def __init__(self, methodName='runTest'):
  24. unittest.TestCase.__init__(self, methodName)
  25. GbpLogTester.__init__(self)
  26. def setUp(self):
  27. tmpdir = str(context.new_tmpdir('bar'))
  28. confname = os.path.join(tmpdir, 'gbp.conf')
  29. with open(confname, 'w') as f:
  30. f.write("this is a broken config\n")
  31. os.environ['GBP_CONF_FILES'] = confname
  32. self._capture_log(True)
  33. def tearDown(self):
  34. del os.environ['GBP_CONF_FILES']
  35. @TestCaseWithData.feed(cmds)
  36. def testBrokenConf(self, cmd):
  37. module = 'gbp.scripts.%s' % cmd
  38. try:
  39. m = __import__(module, globals(), locals(), ['main'], 0)
  40. ret = m.main([cmd, '--help'])
  41. self.assertEquals(ret, 3)
  42. except Exception as e:
  43. self.assertTrue(False, "Caught '%s'" % e)
  44. self._check_log(-1, "See 'man gbp.conf' for the format.")
  45. self._clear_log()
  46. # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: