1515import win32timezone
1616import winerror
1717from win32api import CloseHandle , GetCurrentProcessId , OpenProcess
18- from win32com import universal
1918from win32com .client import (
2019 VARIANT ,
2120 CastTo ,
2524 gencache ,
2625 register_record_class ,
2726)
27+ from win32com .universal import RegisterInterfaces
2828from win32process import GetProcessMemoryInfo
2929
3030# This test uses a Python implemented COM server - ensure correctly registered.
4646 print (f"The PyCOMTest module can not be located or generated.\n { importMsg } \n " )
4747 raise RuntimeError (importMsg ) from error
4848
49- # We had a bg where RegisterInterfaces would fail if gencache had
50- # already been run - exercise that here
51- universal .RegisterInterfaces ("{6BCDCB60-5605-11D0-AE5F-CADD4C000000}" , 0 , 1 , 1 )
52-
5349verbose = 0
5450
5551
@@ -175,7 +171,7 @@ def _DumpFireds(self):
175171 if not self .fireds :
176172 print ("ERROR: Nothing was received!" )
177173 for firedId , no in self .fireds .items ():
178- progress ("ID %d fired %d times" % ( firedId , no ) )
174+ progress (f "ID { firedId } fired { no } times" )
179175
180176
181177# Test everything which can be tested using both the "dynamic" and "generated"
@@ -891,34 +887,39 @@ def TestVTableMI():
891887 pass
892888
893889
894- def TestQueryInterface (long_lived_server = 0 , iterations = 5 ):
890+ def TestQueryInterface (long_lived_server = False , iterations = 5 ):
895891 tester = win32com .client .Dispatch ("PyCOMTest.PyCOMTest" )
896892 if long_lived_server :
897893 # Create a local server
898894 t0 = win32com .client .Dispatch (
899895 "Python.Test.PyCOMTest" , clsctx = pythoncom .CLSCTX_LOCAL_SERVER
900896 )
901- # Request custom interfaces a number of times
902- prompt = [
903- "Testing QueryInterface without long-lived local-server #%d of %d..." ,
904- "Testing QueryInterface with long-lived local-server #%d of %d..." ,
905- ]
897+ # Request custom interfaces a number of time
906898
907899 for i in range (iterations ):
908- progress (prompt [long_lived_server != 0 ] % (i + 1 , iterations ))
900+ progress (
901+ f"Testing QueryInterface "
902+ + ("with" if long_lived_server else "without" )
903+ + f" long-lived local-server #{ i + 1 } of { iterations } ..."
904+ )
909905 tester .TestQueryInterface ()
910906
911907
912908class Tester (win32com .test .util .TestCase ):
913- def testVTableInProc (self ):
909+ def testRegisterInterfacesAfterGencache (self ) -> None :
910+ # We had a bug where RegisterInterfaces would fail if gencache had
911+ # already been run - exercise that here
912+ RegisterInterfaces ("{6BCDCB60-5605-11D0-AE5F-CADD4C000000}" , 0 , 1 , 1 )
913+
914+ def testVTableInProc (self ) -> None :
914915 # We used to crash running this the second time - do it a few times
915916 for i in range (3 ):
916- progress ("Testing VTables in-process #%d..." % (i + 1 ))
917+ progress (f "Testing VTables in-process #{ (i + 1 )} ..." )
917918 TestVTable (pythoncom .CLSCTX_INPROC_SERVER )
918919
919- def testVTableLocalServer (self ):
920+ def testVTableLocalServer (self ) -> None :
920921 for i in range (3 ):
921- progress ("Testing VTables out-of-process #%d..." % (i + 1 ))
922+ progress (f "Testing VTables out-of-process #{ (i + 1 )} ..." )
922923 TestVTable (pythoncom .CLSCTX_LOCAL_SERVER )
923924
924925 def testVTable2 (self ):
@@ -930,15 +931,15 @@ def testVTableMI(self):
930931 TestVTableMI ()
931932
932933 def testMultiQueryInterface (self ):
933- TestQueryInterface (0 , 6 )
934+ TestQueryInterface (False , 6 )
934935 # When we use the custom interface in the presence of a long-lived
935936 # local server, i.e. a local server that is already running when
936937 # we request an instance of our COM object, and remains afterwards,
937938 # then after repeated requests to create an instance of our object
938939 # the custom interface disappears -- i.e. QueryInterface fails with
939940 # E_NOINTERFACE. Set the upper range of the following test to 2 to
940- # pass this test, i.e. TestQueryInterface(1, 2)
941- TestQueryInterface (1 , 6 )
941+ # pass this test, i.e. TestQueryInterface(True, 2)
942+ TestQueryInterface (True , 6 )
942943
943944 def testDynamic (self ):
944945 TestDynamic ()
0 commit comments