2 # Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """This module tests the command module."""
8 from __future__ import print_function
14 sys.path.insert(0, os.path.abspath('%s/../..' % os.path.dirname(__file__)))
16 from chromite.lib import cros_test_lib
17 from chromite import cros
19 _COMMAND_NAME = 'superAwesomeCommandOfFunness'
22 @cros.CommandDecorator(_COMMAND_NAME)
23 class TestCommand(cros.CrosCommand):
29 # pylint: disable=W0212
30 class CommandTest(cros_test_lib.TestCase):
31 """This test class tests that Commands method."""
33 def testParserSetsCrosClass(self):
34 """Tests that our parser sets cros_class correctly."""
35 my_parser = argparse.ArgumentParser()
36 cros.CrosCommand.AddParser(my_parser)
37 ns = my_parser.parse_args([])
38 self.assertEqual(ns.cros_class, cros.CrosCommand)
40 def testCommandDecorator(self):
41 """Tests that our decorator correctly adds TestCommand to _commands."""
42 # Note this exposes an implementation detail of _commands.
43 self.assertEqual(cros._commands[_COMMAND_NAME], TestCommand)
45 def testBadUseOfCommandDecorator(self):
46 """Tests that our decorator correctly rejects bad test commands."""
48 # pylint: disable=W0612
49 @cros.CommandDecorator('bad')
50 class BadTestCommand(object):
51 """A command that wasn't implemented correctly."""
54 except cros.InvalidCommandError:
57 self.fail('Invalid command was accepted by the CommandDecorator')
60 if __name__ == '__main__':