blob: d47c17bf099636832ff8ba5861d94c95ca027477 [file] [log] [blame]
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""This module tests the command module."""
import argparse
import os
import sys
sys.path.insert(0, os.path.abspath('%s/../..' % os.path.dirname(__file__)))
from chromite.lib import cros_test_lib
from chromite import cros
_COMMAND_NAME = 'superAwesomeCommandOfFunness'
class TestCommand(cros.CrosCommand):
"""A fake command."""
def Run(self):
print 'Just testing'
# pylint: disable=W0212
class CommandTest(cros_test_lib.TestCase):
"""This test class tests that Commands method."""
def testParserSetsCrosClass(self):
"""Tests that our parser sets cros_class correctly."""
my_parser = argparse.ArgumentParser()
ns = my_parser.parse_args([])
self.assertEqual(ns.cros_class, cros.CrosCommand)
def testCommandDecorator(self):
"""Tests that our decorator correctly adds TestCommand to _commands."""
# Note this exposes an implementation detail of _commands.
self.assertEqual(cros._commands[_COMMAND_NAME], TestCommand)
def testBadUseOfCommandDecorator(self):
"""Tests that our decorator correctly rejects bad test commands."""
# pylint: disable=W0612
class BadTestCommand(object):
"""A command that wasn't implemented correctly."""
except cros.InvalidCommandError:
else:'Invalid command was accepted by the CommandDecorator')
if __name__ == '__main__':