16_test_supercommand.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # vim: set fileencoding=utf-8 :
  2. # (C) 2013 Guido Günther <agx@sigxcpu.org>
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, please see
  15. # <http://www.gnu.org/licenses/>
  16. """Test L{gbp} command wrapper"""
  17. import unittest
  18. import gbp.scripts.supercommand
  19. from tests.testutils import capture_stdout, capture_stderr
  20. class TestSuperCommand(unittest.TestCase):
  21. def test_import(self):
  22. """Test the importer itself"""
  23. self.assertRaises(ImportError,
  24. gbp.scripts.supercommand.import_command,
  25. 'not.allowed')
  26. self.assertRaises(ImportError,
  27. gbp.scripts.supercommand.import_command,
  28. 'not/allowed')
  29. self.assertRaises(ImportError,
  30. gbp.scripts.supercommand.import_command,
  31. '0notallowed')
  32. self.assertIsNotNone(gbp.scripts.supercommand.import_command('pq'))
  33. def test_invalid_command(self):
  34. """Test if we fail correctly with an invalid command"""
  35. with capture_stderr():
  36. self.assertEqual(gbp.scripts.supercommand.supercommand(
  37. ['argv0', 'asdf']), 2)
  38. self.assertEqual(gbp.scripts.supercommand.supercommand(
  39. ['argv0', 'asdf', '--verbose']), 2)
  40. def test_list_commands(self):
  41. """Invoking with --list-cmds must not raise an error"""
  42. with capture_stdout() as out:
  43. self.assertEqual(gbp.scripts.supercommand.supercommand(['argv0',
  44. '--list-cmds']), 0)
  45. for cmd in ['import-orig', 'create-remote-repo', 'pq']:
  46. self.assertIn("%s - " % cmd, out.output())
  47. def test_help_command(self):
  48. """Invoking with --help must not raise an error"""
  49. self.assertEqual(gbp.scripts.supercommand.supercommand(
  50. ['argv0', '--help']), 0)
  51. def test_missing_arg(self):
  52. self.assertEqual(gbp.scripts.supercommand.supercommand(
  53. ['argv0']), 1)