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

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

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 6 years, 3 months ago
Right Patch Set: Created 5 years, 10 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")
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 self.assertRaises(OSError, open_fail) 450 self.assertRaises(OSError, open_fail)
448 451
449 # Make sure the 32-bit key is actually there 452 # Make sure the 32-bit key is actually there
450 with OpenKeyEx(HKEY_CURRENT_USER, test_reflect_key_name, 0, 453 with OpenKeyEx(HKEY_CURRENT_USER, test_reflect_key_name, 0,
451 KEY_READ | KEY_WOW64_32KEY) as key: 454 KEY_READ | KEY_WOW64_32KEY) as key:
452 self.assertNotEqual(key.handle, 0) 455 self.assertNotEqual(key.handle, 0)
453 finally: 456 finally:
454 DeleteKeyEx(HKEY_CURRENT_USER, test_reflect_key_name, 457 DeleteKeyEx(HKEY_CURRENT_USER, test_reflect_key_name,
455 KEY_WOW64_32KEY, 0) 458 KEY_WOW64_32KEY, 0)
456 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')
457 463
458 def test_main(): 464 def test_main():
459 support.run_unittest(LocalWinregTests, RemoteWinregTests, 465 support.run_unittest(LocalWinregTests, RemoteWinregTests,
460 Win64WinregTests) 466 Win64WinregTests)
461 467
462 if __name__ == "__main__": 468 if __name__ == "__main__":
463 if not REMOTE_NAME: 469 if not REMOTE_NAME:
464 print("Remote registry calls can be tested using", 470 print("Remote registry calls can be tested using",
465 "'test_winreg.py --remote \\\\machine_name'") 471 "'test_winreg.py --remote \\\\machine_name'")
466 test_main() 472 test_main()
LEFTRIGHT

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