test_subcmds_init.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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/init.py module."""
  15. import unittest
  16. from subcmds import init
  17. class InitCommand(unittest.TestCase):
  18. """Check registered all_commands."""
  19. def setUp(self):
  20. self.cmd = init.Init()
  21. def test_cli_parser_good(self):
  22. """Check valid command line options."""
  23. ARGV = (
  24. [],
  25. )
  26. for argv in ARGV:
  27. opts, args = self.cmd.OptionParser.parse_args(argv)
  28. self.cmd.ValidateOptions(opts, args)
  29. def test_cli_parser_bad(self):
  30. """Check invalid command line options."""
  31. ARGV = (
  32. # Too many arguments.
  33. ['asdf'],
  34. # Conflicting options.
  35. ['--mirror', '--archive'],
  36. )
  37. for argv in ARGV:
  38. opts, args = self.cmd.OptionParser.parse_args(argv)
  39. with self.assertRaises(SystemExit):
  40. self.cmd.ValidateOptions(opts, args)