@@ -172,10 +172,17 @@ def TestCommon(o, is_generated):
172
172
progress ("Checking getting/passing IUnknown" )
173
173
check_get_set (o .GetSetUnknown , o )
174
174
progress ("Checking getting/passing IDispatch" )
175
- if not isinstance (o .GetSetDispatch (o ), o .__class__ ):
175
+ # This might be called with either the interface or the CoClass - but these
176
+ # functions always return from the interface.
177
+ expected_class = o .__class__
178
+ # CoClass instances have `default_interface`
179
+ expected_class = getattr (expected_class , "default_interface" , expected_class )
180
+ if not isinstance (o .GetSetDispatch (o ), expected_class ):
176
181
raise error ("GetSetDispatch failed: %r" % (o .GetSetDispatch (o ),))
177
182
progress ("Checking getting/passing IDispatch of known type" )
178
- if o .GetSetInterface (o ).__class__ != o .__class__ :
183
+ expected_class = o .__class__
184
+ expected_class = getattr (expected_class , "default_interface" , expected_class )
185
+ if o .GetSetInterface (o ).__class__ != expected_class :
179
186
raise error ("GetSetDispatch failed" )
180
187
181
188
progress ("Checking misc args" )
@@ -408,6 +415,16 @@ def TestGenerated():
408
415
counter = EnsureDispatch ("PyCOMTest.SimpleCounter" )
409
416
TestCounter (counter , True )
410
417
418
+ # This dance lets us get a CoClass even though it's not explicitly registered.
419
+ # This is `CoPyComTest`
420
+ from win32com .client .CLSIDToClass import GetClass
421
+ coclass_o = GetClass ("{8EE0C520-5605-11D0-AE5F-CADD4C000000}" )()
422
+ TestCommon (coclass_o , True )
423
+
424
+ # This is `CoSimpleCounter` and the counter tests should work.
425
+ coclass = GetClass ("{B88DD310-BAE8-11D0-AE86-76F2C1000000}" )()
426
+ TestCounter (coclass , True )
427
+
411
428
# XXX - this is failing in dynamic tests, but should work fine.
412
429
i1 , i2 = o .GetMultipleInterfaces ()
413
430
if not isinstance (i1 , DispatchBaseClass ) or not isinstance (i2 , DispatchBaseClass ):
0 commit comments