16_test_supercommand.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 sys
  18. import unittest
  19. import gbp.scripts.supercommand
  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. old_stderr = sys.stderr
  36. with open('/dev/null', 'w') as sys.stderr:
  37. self.assertEqual(gbp.scripts.supercommand.supercommand(
  38. ['argv0', 'asdf']), 2)
  39. self.assertEqual(gbp.scripts.supercommand.supercommand(
  40. ['argv0', 'asdf', '--verbose']), 2)
  41. sys.stderr = old_stderr
  42. def test_help_command(self):
  43. """Invoking with --help must not raise an error"""
  44. self.assertEqual(gbp.scripts.supercommand.supercommand(
  45. ['argv0', '--help']), 0)
  46. def test_missing_arg(self):
  47. self.assertEqual(gbp.scripts.supercommand.supercommand(
  48. ['argv0']), 1)