Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions
test.test_winreg.BaseWinregTests Class Reference
Inheritance diagram for test.test_winreg.BaseWinregTests:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def setUp
def delete_tree

Private Member Functions

def _write_test_data
def _read_test_data
def _delete_test_data
def _test_all
def _test_named_args

Detailed Description

Definition at line 47 of file test_winreg.py.


Member Function Documentation

def test.test_winreg.BaseWinregTests._delete_test_data (   self,
  root_key,
  subkeystr = "sub_key" 
) [private]

Definition at line 152 of file test_winreg.py.

00152 
00153     def _delete_test_data(self, root_key, subkeystr="sub_key"):
00154         key = OpenKey(root_key, test_key_name, 0, KEY_ALL_ACCESS)
00155         sub_key = OpenKey(key, subkeystr, 0, KEY_ALL_ACCESS)
00156         # It is not necessary to delete the values before deleting
00157         # the key (although subkeys must not exist).  We delete them
00158         # manually just to prove we can :-)
00159         for value_name, value_data, value_type in test_data:
00160             DeleteValue(sub_key, value_name)
00161 
00162         nkeys, nvalues, since_mod = QueryInfoKey(sub_key)
00163         self.assertEqual(nkeys, 0, "subkey not empty before delete")
00164         self.assertEqual(nvalues, 0, "subkey not empty before delete")
00165         sub_key.Close()
00166         DeleteKey(key, subkeystr)
00167 
00168         try:
00169             # Shouldnt be able to delete it twice!
00170             DeleteKey(key, subkeystr)
00171             self.fail("Deleting the key twice succeeded")
00172         except EnvironmentError:
00173             pass
00174         key.Close()
00175         DeleteKey(root_key, test_key_name)
00176         # Opening should now fail!
00177         try:
00178             key = OpenKey(root_key, test_key_name)
00179             self.fail("Could open the non-existent key")
00180         except WindowsError: # Use this error name this time
00181             pass

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_winreg.BaseWinregTests._read_test_data (   self,
  root_key,
  subkeystr = "sub_key",
  OpenKey = OpenKey 
) [private]

Definition at line 112 of file test_winreg.py.

00112 
00113     def _read_test_data(self, root_key, subkeystr="sub_key", OpenKey=OpenKey):
00114         # Check we can get default value for this key.
00115         val = QueryValue(root_key, test_key_name)
00116         self.assertEqual(val, "Default value",
00117                          "Registry didn't give back the correct value")
00118 
00119         key = OpenKey(root_key, test_key_name)
00120         # Read the sub-keys
00121         with OpenKey(key, subkeystr) as sub_key:
00122             # Check I can enumerate over the values.
00123             index = 0
00124             while 1:
00125                 try:
00126                     data = EnumValue(sub_key, index)
00127                 except EnvironmentError:
00128                     break
00129                 self.assertEqual(data in test_data, True,
00130                                  "Didn't read back the correct test data")
00131                 index = index + 1
00132             self.assertEqual(index, len(test_data),
00133                              "Didn't read the correct number of items")
00134             # Check I can directly access each item
00135             for value_name, value_data, value_type in test_data:
00136                 read_val, read_typ = QueryValueEx(sub_key, value_name)
00137                 self.assertEqual(read_val, value_data,
00138                                  "Could not directly read the value")
00139                 self.assertEqual(read_typ, value_type,
00140                                  "Could not directly read the value")
00141         sub_key.Close()
00142         # Enumerate our main key.
00143         read_val = EnumKey(key, 0)
00144         self.assertEqual(read_val, subkeystr, "Read subkey value wrong")
00145         try:
00146             EnumKey(key, 1)
00147             self.fail("Was able to get a second key when I only have one!")
00148         except EnvironmentError:
00149             pass
00150 
00151         key.Close()

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_winreg.BaseWinregTests._test_all (   self,
  root_key,
  subkeystr = "sub_key" 
) [private]

Definition at line 182 of file test_winreg.py.

00182 
00183     def _test_all(self, root_key, subkeystr="sub_key"):
00184         self._write_test_data(root_key, subkeystr)
00185         self._read_test_data(root_key, subkeystr)
00186         self._delete_test_data(root_key, subkeystr)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_winreg.BaseWinregTests._test_named_args (   self,
  key,
  sub_key 
) [private]

Definition at line 187 of file test_winreg.py.

00187 
00188     def _test_named_args(self, key, sub_key):
00189         with CreateKeyEx(key=key, sub_key=sub_key, reserved=0,
00190                          access=KEY_ALL_ACCESS) as ckey:
00191             self.assertTrue(ckey.handle != 0)
00192 
00193         with OpenKeyEx(key=key, sub_key=sub_key, reserved=0,
00194                        access=KEY_ALL_ACCESS) as okey:
00195             self.assertTrue(okey.handle != 0)
00196 

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_winreg.BaseWinregTests._write_test_data (   self,
  root_key,
  subkeystr = "sub_key",
  CreateKey = CreateKey 
) [private]

Definition at line 71 of file test_winreg.py.

00071 
00072                          CreateKey=CreateKey):
00073         # Set the default value for this key.
00074         SetValue(root_key, test_key_name, REG_SZ, "Default value")
00075         key = CreateKey(root_key, test_key_name)
00076         self.assertTrue(key.handle != 0)
00077         # Create a sub-key
00078         sub_key = CreateKey(key, subkeystr)
00079         # Give the sub-key some named values
00080 
00081         for value_name, value_data, value_type in test_data:
00082             SetValueEx(sub_key, value_name, 0, value_type, value_data)
00083 
00084         # Check we wrote as many items as we thought.
00085         nkeys, nvalues, since_mod = QueryInfoKey(key)
00086         self.assertEqual(nkeys, 1, "Not the correct number of sub keys")
00087         self.assertEqual(nvalues, 1, "Not the correct number of values")
00088         nkeys, nvalues, since_mod = QueryInfoKey(sub_key)
00089         self.assertEqual(nkeys, 0, "Not the correct number of sub keys")
00090         self.assertEqual(nvalues, len(test_data),
00091                          "Not the correct number of values")
00092         # Close this key this way...
00093         # (but before we do, copy the key as an integer - this allows
00094         # us to test that the key really gets closed).
00095         int_sub_key = int(sub_key)
00096         CloseKey(sub_key)
00097         try:
00098             QueryInfoKey(int_sub_key)
00099             self.fail("It appears the CloseKey() function does "
00100                       "not close the actual key!")
00101         except EnvironmentError:
00102             pass
00103         # ... and close that key that way :-)
00104         int_key = int(key)
00105         key.Close()
00106         try:
00107             QueryInfoKey(int_key)
00108             self.fail("It appears the key.Close() function "
00109                       "does not close the actual key!")
00110         except EnvironmentError:
00111             pass

Here is the call graph for this function:

Here is the caller graph for this function:

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

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:

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:


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