test_subcmds.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (C) 2020 The Android Open Source Project
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """Unittests for the subcmds module (mostly __init__.py than subcommands)."""
  15. import unittest
  16. import subcmds
  17. class AllCommands(unittest.TestCase):
  18. """Check registered all_commands."""
  19. def test_required_basic(self):
  20. """Basic checking of registered commands."""
  21. # NB: We don't test all subcommands as we want to avoid "change detection"
  22. # tests, so we just look for the most common/important ones here that are
  23. # unlikely to ever change.
  24. for cmd in {'cherry-pick', 'help', 'init', 'start', 'sync', 'upload'}:
  25. self.assertIn(cmd, subcmds.all_commands)
  26. def test_naming(self):
  27. """Verify we don't add things that we shouldn't."""
  28. for cmd in subcmds.all_commands:
  29. # Reject filename suffixes like "help.py".
  30. self.assertNotIn('.', cmd)
  31. # Make sure all '_' were converted to '-'.
  32. self.assertNotIn('_', cmd)
  33. # Reject internal python paths like "__init__".
  34. self.assertFalse(cmd.startswith('__'))