Back to index

python3.2  3.2.2
Public Member Functions
test.test_winreg.LocalWinregTests Class Reference
Inheritance diagram for test.test_winreg.LocalWinregTests:
Inheritance graph
[legend]
Collaboration diagram for test.test_winreg.LocalWinregTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_registry_works
def test_registry_works_extended_functions
def test_named_arguments
def test_connect_registry_to_local_machine_works
def test_inexistant_remote_registry
def testExpandEnvironmentStrings
def test_context_manager
def test_changing_value
def test_long_key
def test_dynamic_key
def test_reflection_unsupported
def setUp
def delete_tree

Detailed Description

Definition at line 197 of file test_winreg.py.


Member Function Documentation

def test.test_winreg.BaseWinregTests.delete_tree (   self,
  root,
  subkey 
) [inherited]

Definition at line 54 of file test_winreg.py.

00054 
00055     def delete_tree(self, root, subkey):
00056         try:
00057             hkey = OpenKey(root, subkey, KEY_ALL_ACCESS)
00058         except WindowsError:
00059             # subkey does not exist
00060             return
00061         while True:
00062             try:
00063                 subsubkey = EnumKey(hkey, 0)
00064             except WindowsError:
00065                 # no more subkeys
00066                 break
00067             self.delete_tree(hkey, subsubkey)
00068         CloseKey(hkey)
00069         DeleteKey(root, subkey)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_winreg.BaseWinregTests.setUp (   self) [inherited]

Definition at line 49 of file test_winreg.py.

00049 
00050     def setUp(self):
00051         # Make sure that the test key is absent when the test
00052         # starts.
00053         self.delete_tree(HKEY_CURRENT_USER, test_key_name)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 246 of file test_winreg.py.

00246 
00247     def test_changing_value(self):
00248         # Issue2810: A race condition in 2.6 and 3.1 may cause
00249         # EnumValue or QueryValue to throw "WindowsError: More data is
00250         # available"
00251         done = False
00252 
00253         class VeryActiveThread(threading.Thread):
00254             def run(self):
00255                 with CreateKey(HKEY_CURRENT_USER, test_key_name) as key:
00256                     use_short = True
00257                     long_string = 'x'*2000
00258                     while not done:
00259                         s = 'x' if use_short else long_string
00260                         use_short = not use_short
00261                         SetValue(key, 'changing_value', REG_SZ, s)
00262 
00263         thread = VeryActiveThread()
00264         thread.start()
00265         try:
00266             with CreateKey(HKEY_CURRENT_USER,
00267                            test_key_name+'\\changing_value') as key:
00268                 for _ in range(1000):
00269                     num_subkeys, num_values, t = QueryInfoKey(key)
00270                     for i in range(num_values):
00271                         name = EnumValue(key, i)
00272                         QueryValue(key, name[0])
00273         finally:
00274             done = True
00275             thread.join()
00276             DeleteKey(HKEY_CURRENT_USER, test_key_name+'\\changing_value')
00277             DeleteKey(HKEY_CURRENT_USER, test_key_name)

Here is the call graph for this function:

Definition at line 221 of file test_winreg.py.

00221 
00222     def test_connect_registry_to_local_machine_works(self):
00223         # perform minimal ConnectRegistry test which just invokes it
00224         h = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
00225         self.assertNotEqual(h.handle, 0)
00226         h.Close()
00227         self.assertEqual(h.handle, 0)

Here is the call graph for this function:

Definition at line 237 of file test_winreg.py.

00237 
00238     def test_context_manager(self):
00239         # ensure that the handle is closed if an exception occurs
00240         try:
00241             with ConnectRegistry(None, HKEY_LOCAL_MACHINE) as h:
00242                 self.assertNotEqual(h.handle, 0)
00243                 raise WindowsError
00244         except WindowsError:
00245             self.assertEqual(h.handle, 0)

Here is the call graph for this function:

Definition at line 292 of file test_winreg.py.

00292 
00293     def test_dynamic_key(self):
00294         # Issue2810, when the value is dynamically generated, these
00295         # throw "WindowsError: More data is available" in 2.6 and 3.1
00296         EnumValue(HKEY_PERFORMANCE_DATA, 0)
00297         QueryValueEx(HKEY_PERFORMANCE_DATA, "")

