Skip to content

Commit d470b62

Browse files
authored
modernize test_client (#466)
* change from udf `silence_stdout` to stdlib `contextlib.contextmanager` * remove `sys.version_info` bridges * remove excessive blank lines
1 parent 04037ae commit d470b62

File tree

1 file changed

+1
-21
lines changed

1 file changed

+1
-21
lines changed

comtypes/test/test_client.py

+1-21
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,6 @@
1212
from comtypes.gen import Scripting
1313

1414

15-
if sys.version_info >= (3, 0):
16-
text_type = str
17-
else:
18-
text_type = unicode
19-
20-
21-
# HACK: Prefer to use `contextlib.redirect_stdout`, but it's New in version 3.4
22-
@contextlib.contextmanager
23-
def silence_stdout():
24-
old_target = sys.stdout
25-
try:
26-
with open(os.devnull, "w") as new_target:
27-
sys.stdout = new_target
28-
yield new_target
29-
finally:
30-
sys.stdout = old_target
31-
32-
3315
class Test_GetModule(ut.TestCase):
3416
def test_tlib_string(self):
3517
mod = comtypes.client.GetModule("scrrun.dll")
@@ -140,7 +122,6 @@ def test_clsid(self):
140122

141123
def test_clsid_string(self):
142124
# create from string clsid
143-
comtypes.client.CreateObject(text_type(Scripting.Dictionary._reg_clsid_))
144125
comtypes.client.CreateObject(str(Scripting.Dictionary._reg_clsid_))
145126

146127
def test_remote(self):
@@ -267,9 +248,8 @@ def test_returns_other_than_enum_members(self):
267248
# float (Constant c_float)
268249
self.assertEqual(consts.Speech_Default_Weight, sapi.Speech_Default_Weight)
269250

270-
@ut.skipUnless(sys.version_info >= (3, 0), "Some words are not in Python2 keywords")
271251
def test_munged_definitions(self):
272-
with silence_stdout(): # supress warnings
252+
with contextlib.redirect_stdout(None): # supress warnings
273253
MSVidCtlLib = comtypes.client.GetModule("msvidctl.dll")
274254
consts = comtypes.client.Constants("msvidctl.dll")
275255
# `None` is a Python3 keyword.

0 commit comments

Comments
 (0)