Skip to content

Commit 86d39f5

Browse files
authored
test: Fix error message validation in test_puredispatch.py. (#891)
Corrected the usage of `assertRaises` in `test_puredispatch.py`. Previously, `msg` was mistakenly used as error message validation. This has been updated to use `assertRaisesRegex` with a compiled regex pattern to ensure proper validation of the expected `ValueError` messages.
1 parent 7c01639 commit 86d39f5

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

comtypes/test/test_puredispatch.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
import unittest as ut
23
import winreg
34

@@ -12,6 +13,8 @@
1213
HKCR = 0 # HKEY_CLASSES_ROOT
1314
HKCU = 1 # HKEY_CURRENT_USER
1415

16+
NAMED_PARAM_ERRMSG = "named parameters not yet implemented"
17+
1518

1619
class Test_Installer(ut.TestCase):
1720
def test_registry_value_with_root_key_value(self):
@@ -58,20 +61,20 @@ def test_registry_value_with_named_params(self):
5861
# if named arguments are passed to prevent invalid calls.
5962
# TODO: After named parameters are supported, this will become a test to
6063
# assert the return value.
61-
ERRMSG = "named parameters not yet implemented"
62-
with self.assertRaises(ValueError, msg=ERRMSG):
64+
PTN = re.compile(rf"^{re.escape(NAMED_PARAM_ERRMSG)}$")
65+
with self.assertRaisesRegex(ValueError, PTN):
6366
inst.RegistryValue(Root=HKCR, Key=".txt", Value="") # type: ignore
64-
with self.assertRaises(ValueError, msg=ERRMSG):
67+
with self.assertRaisesRegex(ValueError, PTN):
6568
inst.RegistryValue(Value="", Root=HKCR, Key=".txt") # type: ignore
66-
with self.assertRaises(ValueError, msg=ERRMSG):
69+
with self.assertRaisesRegex(ValueError, PTN):
6770
inst.RegistryValue(HKCR, Key=".txt", Value="") # type: ignore
68-
with self.assertRaises(ValueError, msg=ERRMSG):
71+
with self.assertRaisesRegex(ValueError, PTN):
6972
inst.RegistryValue(HKCR, ".txt", Value="") # type: ignore
70-
with self.assertRaises(ValueError, msg=ERRMSG):
73+
with self.assertRaisesRegex(ValueError, PTN):
7174
inst.RegistryValue(Root=HKCU, Key=r"Control Panel\Desktop") # type: ignore
72-
with self.assertRaises(ValueError, msg=ERRMSG):
75+
with self.assertRaisesRegex(ValueError, PTN):
7376
inst.RegistryValue(Key=r"Control Panel\Desktop", Root=HKCR) # type: ignore
74-
with self.assertRaises(ValueError, msg=ERRMSG):
77+
with self.assertRaisesRegex(ValueError, PTN):
7578
inst.RegistryValue(HKCR, Key=r"Control Panel\Desktop") # type: ignore
7679

7780
def test_product_state(self):

0 commit comments

Comments
 (0)