Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10263)

Unified Diff: chrome/test/mini_installer/test_installer.py

Issue 22480002: Use unittest framework in the Automated Installer Testing Framework. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Try to fix 'old chunk mismatch' error in diff. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/mini_installer/test_installer.py
diff --git a/chrome/test/mini_installer/test_installer.py b/chrome/test/mini_installer/test_installer.py
index a59bf9164074f3706728b0b4042490dfee34f2c3..426685c25d884f64230853ca757bc7767dfdd970 100644
--- a/chrome/test/mini_installer/test_installer.py
+++ b/chrome/test/mini_installer/test_installer.py
@@ -13,8 +13,8 @@ import argparse
import json
import os
import subprocess
+import unittest
-import settings
import verifier
@@ -34,6 +34,81 @@ class Config:
self.tests = []
+class InstallerTest(unittest.TestCase):
+ """Tests a test case in the config file."""
+
+ def __init__(self, test, config):
+ """Constructor.
+
+ Args:
+ test: An array of alternating state names and action names, starting and
+ ending with state names.
+ config: The Config object.
+ """
+ super(InstallerTest, self).__init__()
+ self.test = test
+ self.config = config
+
+ def runTest(self):
+ """Run the test case."""
+ test = self.test
+
+ # |test| is an array of alternating state names and action names, starting
+ # and ending with state names. Therefore, its length must be odd.
+ self.assertEqual(len(test) % 2, 1, 'The length of test array must be odd')
+
+ self._RunResetCommand()
+
+ self.current_state = test[0]
+ self._VerifyCurrentState()
+
+ for i in range(1, len(test), 2):
+ action = test[i]
+ self._RunCommand(self.config.actions[action])
+
+ self.current_state = test[i + 1]
+ self._VerifyCurrentState()
+
+ def __str__(self):
+ return 'Test: %s' % (' -> '.join(self.test))
gab 2013/08/07 13:03:34 Add a method comment with an example of what this
sukolsak 2013/08/07 21:23:29 Done.
+
+ def shortDescription(self):
+ """Returns None as the short description to suppress its printing.
+
+ The default implementation of this method returns the docstring of the
+ runTest method, which is not useful since it's the same for every test case.
+ The description from the __str__ method is informative enough.
+ """
+ return None
+
+ def failureException(self, msg):
+ """Returns an AssertionError with the current state information.
+
+ The default implementation of this method returns AssertionError(msg).
+ We add the current state information to the message so that we know where
+ the test fails.
+
+ Args:
+ msg: The error message.
+
+ Returns:
+ An AssertionError.
+ """
+ return AssertionError("In state '%s', %s" % (self.current_state, msg))
+
+ def _VerifyCurrentState(self):
+ """Verifies that the current machine states match the expected machine
+ states."""
gab 2013/08/07 13:03:34 s/states/state for both 'states' in this sentence
sukolsak 2013/08/07 21:23:29 Done.
+ verifier.Verify(self.config.states[self.current_state], self)
+
+ def _RunCommand(self, command):
+ subprocess.call(command, shell=True)
+
+ def _RunResetCommand(self):
+ # TODO(sukolsak): Need to figure how exactly we want to reset.
+ pass
+
+
def MergePropertyDictionaries(current_property, new_property):
"""Merges the new property dictionary into the current property dictionary.
@@ -100,54 +175,16 @@ def ParseConfigFile(filename):
return config
-def VerifyState(config, state):
- """Verifies that the current machine states match the given machine states.
-
- Args:
- config: A Config object.
- state: The current state.
- """
- # TODO(sukolsak): Think of ways of preserving the log when the test fails but
- # not printing these when the test passes.
- print settings.PRINT_STATE_PREFIX + state
- verifier.Verify(config.states[state])
-
-
-def RunCommand(command):
- print settings.PRINT_COMMAND_PREFIX + command
- subprocess.call(command, shell=True)
-
-
-def RunResetCommand():
- print settings.PRINT_COMMAND_PREFIX + 'Reset'
- # TODO(sukolsak): Need to figure how exactly we want to reset.
-
-
def Test(config):
"""Tests the installer using the given Config object.
Args:
config: A Config object.
"""
+ suite = unittest.TestSuite()
for test in config.tests:
- print settings.PRINT_TEST_PREFIX + ' -> '.join(test)
-
- # A Test object is an array of alternating state names and action names.
- # The array starts and ends with states. Therefore, the length must be odd.
- assert(len(test) % 2 == 1)
-
- RunResetCommand()
-
- current_state = test[0]
- VerifyState(config, current_state)
- # TODO(sukolsak): Quit the test early if VerifyState fails at any point.
gab 2013/08/07 13:03:34 Bring this TODO in the new test code above.
sukolsak 2013/08/07 21:23:29 The assertions in verifiers will kill the test cas
-
- for i in range(1, len(test), 2):
- action = test[i]
- RunCommand(config.actions[action])
-
- current_state = test[i + 1]
- VerifyState(config, current_state)
+ suite.addTest(InstallerTest(test, config))
+ unittest.TextTestRunner(verbosity=2).run(suite)
def main():

Powered by Google App Engine
This is Rietveld 408576698