Fix list_values, add test (#33264)

This commit is contained in:
Moe 2016-05-16 07:31:19 -07:00 committed by Mike Place
parent 05e763c53c
commit 3b50a7b98d
2 changed files with 23 additions and 1 deletions

View File

@ -285,8 +285,9 @@ def list_values(hive, key=None, use_32bit_registry=False, include_default=True):
registry = Registry()
hkey = registry.hkeys[local_hive]
access_mask = registry.registry_32[use_32bit_registry]
handle = None
values = list()
try:
handle = _winreg.OpenKey(hkey, local_key, 0, access_mask)

View File

@ -119,6 +119,27 @@ class RegWinTestCase(TestCase):
test = len(test_list) > 5 # Their should be a lot more than 5 items
self.assertTrue(test)
@skipIf(not sys.platform.startswith("win"), "requires Windows OS")
def test_list_values_fail(self):
'''
Test - List the values under a subkey which does not exist.
'''
subkey = 'ThisIsJunkItDoesNotExistIhope'
test_list = win_mod_reg.list_values('HKEY_LOCAL_MACHINE', subkey)
# returns a tuple with first item false, and second item a reason
test = isinstance(test_list, tuple) and (not test_list[0])
self.assertTrue(test)
@skipIf(not sys.platform.startswith("win"), "requires Windows OS")
def test_list_values(self):
'''
Test - List the values under a subkey.
'''
subkey = r'Software\Microsoft\Windows NT\CurrentVersion'
test_list = win_mod_reg.list_values('HKEY_LOCAL_MACHINE', subkey)
test = len(test_list) > 5 # There should be a lot more than 5 items
self.assertTrue(test)
# Not considering this destructive as its writing to a private space
@skipIf(not sys.platform.startswith("win"), "requires Windows OS")
def test_set_value_unicode(self):