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

Side by Side Diff: Lib/test/test_winreg.py

Issue 16510: Using appropriate checks in tests
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:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_weakset.py ('k') | Lib/test/test_with.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 break 68 break
69 self.delete_tree(hkey, subsubkey) 69 self.delete_tree(hkey, subsubkey)
70 CloseKey(hkey) 70 CloseKey(hkey)
71 DeleteKey(root, subkey) 71 DeleteKey(root, subkey)
72 72
73 def _write_test_data(self, root_key, subkeystr="sub_key", 73 def _write_test_data(self, root_key, subkeystr="sub_key",
74 CreateKey=CreateKey): 74 CreateKey=CreateKey):
75 # Set the default value for this key. 75 # Set the default value for this key.
76 SetValue(root_key, test_key_name, REG_SZ, "Default value") 76 SetValue(root_key, test_key_name, REG_SZ, "Default value")
77 key = CreateKey(root_key, test_key_name) 77 key = CreateKey(root_key, test_key_name)
78 self.assertTrue(key.handle != 0) 78 self.assertNotEqual(key.handle, 0)
79 # Create a sub-key 79 # Create a sub-key
80 sub_key = CreateKey(key, subkeystr) 80 sub_key = CreateKey(key, subkeystr)
81 # Give the sub-key some named values 81 # Give the sub-key some named values
82 82
83 for value_name, value_data, value_type in test_data: 83 for value_name, value_data, value_type in test_data:
84 SetValueEx(sub_key, value_name, 0, value_type, value_data) 84 SetValueEx(sub_key, value_name, 0, value_type, value_data)
85 85
86 # Check we wrote as many items as we thought. 86 # Check we wrote as many items as we thought.
87 nkeys, nvalues, since_mod = QueryInfoKey(key) 87 nkeys, nvalues, since_mod = QueryInfoKey(key)
88 self.assertEqual(nkeys, 1, "Not the correct number of sub keys") 88 self.assertEqual(nkeys, 1, "Not the correct number of sub keys")
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 pass 183 pass
184 184
185 def _test_all(self, root_key, subkeystr="sub_key"): 185 def _test_all(self, root_key, subkeystr="sub_key"):
186 self._write_test_data(root_key, subkeystr) 186 self._write_test_data(root_key, subkeystr)
187 self._read_test_data(root_key, subkeystr) 187 self._read_test_data(root_key, subkeystr)
188 self._delete_test_data(root_key, subkeystr) 188 self._delete_test_data(root_key, subkeystr)
189 189
190 def _test_named_args(self, key, sub_key): 190 def _test_named_args(self, key, sub_key):
191 with CreateKeyEx(key=key, sub_key=sub_key, reserved=0, 191 with CreateKeyEx(key=key, sub_key=sub_key, reserved=0,
192 access=KEY_ALL_ACCESS) as ckey: 192 access=KEY_ALL_ACCESS) as ckey:
193 self.assertTrue(ckey.handle != 0) 193 self.assertNotEqual(ckey.handle, 0)
194 194
195 with OpenKeyEx(key=key, sub_key=sub_key, reserved=0, 195 with OpenKeyEx(key=key, sub_key=sub_key, reserved=0,
196 access=KEY_ALL_ACCESS) as okey: 196 access=KEY_ALL_ACCESS) as okey:
197 self.assertTrue(okey.handle != 0) 197 self.assertNotEqual(okey.handle, 0)
198 198
199 199
200 class LocalWinregTests(BaseWinregTests): 200 class LocalWinregTests(BaseWinregTests):
201 201
202 def test_registry_works(self): 202 def test_registry_works(self):
203 self._test_all(HKEY_CURRENT_USER) 203 self._test_all(HKEY_CURRENT_USER)
204 self._test_all(HKEY_CURRENT_USER, "日本-subkey") 204 self._test_all(HKEY_CURRENT_USER, "日本-subkey")
205 205
206 def test_registry_works_extended_functions(self): 206 def test_registry_works_extended_functions(self):
207 # Substitute the regular CreateKey and OpenKey calls with their 207 # Substitute the regular CreateKey and OpenKey calls with their
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 463
464 def test_main(): 464 def test_main():
465 support.run_unittest(LocalWinregTests, RemoteWinregTests, 465 support.run_unittest(LocalWinregTests, RemoteWinregTests,
466 Win64WinregTests) 466 Win64WinregTests)
467 467
468 if __name__ == "__main__": 468 if __name__ == "__main__":
469 if not REMOTE_NAME: 469 if not REMOTE_NAME:
470 print("Remote registry calls can be tested using", 470 print("Remote registry calls can be tested using",
471 "'test_winreg.py --remote \\\\machine_name'") 471 "'test_winreg.py --remote \\\\machine_name'")
472 test_main() 472 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_weakset.py ('k') | Lib/test/test_with.py » ('j') | no next file with comments »

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