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

Side by Side 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 unified diff | Download patch
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import _winreg 5 import _winreg
6 6
7 import settings 7 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.
8 """Verifies that the current registry matches the specified criteria."""
8 9
10 def __init__(self, testcase):
11 """Constructor.
9 12
10 def VerifyRegistryEntries(entries): 13 Args:
11 """Verifies that the current registry matches the specified criteria.""" 14 testcase: A unittest.TestCase instance.
12 for key, entry in entries.iteritems(): 15 """
13 # TODO(sukolsak): Use unittest framework instead of prints. 16 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.
14 if VerifyRegistryEntry(key, entry):
15 print 'Passed'
16 else:
17 print 'Failed'
18 17
18 def VerifyRegistryEntries(self, entries):
19 """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.
20 for key, entry in entries.iteritems():
21 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
19 22
20 def RootKeyConstant(key): 23 def _RootKeyConstant(self, key):
Mathieu 2013/08/09 16:08:43 one-line docstring please
sukolsak 2013/08/09 21:12:38 Done.
21 if key == 'HKEY_CLASSES_ROOT': 24 if key == 'HKEY_CLASSES_ROOT':
22 return _winreg.HKEY_CLASSES_ROOT 25 return _winreg.HKEY_CLASSES_ROOT
23 if key == 'HKEY_CURRENT_USER': 26 if key == 'HKEY_CURRENT_USER':
24 return _winreg.HKEY_CURRENT_USER 27 return _winreg.HKEY_CURRENT_USER
25 if key == 'HKEY_LOCAL_MACHINE': 28 if key == 'HKEY_LOCAL_MACHINE':
26 return _winreg.HKEY_LOCAL_MACHINE 29 return _winreg.HKEY_LOCAL_MACHINE
27 if key == 'HKEY_USERS': 30 if key == 'HKEY_USERS':
28 return _winreg.HKEY_USERS 31 return _winreg.HKEY_USERS
29 # TODO(sukolsak): Use unittest framework instead of exceptions. 32 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
30 raise Exception('Unknown registry key')
31 33
34 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.
35 """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.
36 the specified value.
32 37
33 def VerifyRegistryEntry(key, entry): 38 Args:
34 """Verifies that a registry entry exists or doesn't exist and has 39 key: Name of the registry key.
35 the specified value. 40 entry: A dictionary with the following keys and values:
41 '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
42 'value' (optional) a string representing the value of the registry
43 entry.
36 44
37 Args: 45 Returns:
38 key: Name of the registry key. 46 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.
39 entry: A dictionary with the following keys and values: 47 """
40 'expected' a boolean indicating whether the registry entry exists. 48 expected = entry['expected']
Mathieu 2013/08/09 16:08:43 remove this line, see below.
sukolsak 2013/08/09 21:12:38 Done.
41 'value' (optional) a string representing the value of the registry entry. 49 root_key, sub_key = key.split('\\', 1)
42 50 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.
43 Returns: 51 reg_key = _winreg.OpenKey(self._RootKeyConstant(root_key), sub_key, 0,
44 A boolean indicating whether the registry entry matches the criteria. 52 _winreg.KEY_READ)
45 """ 53 except WindowsError:
46 expected = entry['expected'] 54 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.
47 # TODO(sukolsak): Debug prints to be removed later. 55 return
48 print settings.PRINT_VERIFIER_PREFIX + key, 56 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.
49 if expected: 57 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.
50 print 'exists...', 58 # TODO(sukolsak): implement value
51 else: 59 pass
52 print "doesn't exist...",
53 root_key, sub_key = key.split('\\', 1)
54 try:
55 reg_key = _winreg.OpenKey(RootKeyConstant(root_key),
56 sub_key, 0, _winreg.KEY_READ)
57 except WindowsError:
58 return not expected
59 if not expected:
60 return False
61 if 'value' in entry:
62 # TODO(sukolsak): implement value
63 pass
64 return True
OLDNEW
« 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