summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_winreg.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-06-07 23:12:44 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-06-07 23:12:44 (GMT)
commit64092a56ec2f9278cbee033fc123352cbb74aaa4 (patch)
tree632e1a38a8219550bbcd190ed7db5caad048e28d /Lib/test/test_winreg.py
parentb4347a259cc48fa1b30d3c1f3e543e4780a98f33 (diff)
downloadcpython-64092a56ec2f9278cbee033fc123352cbb74aaa4.zip
cpython-64092a56ec2f9278cbee033fc123352cbb74aaa4.tar.gz
cpython-64092a56ec2f9278cbee033fc123352cbb74aaa4.tar.bz2
backport r73273
Diffstat (limited to 'Lib/test/test_winreg.py')
-rw-r--r--Lib/test/test_winreg.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py
index 1eaa930..4453afe 100644
--- a/Lib/test/test_winreg.py
+++ b/Lib/test/test_winreg.py
@@ -35,6 +35,27 @@ if test_support.have_unicode:
class WinregTests(unittest.TestCase):
remote_name = None
+ def setUp(self):
+ # Make sure that the test key is absent when the test
+ # starts.
+ self.delete_tree(HKEY_CURRENT_USER, test_key_name)
+
+ def delete_tree(self, root, subkey):
+ try:
+ hkey = OpenKey(root, subkey, KEY_ALL_ACCESS)
+ except WindowsError:
+ # subkey does not exist
+ return
+ while True:
+ try:
+ subsubkey = EnumKey(hkey, 0)
+ except WindowsError:
+ # no more subkeys
+ break
+ self.delete_tree(hkey, subsubkey)
+ CloseKey(hkey)
+ DeleteKey(root, subkey)
+
def WriteTestData(self, root_key):
# Set the default value for this key.
SetValue(root_key, test_key_name, REG_SZ, "Default value")