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

Unified Diff: chrome/test/mini_installer/registry_verifier.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: Change verifiers to classes. 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
« no previous file with comments | « no previous file | chrome/test/mini_installer/settings.py » ('j') | chrome/test/mini_installer/test_installer.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/mini_installer/registry_verifier.py
diff --git a/chrome/test/mini_installer/registry_verifier.py b/chrome/test/mini_installer/registry_verifier.py
index ceac20dd00868c8e28afe90d00c88b763a9790b2..48be39563ad58c03d9a811ddcf91a3c38b5e573b 100644
--- a/chrome/test/mini_installer/registry_verifier.py
+++ b/chrome/test/mini_installer/registry_verifier.py
@@ -4,61 +4,56 @@
import _winreg
-import settings
-
-
-def VerifyRegistryEntries(entries):
+class RegistryVerifier:
robertshield 2013/08/09 19:00:15 probably want to use new-style objects
sukolsak 2013/08/12 19:20:20 We are using stand-alone methods now.
"""Verifies that the current registry matches the specified criteria."""
- for key, entry in entries.iteritems():
- # TODO(sukolsak): Use unittest framework instead of prints.
- if VerifyRegistryEntry(key, entry):
- print 'Passed'
- else:
- print 'Failed'
-
-
-def RootKeyConstant(key):
- if key == 'HKEY_CLASSES_ROOT':
- return _winreg.HKEY_CLASSES_ROOT
- if key == 'HKEY_CURRENT_USER':
- return _winreg.HKEY_CURRENT_USER
- if key == 'HKEY_LOCAL_MACHINE':
- return _winreg.HKEY_LOCAL_MACHINE
- if key == 'HKEY_USERS':
- return _winreg.HKEY_USERS
- # TODO(sukolsak): Use unittest framework instead of exceptions.
- raise Exception('Unknown registry key')
-
-
-def VerifyRegistryEntry(key, entry):
- """Verifies that a registry entry exists or doesn't exist and has
- the specified value.
-
- Args:
- key: Name of the registry key.
- entry: A dictionary with the following keys and values:
- 'expected' a boolean indicating whether the registry entry exists.
- 'value' (optional) a string representing the value of the registry entry.
- Returns:
- A boolean indicating whether the registry entry matches the criteria.
- """
- expected = entry['expected']
- # TODO(sukolsak): Debug prints to be removed later.
- print settings.PRINT_VERIFIER_PREFIX + key,
- if expected:
- print 'exists...',
- else:
- print "doesn't exist...",
- root_key, sub_key = key.split('\\', 1)
- try:
- reg_key = _winreg.OpenKey(RootKeyConstant(root_key),
- sub_key, 0, _winreg.KEY_READ)
- except WindowsError:
- return not expected
- if not expected:
- return False
- if 'value' in entry:
- # TODO(sukolsak): implement value
- pass
- return True
+ def __init__(self, testcase):
+ """Constructor.
+
+ Args:
+ testcase: A unittest.TestCase instance.
+ """
+ self.testcase = testcase
Mathieu 2013/08/09 16:08:43 self._testcase to show it's private.
sukolsak 2013/08/09 21:12:38 I have removed testcase.
+
+ def VerifyRegistryEntries(self, entries):
+ """Verifies that the current registry matches the specified criteria."""
Mathieu 2013/08/09 16:08:43 can you describe |entries|, since it's a non-trivi
sukolsak 2013/08/09 21:12:38 Done.
+ for key, entry in entries.iteritems():
+ self._VerifyRegistryEntry(key, entry)
Mathieu 2013/08/09 17:25:15 you probably don't need a private method for the i
sukolsak 2013/08/09 21:12:38 I think it's much cleaner to put it in a separate
+
+ def _RootKeyConstant(self, key):
Mathieu 2013/08/09 16:08:43 one-line docstring please
sukolsak 2013/08/09 21:12:38 Done.
+ if key == 'HKEY_CLASSES_ROOT':
+ return _winreg.HKEY_CLASSES_ROOT
+ if key == 'HKEY_CURRENT_USER':
+ return _winreg.HKEY_CURRENT_USER
+ if key == 'HKEY_LOCAL_MACHINE':
+ return _winreg.HKEY_LOCAL_MACHINE
+ if key == 'HKEY_USERS':
+ return _winreg.HKEY_USERS
+ self.testcase.fail('Unknown registry key')
Mathieu 2013/08/09 17:25:15 Have this return an error instead (try throwing Ke
sukolsak 2013/08/09 21:12:38 Changed to KeyError. I don't think we have to crea
+
+ def _VerifyRegistryEntry(self, key, entry):
Mathieu 2013/08/09 16:08:43 I think you should rename entry to "expectation"
sukolsak 2013/08/09 21:12:38 Done.
+ """Verifies that a registry entry exists or doesn't exist and has
Mathieu 2013/08/09 16:08:43 Has to be one line. """Verifies a registry key ac
sukolsak 2013/08/09 21:12:38 Done.
+ the specified value.
+
+ Args:
+ key: Name of the registry key.
+ entry: A dictionary with the following keys and values:
+ 'expected' a boolean indicating whether the registry entry exists.
Mathieu 2013/08/09 16:08:43 *registry entry should exist. Unless I'm not unde
Mathieu 2013/08/09 16:08:43 rename 'expected' to 'should_exist'?
sukolsak 2013/08/09 21:12:38 Done. Yes.
sukolsak 2013/08/09 21:12:38 I have renamed it to 'exist' (or should it be 'exi
+ 'value' (optional) a string representing the value of the registry
+ entry.
+
+ Returns:
+ A boolean indicating whether the registry entry matches the criteria.
Mathieu 2013/08/09 16:08:43 your method doesn't return anything, so you can re
sukolsak 2013/08/09 21:12:38 Done.
+ """
+ expected = entry['expected']
Mathieu 2013/08/09 16:08:43 remove this line, see below.
sukolsak 2013/08/09 21:12:38 Done.
+ root_key, sub_key = key.split('\\', 1)
+ try:
Mathieu 2013/08/09 16:08:43 Add a comment inside the try block to describe wha
sukolsak 2013/08/09 21:12:38 Done.
+ reg_key = _winreg.OpenKey(self._RootKeyConstant(root_key), sub_key, 0,
+ _winreg.KEY_READ)
+ except WindowsError:
+ self.testcase.assertFalse(expected, 'Registry entry %s is missing' % key)
Mathieu 2013/08/09 16:08:43 - Add a comment. - keep expectation['should_exist'
sukolsak 2013/08/09 21:12:38 Done.
+ return
+ self.testcase.assertTrue(expected, 'Registry entry %s exists' % key)
Mathieu 2013/08/09 16:08:43 put a comment here: # The key exists, see that it
sukolsak 2013/08/09 21:12:38 Done.
+ if 'value' in entry:
Mathieu 2013/08/09 16:08:43 remove this from the CL and only leave the TODO?
sukolsak 2013/08/09 21:12:38 Done.
+ # TODO(sukolsak): implement value
+ pass
« no previous file with comments | « no previous file | chrome/test/mini_installer/settings.py » ('j') | chrome/test/mini_installer/test_installer.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698