Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(79471)

Delta Between Two Patch Sets: Lib/test/test_winreg.py

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 6 years, 9 months ago
Right Patch Set: Created 5 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_weakset.py ('k') | Lib/test/test_with.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # Test the windows specific win32reg module. 1 # Test the windows specific win32reg module.
2 # Only win32reg functions not hit here: FlushKey, LoadKey and SaveKey 2 # Only win32reg functions not hit here: FlushKey, LoadKey and SaveKey
3 3
4 import os, sys, errno 4 import os, sys, errno
5 import unittest 5 import unittest
6 from test import support 6 from test import support
7 threading = support.import_module("threading") 7 threading = support.import_module("threading")
8 from platform import machine 8 from platform import machine
9 9
10 # Do this first so test will be skipped if module doesn't exist 10 # Do this first so test will be skipped if module doesn't exist
(...skipping 10 matching lines...) Expand all
21 WIN_VER = sys.getwindowsversion()[:2] 21 WIN_VER = sys.getwindowsversion()[:2]
22 # Some tests should only run on 64-bit architectures where WOW64 will be. 22 # Some tests should only run on 64-bit architectures where WOW64 will be.
23 WIN64_MACHINE = True if machine() == "AMD64" else False 23 WIN64_MACHINE = True if machine() == "AMD64" else False
24 24
25 # Starting with Windows 7 and Windows Server 2008 R2, WOW64 no longer uses 25 # Starting with Windows 7 and Windows Server 2008 R2, WOW64 no longer uses
26 # registry reflection and formerly reflected keys are shared instead. 26 # registry reflection and formerly reflected keys are shared instead.
27 # Windows 7 and Windows Server 2008 R2 are version 6.1. Due to this, some 27 # Windows 7 and Windows Server 2008 R2 are version 6.1. Due to this, some
28 # tests are only valid up until 6.1 28 # tests are only valid up until 6.1
29 HAS_REFLECTION = True if WIN_VER < (6, 1) else False 29 HAS_REFLECTION = True if WIN_VER < (6, 1) else False
30 30
31 test_key_name = "SOFTWARE\\Python Registry Test Key - Delete Me" 31 # Use a per-process key to prevent concurrent test runs (buildbot!) from
32 # stomping on each other.
33 test_key_base = "Python Test Key [%d] - Delete Me" % (os.getpid(),)
34 test_key_name = "SOFTWARE\\" + test_key_base
32 # On OS'es that support reflection we should test with a reflected key 35 # On OS'es that support reflection we should test with a reflected key
33 test_reflect_key_name = "SOFTWARE\\Classes\\Python Test Key - Delete Me" 36 test_reflect_key_name = "SOFTWARE\\Classes\\" + test_key_base
34 37
35 test_data = [ 38 test_data = [
36 ("Int Value", 45, REG_DWORD), 39 ("Int Value", 45, REG_DWORD),
37 ("String Val", "A string value", REG_SZ), 40 ("String Val", "A string value", REG_SZ),
38 ("StringExpand", "The path is %path%", REG_EXPAND_SZ), 41 ("StringExpand", "The path is %path%", REG_EXPAND_SZ),
39 ("Multi-string", ["Lots", "of", "string", "values"], REG_MULTI_SZ), 42 ("Multi-string", ["Lots", "of", "string", "values"], REG_MULTI_SZ),
40 ("Raw Data", b"binary\x00data", REG_BINARY), 43 ("Raw Data", b"binary\x00data", REG_BINARY),
41 ("Big String", "x"*(2**14-1), REG_SZ), 44 ("Big String", "x"*(2**14-1), REG_SZ),
42 ("Big Binary", b"x"*(2**14), REG_BINARY), 45 ("Big Binary", b"x"*(2**14), REG_BINARY),
43 # Two and three kanjis, meaning: "Japan" and "Japanese") 46 # Two and three kanjis, meaning: "Japan" and "Japanese")
44 ("Japanese 日本", "日本語", REG_SZ), 47 ("Japanese 日本", "日本語", REG_SZ),
45 ] 48 ]
46 49
47 class BaseWinregTests(unittest.TestCase): 50 class BaseWinregTests(unittest.TestCase):
48 51
49 def setUp(self): 52 def setUp(self):
50 # Make sure that the test key is absent when the test 53 # Make sure that the test key is absent when the test
51 # starts. 54 # starts.
52 self.delete_tree(HKEY_CURRENT_USER, test_key_name) 55 self.delete_tree(HKEY_CURRENT_USER, test_key_name)
53 56
54 def delete_tree(self, root, subkey): 57 def delete_tree(self, root, subkey):
55 try: 58 try:
56 hkey = OpenKey(root, subkey, KEY_ALL_ACCESS) 59 hkey = OpenKey(root, subkey, KEY_ALL_ACCESS)
57 except WindowsError: 60 except OSError:
58 # subkey does not exist 61 # subkey does not exist
59 return 62 return
60 while True: 63 while True:
61 try: 64 try:
62 subsubkey = EnumKey(hkey, 0) 65 subsubkey = EnumKey(hkey, 0)
63 except WindowsError: 66 except OSError:
64 # no more subkeys 67 # no more subkeys
65 break 68 break
66 self.delete_tree(hkey, subsubkey) 69 self.delete_tree(hkey, subsubkey)
67 CloseKey(hkey) 70 CloseKey(hkey)
68 DeleteKey(root, subkey) 71 DeleteKey(root, subkey)
69 72
70 def _write_test_data(self, root_key, subkeystr="sub_key", 73 def _write_test_data(self, root_key, subkeystr="sub_key",
71 CreateKey=CreateKey): 74 CreateKey=CreateKey):
72 # Set the default value for this key. 75 # Set the default value for this key.
73 SetValue(root_key, test_key_name, REG_SZ, "Default value") 76 SetValue(root_key, test_key_name, REG_SZ, "Default value")
(...skipping 16 matching lines...) Expand all
90 "Not the correct number of values") 93 "Not the correct number of values")
91 # Close this key this way... 94 # Close this key this way...
92 # (but before we do, copy the key as an integer - this allows 95 # (but before we do, copy the key as an integer - this allows
93 # us to test that the key really gets closed). 96 # us to test that the key really gets closed).
94 int_sub_key = int(sub_key) 97 int_sub_key = int(sub_key)
95 CloseKey(sub_key) 98 CloseKey(sub_key)
96 try: 99 try:
97 QueryInfoKey(int_sub_key) 100 QueryInfoKey(int_sub_key)
98 self.fail("It appears the CloseKey() function does " 101 self.fail("It appears the CloseKey() function does "
99 "not close the actual key!") 102 "not close the actual key!")
100 except EnvironmentError: 103 except OSError:
101 pass 104 pass
102 # ... and close that key that way :-) 105 # ... and close that key that way :-)
103 int_key = int(key) 106 int_key = int(key)
104 key.Close() 107 key.Close()
105 try: 108 try:
106 QueryInfoKey(int_key) 109 QueryInfoKey(int_key)
107 self.fail("It appears the key.Close() function " 110 self.fail("It appears the key.Close() function "
108 "does not close the actual key!") 111 "does not close the actual key!")
109 except EnvironmentError: 112 except OSError:
110 pass 113 pass
111 114
112 def _read_test_data(self, root_key, subkeystr="sub_key", OpenKey=OpenKey): 115 def _read_test_data(self, root_key, subkeystr="sub_key", OpenKey=OpenKey):
113 # Check we can get default value for this key. 116 # Check we can get default value for this key.
114 val = QueryValue(root_key, test_key_name) 117 val = QueryValue(root_key, test_key_name)
115 self.assertEqual(val, "Default value", 118 self.assertEqual(val, "Default value",
116 "Registry didn't give back the correct value") 119 "Registry didn't give back the correct value")
117 120
118 key = OpenKey(root_key, test_key_name) 121 key = OpenKey(root_key, test_key_name)
119 # Read the sub-keys 122 # Read the sub-keys
120 with OpenKey(key, subkeystr) as sub_key: 123 with OpenKey(key, subkeystr) as sub_key:
121 # Check I can enumerate over the values. 124 # Check I can enumerate over the values.
122 index = 0 125 index = 0
123 while 1: 126 while 1:
124 try: 127 try:
125 data = EnumValue(sub_key, index) 128 data = EnumValue(sub_key, index)
126 except EnvironmentError: 129 except OSError:
127 break 130 break
128 self.assertEqual(data in test_data, True, 131 self.assertEqual(data in test_data, True,
129 "Didn't read back the correct test data") 132 "Didn't read back the correct test data")
130 index = index + 1 133 index = index + 1
131 self.assertEqual(index, len(test_data), 134 self.assertEqual(index, len(test_data),
132 "Didn't read the correct number of items") 135 "Didn't read the correct number of items")
133 # Check I can directly access each item 136 # Check I can directly access each item
134 for value_name, value_data, value_type in test_data: 137 for value_name, value_data, value_type in test_data:
135 read_val, read_typ = QueryValueEx(sub_key, value_name) 138 read_val, read_typ = QueryValueEx(sub_key, value_name)
136 self.assertEqual(read_val, value_data, 139 self.assertEqual(read_val, value_data,
137 "Could not directly read the value") 140 "Could not directly read the value")
138 self.assertEqual(read_typ, value_type, 141 self.assertEqual(read_typ, value_type,
139 "Could not directly read the value") 142 "Could not directly read the value")
140 sub_key.Close() 143 sub_key.Close()
141 # Enumerate our main key. 144 # Enumerate our main key.
142 read_val = EnumKey(key, 0) 145 read_val = EnumKey(key, 0)
143 self.assertEqual(read_val, subkeystr, "Read subkey value wrong") 146 self.assertEqual(read_val, subkeystr, "Read subkey value wrong")
144 try: 147 try:
145 EnumKey(key, 1) 148 EnumKey(key, 1)
146 self.fail("Was able to get a second key when I only have one!") 149 self.fail("Was able to get a second key when I only have one!")
147 except EnvironmentError: 150 except OSError:
148 pass 151 pass
149 152
150 key.Close() 153 key.Close()
151 154
152 def _delete_test_data(self, root_key, subkeystr="sub_key"): 155 def _delete_test_data(self, root_key, subkeystr="sub_key"):
153 key = OpenKey(root_key, test_key_name, 0, KEY_ALL_ACCESS) 156 key = OpenKey(root_key, test_key_name, 0, KEY_ALL_ACCESS)
154 sub_key = OpenKey(key, subkeystr, 0, KEY_ALL_ACCESS) 157 sub_key = OpenKey(key, subkeystr, 0, KEY_ALL_ACCESS)
155 # It is not necessary to delete the values before deleting 158 # It is not necessary to delete the values before deleting
156 # the key (although subkeys must not exist). We delete them 159 # the key (although subkeys must not exist). We delete them
157 # manually just to prove we can :-) 160 # manually just to prove we can :-)
158 for value_name, value_data, value_type in test_data: 161 for value_name, value_data, value_type in test_data:
159 DeleteValue(sub_key, value_name) 162 DeleteValue(sub_key, value_name)
160 163
161 nkeys, nvalues, since_mod = QueryInfoKey(sub_key) 164 nkeys, nvalues, since_mod = QueryInfoKey(sub_key)
162 self.assertEqual(nkeys, 0, "subkey not empty before delete") 165 self.assertEqual(nkeys, 0, "subkey not empty before delete")
163 self.assertEqual(nvalues, 0, "subkey not empty before delete") 166 self.assertEqual(nvalues, 0, "subkey not empty before delete")
164 sub_key.Close() 167 sub_key.Close()
165 DeleteKey(key, subkeystr) 168 DeleteKey(key, subkeystr)
166 169
167 try: 170 try:
168 # Shouldnt be able to delete it twice! 171 # Shouldnt be able to delete it twice!
169 DeleteKey(key, subkeystr) 172 DeleteKey(key, subkeystr)
170 self.fail("Deleting the key twice succeeded") 173 self.fail("Deleting the key twice succeeded")
171 except EnvironmentError: 174 except OSError:
172 pass 175 pass
173 key.Close() 176 key.Close()
174 DeleteKey(root_key, test_key_name) 177 DeleteKey(root_key, test_key_name)
175 # Opening should now fail! 178 # Opening should now fail!
176 try: 179 try:
177 key = OpenKey(root_key, test_key_name) 180 key = OpenKey(root_key, test_key_name)
178 self.fail("Could open the non-existent key") 181 self.fail("Could open the non-existent key")
179 except WindowsError: # Use this error name this time 182 except OSError: # Use this error name this time
180 pass 183 pass
181 184
182 def _test_all(self, root_key, subkeystr="sub_key"): 185 def _test_all(self, root_key, subkeystr="sub_key"):
183 self._write_test_data(root_key, subkeystr) 186 self._write_test_data(root_key, subkeystr)
184 self._read_test_data(root_key, subkeystr) 187 self._read_test_data(root_key, subkeystr)
185 self._delete_test_data(root_key, subkeystr) 188 self._delete_test_data(root_key, subkeystr)
186 189
187 def _test_named_args(self, key, sub_key): 190 def _test_named_args(self, key, sub_key):
188 with CreateKeyEx(key=key, sub_key=sub_key, reserved=0, 191 with CreateKeyEx(key=key, sub_key=sub_key, reserved=0,
189 access=KEY_ALL_ACCESS) as ckey: 192 access=KEY_ALL_ACCESS) as ckey:
(...skipping 30 matching lines...) Expand all
220 223
221 def test_connect_registry_to_local_machine_works(self): 224 def test_connect_registry_to_local_machine_works(self):
222 # perform minimal ConnectRegistry test which just invokes it 225 # perform minimal ConnectRegistry test which just invokes it
223 h = ConnectRegistry(None, HKEY_LOCAL_MACHINE) 226 h = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
224 self.assertNotEqual(h.handle, 0) 227 self.assertNotEqual(h.handle, 0)
225 h.Close() 228 h.Close()
226 self.assertEqual(h.handle, 0) 229 self.assertEqual(h.handle, 0)
227 230
228 def test_inexistant_remote_registry(self): 231 def test_inexistant_remote_registry(self):
229 connect = lambda: ConnectRegistry("abcdefghijkl", HKEY_CURRENT_USER) 232 connect = lambda: ConnectRegistry("abcdefghijkl", HKEY_CURRENT_USER)
230 self.assertRaises(WindowsError, connect) 233 self.assertRaises(OSError, connect)
231 234
232 def testExpandEnvironmentStrings(self): 235 def testExpandEnvironmentStrings(self):
233 r = ExpandEnvironmentStrings("%windir%\\test") 236 r = ExpandEnvironmentStrings("%windir%\\test")
234 self.assertEqual(type(r), str) 237 self.assertEqual(type(r), str)
235 self.assertEqual(r, os.environ["windir"] + "\\test") 238 self.assertEqual(r, os.environ["windir"] + "\\test")
236 239
237 def test_context_manager(self): 240 def test_context_manager(self):
238 # ensure that the handle is closed if an exception occurs 241 # ensure that the handle is closed if an exception occurs
239 try: 242 try:
240 with ConnectRegistry(None, HKEY_LOCAL_MACHINE) as h: 243 with ConnectRegistry(None, HKEY_LOCAL_MACHINE) as h:
241 self.assertNotEqual(h.handle, 0) 244 self.assertNotEqual(h.handle, 0)
242 raise WindowsError 245 raise OSError
243 except WindowsError: 246 except OSError:
244 self.assertEqual(h.handle, 0) 247 self.assertEqual(h.handle, 0)
245 248
246 def test_changing_value(self): 249 def test_changing_value(self):
247 # Issue2810: A race condition in 2.6 and 3.1 may cause 250 # Issue2810: A race condition in 2.6 and 3.1 may cause
248 # EnumValue or QueryValue to throw "WindowsError: More data is 251 # EnumValue or QueryValue to raise "WindowsError: More data is
249 # available" 252 # available"
250 done = False 253 done = False
251 254
252 class VeryActiveThread(threading.Thread): 255 class VeryActiveThread(threading.Thread):
253 def run(self): 256 def run(self):
254 with CreateKey(HKEY_CURRENT_USER, test_key_name) as key: 257 with CreateKey(HKEY_CURRENT_USER, test_key_name) as key:
255 use_short = True 258 use_short = True
256 long_string = 'x'*2000 259 long_string = 'x'*2000
257 while not done: 260 while not done:
258 s = 'x' if use_short else long_string 261 s = 'x' if use_short else long_string
(...skipping 11 matching lines...) Expand all
270 name = EnumValue(key, i) 273 name = EnumValue(key, i)
271 QueryValue(key, name[0]) 274 QueryValue(key, name[0])
272 finally: 275 finally:
273 done = True 276 done = True
274 thread.join() 277 thread.join()
275 DeleteKey(HKEY_CURRENT_USER, test_key_name+'\\changing_value') 278 DeleteKey(HKEY_CURRENT_USER, test_key_name+'\\changing_value')
276 DeleteKey(HKEY_CURRENT_USER, test_key_name) 279 DeleteKey(HKEY_CURRENT_USER, test_key_name)
277 280
278 def test_long_key(self): 281 def test_long_key(self):
279 # Issue2810, in 2.6 and 3.1 when the key name was exactly 256 282 # Issue2810, in 2.6 and 3.1 when the key name was exactly 256
280 # characters, EnumKey threw "WindowsError: More data is 283 # characters, EnumKey raised "WindowsError: More data is
281 # available" 284 # available"
282 name = 'x'*256 285 name = 'x'*256
283 try: 286 try:
284 with CreateKey(HKEY_CURRENT_USER, test_key_name) as key: 287 with CreateKey(HKEY_CURRENT_USER, test_key_name) as key:
285 SetValue(key, name, REG_SZ, 'x') 288 SetValue(key, name, REG_SZ, 'x')
286 num_subkeys, num_values, t = QueryInfoKey(key) 289 num_subkeys, num_values, t = QueryInfoKey(key)
287 EnumKey(key, 0) 290 EnumKey(key, 0)
288 finally: 291 finally:
289 DeleteKey(HKEY_CURRENT_USER, '\\'.join((test_key_name, name))) 292 DeleteKey(HKEY_CURRENT_USER, '\\'.join((test_key_name, name)))
290 DeleteKey(HKEY_CURRENT_USER, test_key_name) 293 DeleteKey(HKEY_CURRENT_USER, test_key_name)
291 294
292 def test_dynamic_key(self): 295 def test_dynamic_key(self):
293 # Issue2810, when the value is dynamically generated, these 296 # Issue2810, when the value is dynamically generated, these
294 # throw "WindowsError: More data is available" in 2.6 and 3.1 297 # raise "WindowsError: More data is available" in 2.6 and 3.1
295 try: 298 try:
296 EnumValue(HKEY_PERFORMANCE_DATA, 0) 299 EnumValue(HKEY_PERFORMANCE_DATA, 0)
297 except OSError as e: 300 except OSError as e:
298 if e.errno in (errno.EPERM, errno.EACCES): 301 if e.errno in (errno.EPERM, errno.EACCES):
299 self.skipTest("access denied to registry key " 302 self.skipTest("access denied to registry key "
300 "(are you running in a non-interactive session?)") 303 "(are you running in a non-interactive session?)")
301 raise 304 raise
302 QueryValueEx(HKEY_PERFORMANCE_DATA, "") 305 QueryValueEx(HKEY_PERFORMANCE_DATA, "")
303 306
304 # Reflection requires XP x64/Vista at a minimum. XP doesn't have this stuff 307 # Reflection requires XP x64/Vista at a minimum. XP doesn't have this stuff
(...skipping 10 matching lines...) Expand all
315 with self.assertRaises(NotImplementedError): 318 with self.assertRaises(NotImplementedError):
316 DisableReflectionKey(key) 319 DisableReflectionKey(key)
317 with self.assertRaises(NotImplementedError): 320 with self.assertRaises(NotImplementedError):
318 EnableReflectionKey(key) 321 EnableReflectionKey(key)
319 with self.assertRaises(NotImplementedError): 322 with self.assertRaises(NotImplementedError):
320 QueryReflectionKey(key) 323 QueryReflectionKey(key)
321 with self.assertRaises(NotImplementedError): 324 with self.assertRaises(NotImplementedError):
322 DeleteKeyEx(HKEY_CURRENT_USER, test_key_name) 325 DeleteKeyEx(HKEY_CURRENT_USER, test_key_name)
323 finally: 326 finally:
324 DeleteKey(HKEY_CURRENT_USER, test_key_name) 327 DeleteKey(HKEY_CURRENT_USER, test_key_name)
328
329 def test_setvalueex_value_range(self):
330 # Test for Issue #14420, accept proper ranges for SetValueEx.
331 # Py2Reg, which gets called by SetValueEx, was using PyLong_AsLong,
332 # thus raising OverflowError. The implementation now uses
333 # PyLong_AsUnsignedLong to match DWORD's size.
334 try:
335 with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck:
336 self.assertNotEqual(ck.handle, 0)
337 SetValueEx(ck, "test_name", None, REG_DWORD, 0x80000000)
338 finally:
339 DeleteKey(HKEY_CURRENT_USER, test_key_name)
340
341 def test_queryvalueex_return_value(self):
342 # Test for Issue #16759, return unsigned int from QueryValueEx.
343 # Reg2Py, which gets called by QueryValueEx, was returning a value
344 # generated by PyLong_FromLong. The implmentation now uses
345 # PyLong_FromUnsignedLong to match DWORD's size.
346 try:
347 with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck:
348 self.assertNotEqual(ck.handle, 0)
349 test_val = 0x80000000
350 SetValueEx(ck, "test_name", None, REG_DWORD, test_val)
351 ret_val, ret_type = QueryValueEx(ck, "test_name")
352 self.assertEqual(ret_type, REG_DWORD)
353 self.assertEqual(ret_val, test_val)
354 finally:
355 DeleteKey(HKEY_CURRENT_USER, test_key_name)
356
325 357
326 358
327 @unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests") 359 @unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests")
328 class RemoteWinregTests(BaseWinregTests): 360 class RemoteWinregTests(BaseWinregTests):
329 361
330 def test_remote_registry_works(self): 362 def test_remote_registry_works(self):
331 remote_key = ConnectRegistry(REMOTE_NAME, HKEY_CURRENT_USER) 363 remote_key = ConnectRegistry(REMOTE_NAME, HKEY_CURRENT_USER)
332 self._test_all(remote_key) 364 self._test_all(remote_key)
333 365
334 366
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 self.assertNotEqual(key.handle, 0) 400 self.assertNotEqual(key.handle, 0)
369 401
370 # Write a value to what currently is only in the 32-bit area 402 # Write a value to what currently is only in the 32-bit area
371 SetValueEx(created_key, "", 0, REG_SZ, "32KEY") 403 SetValueEx(created_key, "", 0, REG_SZ, "32KEY")
372 404
373 # The key is not reflected until created_key is closed. 405 # The key is not reflected until created_key is closed.
374 # The 64-bit version of the key should not be available yet. 406 # The 64-bit version of the key should not be available yet.
375 open_fail = lambda: OpenKey(HKEY_CURRENT_USER, 407 open_fail = lambda: OpenKey(HKEY_CURRENT_USER,
376 test_reflect_key_name, 0, 408 test_reflect_key_name, 0,
377 KEY_READ | KEY_WOW64_64KEY) 409 KEY_READ | KEY_WOW64_64KEY)
378 self.assertRaises(WindowsError, open_fail) 410 self.assertRaises(OSError, open_fail)
379 411
380 # Now explicitly open the 64-bit version of the key 412 # Now explicitly open the 64-bit version of the key
381 with OpenKey(HKEY_CURRENT_USER, test_reflect_key_name, 0, 413 with OpenKey(HKEY_CURRENT_USER, test_reflect_key_name, 0,
382 KEY_ALL_ACCESS | KEY_WOW64_64KEY) as key: 414 KEY_ALL_ACCESS | KEY_WOW64_64KEY) as key:
383 self.assertNotEqual(key.handle, 0) 415 self.assertNotEqual(key.handle, 0)
384 # Make sure the original value we set is there 416 # Make sure the original value we set is there
385 self.assertEqual("32KEY", QueryValue(key, "")) 417 self.assertEqual("32KEY", QueryValue(key, ""))
386 # Set a new value, which will get reflected to 32-bit 418 # Set a new value, which will get reflected to 32-bit
387 SetValueEx(key, "", 0, REG_SZ, "64KEY") 419 SetValueEx(key, "", 0, REG_SZ, "64KEY")
388 420
(...skipping 19 matching lines...) Expand all
408 self.assertFalse(disabled) 440 self.assertFalse(disabled)
409 441
410 DisableReflectionKey(created_key) 442 DisableReflectionKey(created_key)
411 self.assertTrue(QueryReflectionKey(created_key)) 443 self.assertTrue(QueryReflectionKey(created_key))
412 444
413 # The key is now closed and would normally be reflected to the 445 # The key is now closed and would normally be reflected to the
414 # 64-bit area, but let's make sure that didn't happen. 446 # 64-bit area, but let's make sure that didn't happen.
415 open_fail = lambda: OpenKeyEx(HKEY_CURRENT_USER, 447 open_fail = lambda: OpenKeyEx(HKEY_CURRENT_USER,
416 test_reflect_key_name, 0, 448 test_reflect_key_name, 0,
417 KEY_READ | KEY_WOW64_64KEY) 449 KEY_READ | KEY_WOW64_64KEY)
418 self.assertRaises(WindowsError, open_fail) 450 self.assertRaises(OSError, open_fail)
419 451
420 # Make sure the 32-bit key is actually there 452 # Make sure the 32-bit key is actually there
421 with OpenKeyEx(HKEY_CURRENT_USER, test_reflect_key_name, 0, 453 with OpenKeyEx(HKEY_CURRENT_USER, test_reflect_key_name, 0,
422 KEY_READ | KEY_WOW64_32KEY) as key: 454 KEY_READ | KEY_WOW64_32KEY) as key:
423 self.assertNotEqual(key.handle, 0) 455 self.assertNotEqual(key.handle, 0)
424 finally: 456 finally:
425 DeleteKeyEx(HKEY_CURRENT_USER, test_reflect_key_name, 457 DeleteKeyEx(HKEY_CURRENT_USER, test_reflect_key_name,
426 KEY_WOW64_32KEY, 0) 458 KEY_WOW64_32KEY, 0)
427 459
460 def test_exception_numbers(self):
461 with self.assertRaises(FileNotFoundError) as ctx:
462 QueryValue(HKEY_CLASSES_ROOT, 'some_value_that_does_not_exist')
428 463
429 def test_main(): 464 def test_main():
430 support.run_unittest(LocalWinregTests, RemoteWinregTests, 465 support.run_unittest(LocalWinregTests, RemoteWinregTests,
431 Win64WinregTests) 466 Win64WinregTests)
432 467
433 if __name__ == "__main__": 468 if __name__ == "__main__":
434 if not REMOTE_NAME: 469 if not REMOTE_NAME:
435 print("Remote registry calls can be tested using", 470 print("Remote registry calls can be tested using",
436 "'test_winreg.py --remote \\\\machine_name'") 471 "'test_winreg.py --remote \\\\machine_name'")
437 test_main() 472 test_main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+