Definition at line 228 of file test_winreg.py.

00228 
00229     def test_inexistant_remote_registry(self):
00230         connect = lambda: ConnectRegistry("abcdefghijkl", HKEY_CURRENT_USER)
00231         self.assertRaises(WindowsError, connect)

Here is the call graph for this function:

Definition at line 278 of file test_winreg.py.

00278 
00279     def test_long_key(self):
00280         # Issue2810, in 2.6 and 3.1 when the key name was exactly 256
00281         # characters, EnumKey threw "WindowsError: More data is
00282         # available"
00283         name = 'x'*256
00284         try:
00285             with CreateKey(HKEY_CURRENT_USER, test_key_name) as key:
00286                 SetValue(key, name, REG_SZ, 'x')
00287                 num_subkeys, num_values, t = QueryInfoKey(key)
00288                 EnumKey(key, 0)
00289         finally:
00290             DeleteKey(HKEY_CURRENT_USER, '\\'.join((test_key_name, name)))
00291             DeleteKey(HKEY_CURRENT_USER, test_key_name)

Definition at line 215 of file test_winreg.py.

00215 
00216     def test_named_arguments(self):
00217         self._test_named_args(HKEY_CURRENT_USER, test_key_name)
00218         # Use the regular DeleteKey to clean up
00219         # DeleteKeyEx takes named args and is tested separately
00220         DeleteKey(HKEY_CURRENT_USER, test_key_name)

Here is the call graph for this function:

Definition at line 301 of file test_winreg.py.

00301 
00302     def test_reflection_unsupported(self):
00303         try:
00304             with CreateKey(HKEY_CURRENT_USER, test_key_name) as ck:
00305                 self.assertNotEqual(ck.handle, 0)
00306 
00307             key = OpenKey(HKEY_CURRENT_USER, test_key_name)
00308             self.assertNotEqual(key.handle, 0)
00309 
00310             with self.assertRaises(NotImplementedError):
00311                 DisableReflectionKey(key)
00312             with self.assertRaises(NotImplementedError):
00313                 EnableReflectionKey(key)
00314             with self.assertRaises(NotImplementedError):
00315                 QueryReflectionKey(key)
00316             with self.assertRaises(NotImplementedError):
00317                 DeleteKeyEx(HKEY_CURRENT_USER, test_key_name)
00318         finally:
00319             DeleteKey(HKEY_CURRENT_USER, test_key_name)
00320 
00321 
@unittest.skipUnless(REMOTE_NAME, "Skipping remote registry tests")

Here is the call graph for this function:

Definition at line 199 of file test_winreg.py.

00199 
00200     def test_registry_works(self):
00201         self._test_all(HKEY_CURRENT_USER)
00202         self._test_all(HKEY_CURRENT_USER, "日本-subkey")

Here is the call graph for this function:

Definition at line 203 of file test_winreg.py.

00203 
00204     def test_registry_works_extended_functions(self):
00205         # Substitute the regular CreateKey and OpenKey calls with their
00206         # extended counterparts.
00207         # Note: DeleteKeyEx is not used here because it is platform dependent
00208         cke = lambda key, sub_key: CreateKeyEx(key, sub_key, 0, KEY_ALL_ACCESS)
00209         self._write_test_data(HKEY_CURRENT_USER, CreateKey=cke)
00210 
00211         oke = lambda key, sub_key: OpenKeyEx(key, sub_key, 0, KEY_READ)
00212         self._read_test_data(HKEY_CURRENT_USER, OpenKey=oke)
00213 
00214         self._delete_test_data(HKEY_CURRENT_USER)

Here is the call graph for this function:

Definition at line 232 of file test_winreg.py.

00232 
00233     def testExpandEnvironmentStrings(self):
00234         r = ExpandEnvironmentStrings("%windir%\\test")
00235         self.assertEqual(type(r), str)
00236         self.assertEqual(r, os.environ["windir"] + "\\test")

Here is the call graph for this function:


The documentation for this class was generated from the following file: