Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f82d9b5

Browse files
committed
Patch #1076: Use wide API for registry functions.
1 parent 5d12abe commit f82d9b5

2 files changed

Lines changed: 128 additions & 182 deletions

File tree

Lib/test/test_winreg.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
# Test the windows specific win32reg module.
23
# Only win32reg functions not hit here: FlushKey, LoadKey and SaveKey
34

@@ -17,17 +18,19 @@
1718
("Raw Data", b"binary\x00data", REG_BINARY),
1819
("Big String", "x"*(2**14-1), REG_SZ),
1920
("Big Binary", b"x"*(2**14), REG_BINARY),
21+
# Two and three kanjis, meaning: "Japan" and "Japanese")
22+
("Japanese 日本", "日本語", REG_SZ),
2023
]
2124

2225
class WinregTests(unittest.TestCase):
2326
remote_name = None
2427

25-
def WriteTestData(self, root_key):
28+
def WriteTestData(self, root_key, subkeystr="sub_key"):
2629
# Set the default value for this key.
2730
SetValue(root_key, test_key_name, REG_SZ, "Default value")
2831
key = CreateKey(root_key, test_key_name)
2932
# Create a sub-key
30-
sub_key = CreateKey(key, "sub_key")
33+
sub_key = CreateKey(key, subkeystr)
3134
# Give the sub-key some named values
3235

3336
for value_name, value_data, value_type in test_data:
@@ -62,15 +65,15 @@ def WriteTestData(self, root_key):
6265
except EnvironmentError:
6366
pass
6467

65-
def ReadTestData(self, root_key):
68+
def ReadTestData(self, root_key, subkeystr="sub_key"):
6669
# Check we can get default value for this key.
6770
val = QueryValue(root_key, test_key_name)
6871
self.assertEquals(val, "Default value",
6972
"Registry didn't give back the correct value")
7073

7174
key = OpenKey(root_key, test_key_name)
7275
# Read the sub-keys
73-
sub_key = OpenKey(key, "sub_key")
76+
sub_key = OpenKey(key, subkeystr)
7477
# Check I can enumerate over the values.
7578
index = 0
7679
while 1:
@@ -93,7 +96,7 @@ def ReadTestData(self, root_key):
9396
sub_key.Close()
9497
# Enumerate our main key.
9598
read_val = EnumKey(key, 0)
96-
self.assertEquals(read_val, "sub_key", "Read subkey value wrong")
99+
self.assertEquals(read_val, subkeystr, "Read subkey value wrong")
97100
try:
98101
EnumKey(key, 1)
99102
self.fail("Was able to get a second key when I only have one!")
@@ -102,9 +105,9 @@ def ReadTestData(self, root_key):
102105

103106
key.Close()
104107

105-
def DeleteTestData(self, root_key):
108+
def DeleteTestData(self, root_key, subkeystr="sub_key"):
106109
key = OpenKey(root_key, test_key_name, 0, KEY_ALL_ACCESS)
107-
sub_key = OpenKey(key, "sub_key", 0, KEY_ALL_ACCESS)
110+
sub_key = OpenKey(key, subkeystr, 0, KEY_ALL_ACCESS)
108111
# It is not necessary to delete the values before deleting
109112
# the key (although subkeys must not exist). We delete them
110113
# manually just to prove we can :-)
@@ -115,11 +118,11 @@ def DeleteTestData(self, root_key):
115118
self.assertEquals(nkeys, 0, "subkey not empty before delete")
116119
self.assertEquals(nvalues, 0, "subkey not empty before delete")
117120
sub_key.Close()
118-
DeleteKey(key, "sub_key")
121+
DeleteKey(key, subkeystr)
119122

120123
try:
121124
# Shouldnt be able to delete it twice!
122-
DeleteKey(key, "sub_key")
125+
DeleteKey(key, subkeystr)
123126
self.fail("Deleting the key twice succeeded")
124127
except EnvironmentError:
125128
pass
@@ -132,13 +135,14 @@ def DeleteTestData(self, root_key):
132135
except WindowsError: # Use this error name this time
133136
pass
134137

135-
def TestAll(self, root_key):
136-
self.WriteTestData(root_key)
137-
self.ReadTestData(root_key)
138-
self.DeleteTestData(root_key)
138+
def TestAll(self, root_key, subkeystr="sub_key"):
139+
self.WriteTestData(root_key, subkeystr)
140+
self.ReadTestData(root_key, subkeystr)
141+
self.DeleteTestData(root_key, subkeystr)
139142

140143
def testLocalMachineRegistryWorks(self):
141144
self.TestAll(HKEY_CURRENT_USER)
145+
self.TestAll(HKEY_CURRENT_USER, "日本-subkey")
142146

143147
def testConnectRegistryToLocalMachineWorks(self):
144148
# perform minimal ConnectRegistry test which just invokes it

0 commit comments

Comments
 (0)