MCPcopy Index your code
hub / github.com/python/cpython / _write_test_data

Method _write_test_data

Lib/test/test_winreg.py:88–128  ·  view source on GitHub ↗
(self, root_key, subkeystr="sub_key",
                         CreateKey=CreateKey)

Source from the content-addressed store, hash-verified

86 DeleteKey(root, subkey)
87
88 def _write_test_data(self, root_key, subkeystr="sub_key",
89 CreateKey=CreateKey):
90 # Set the default value for this key.
91 SetValue(root_key, test_key_name, REG_SZ, "Default value")
92 key = CreateKey(root_key, test_key_name)
93 self.assertTrue(key.handle != 0)
94 # Create a sub-key
95 sub_key = CreateKey(key, subkeystr)
96 # Give the sub-key some named values
97
98 for value_name, value_data, value_type in test_data:
99 SetValueEx(sub_key, value_name, 0, value_type, value_data)
100
101 # Check we wrote as many items as we thought.
102 nkeys, nvalues, since_mod = QueryInfoKey(key)
103 self.assertEqual(nkeys, 1, "Not the correct number of sub keys")
104 self.assertEqual(nvalues, 1, "Not the correct number of values")
105 nkeys, nvalues, since_mod = QueryInfoKey(sub_key)
106 self.assertEqual(nkeys, 0, "Not the correct number of sub keys")
107 self.assertEqual(nvalues, len(test_data),
108 "Not the correct number of values")
109 # Close this key this way...
110 # (but before we do, copy the key as an integer - this allows
111 # us to test that the key really gets closed).
112 int_sub_key = int(sub_key)
113 CloseKey(sub_key)
114 try:
115 QueryInfoKey(int_sub_key)
116 self.fail("It appears the CloseKey() function does "
117 "not close the actual key!")
118 except OSError:
119 pass
120 # ... and close that key that way :-)
121 int_key = int(key)
122 key.Close()
123 try:
124 QueryInfoKey(int_key)
125 self.fail("It appears the key.Close() function "
126 "does not close the actual key!")
127 except OSError:
128 pass
129 def _read_test_data(self, root_key, subkeystr="sub_key", OpenKey=OpenKey):
130 # Check we can get default value for this key.
131 val = QueryValue(root_key, test_key_name)

Callers 2

_test_allMethod · 0.95

Calls 4

assertTrueMethod · 0.80
CloseMethod · 0.80
assertEqualMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected