-
-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[test\test_basic.py] Use OleDLL instead of windll #764
[test\test_basic.py] Use OleDLL instead of windll #764
Conversation
c8d1c7c
to
a9f0558
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here’s my perspective on this test:
Given the objectives of test_refcounts
and test_qi
, any test double that serves as a pointer to IUnknown
should suffice. However, I think it's better to avoid approaches that rely on specific custom interface definitions.
Since test_identity
calls CreateTypeLib
(that indirectly calls _CreateTypeLib2
), I don’t see much value in testing _CreateTypeLib2
bound to ICreateTypeLib2
specifically in this context.
comtypes/comtypes/test/test_basic.py
Lines 101 to 115 in a9f0558
def test_identity(self): | |
# COM indentity rules | |
# these should be identical | |
a = POINTER(IUnknown)() | |
b = POINTER(IUnknown)() | |
self.assertEqual(a, b) | |
self.assertEqual(hash(a), hash(b)) | |
from comtypes.typeinfo import CreateTypeLib | |
# we do not save the lib, so no file will be created. | |
# these should NOT be identical | |
a = CreateTypeLib("blahblah") | |
b = CreateTypeLib("spam") |
It might be worth considering defining a single-responsibility function to create this test double, duplicating _CreateTypeLib2
from typeinfo.py
and make the “_CreateTypeLib2
that accepts POINTER(IUnknown)
”.
What are your thoughts on this?
I prefer to adhere strictly to the actual parameters of CreateTypeLib2 to maintain accuracy and consistency. Since What do you think? |
Indeed, comments can be a powerful tool in situations like this. Considering a scenario where future maintainers might need to modify these tests, it’s important to document our thought process here. Please make a commit to add comments. |
a9f0558
to
fcd7e40
Compare
Done, let me know what you think. |
comtypes/test/test_basic.py
Outdated
@@ -20,17 +21,21 @@ def test_release(self): | |||
POINTER(IUnknown)() | |||
|
|||
def test_refcounts(self): | |||
p = POINTER(IUnknown)() | |||
windll.oleaut32.CreateTypeLib2(1, "blabla", byref(p)) | |||
# Since IUnknown behaves like an abstract class, the reference counting behavior cannot be tested directly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the previous code demonstrates, QueryInterface
and refcount tests can be performed with this package’s IUnknown
.
To better reflect the accurate situation, I think a comments like “COM interfaces can use AddRef
, Release
, and QueryInterface
inherited from IUnknown
” would be more appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- # Since IUnknown behaves like an abstract class, the reference counting behavior cannot be tested directly.
- # Although we use ICreateTypeLib2 here, the aim is to validate the reference counting behavior of IUnknown.
+ # Since all COM interfaces derive from IUnknown and have the same reference counting behavior, any interface
+ # — whether ICreateTypeLib2 or otherwise — could be used for this test.
Would this be sufficient?
A comment like this would help future maintainers understand that this test is NOT strictly tied to ICreateTypeLib2
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I applied your suggestion
comtypes/test/test_basic.py
Outdated
@@ -20,17 +21,21 @@ def test_release(self): | |||
POINTER(IUnknown)() | |||
|
|||
def test_refcounts(self): | |||
p = POINTER(IUnknown)() | |||
windll.oleaut32.CreateTypeLib2(1, "blabla", byref(p)) | |||
# Since IUnknown behaves like an abstract class, the reference counting behavior cannot be tested directly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- # Since IUnknown behaves like an abstract class, the reference counting behavior cannot be tested directly.
- # Although we use ICreateTypeLib2 here, the aim is to validate the reference counting behavior of IUnknown.
+ # Since all COM interfaces derive from IUnknown and have the same reference counting behavior, any interface
+ # — whether ICreateTypeLib2 or otherwise — could be used for this test.
Would this be sufficient?
A comment like this would help future maintainers understand that this test is NOT strictly tied to ICreateTypeLib2
.
comtypes/test/test_basic.py
Outdated
# Since IUnknown behaves like an abstract class, the reference counting behavior cannot be tested directly. | ||
# Although we use ICreateTypeLib2 here, the aim is to validate the reference counting behavior of IUnknown. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- # Since IUnknown behaves like an abstract class, the reference counting behavior cannot be tested directly.
- # Although we use ICreateTypeLib2 here, the aim is to validate the reference counting behavior of IUnknown.
+ # Since all COM interfaces derive from IUnknown and have the same QueryInterface behavior, any interface
+ # — whether ICreateTypeLib2 or otherwise — could be used for this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I applied your suggestion
fcd7e40
to
be229d9
Compare
be229d9
to
bbcd6a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
See #735
IUnknown to ICreateTypeLib2 because CreateTypeLib2 doesn't take IUnknown as a parameter.