comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

Quit using `shdocvw.dll`(or `ieframe.dll`) in tests

Open junkmd opened this issue 3 years ago • 3 comments

Internet Explorer will be end of support. https://blogs.windows.com/windowsexperience/2021/05/19/the-future-of-internet-explorer-on-windows-10-is-in-microsoft-edge/

Currently, some tests using IE were skipped, (see https://github.com/enthought/comtypes/issues/267#issuecomment-1029305670 by @dmwyatt, #271, #298)

However, there still remains tests using shdocvw.dll(ieframe.dll), which provides IE and web browser classes. This will likely cause us to inadvertently use the IE class.

To be samples for testing, there is no need to use the DLL, and we plan to replace it with something more universal.

junkmd avatar Jun 15 '22 13:06 junkmd

This issue contains restoring tests using InternetExplorer and have been skipped.

Like below:

https://github.com/enthought/comtypes/blob/782444957e1133bb40825576540b8a5fc79dd398/comtypes/test/test_client.py#L37-L70

    def test_remote(self):
        obj = comtypes.client.CreateObject(
            UIAutomationClient.CUIAutomation().IPersist_GetClassID(),
            interface=UIAutomationClient.IUIAutomation,
            clsctx=comtypes.CLSCTX_INPROC_SERVER,
            machine="localhost")
        self.assertTrue(isinstance(obj, POINTER(UIAutomationClient.IUIAutomation)))
        self.assertTrue(isinstance(obj, UIAutomationClient.IUIAutomation))

    def test_server_info(self):
        serverinfo = COSERVERINFO()
        serverinfo.pwszName = "localhost"
        pServerInfo = byref(serverinfo)
        self.assertRaises(
            ValueError,
            comtypes.client.CreateObject,
            UIAutomationClient.CUIAutomation().IPersist_GetClassID(),
            machine="localhost",
            pServerInfo=pServerInfo)
        obj = comtypes.client.CreateObject(
            UIAutomationClient.CUIAutomation().IPersist_GetClassID(),
            interface=UIAutomationClient.IUIAutomation,
            clsctx=comtypes.CLSCTX_INPROC_SERVER,
            pServerInfo=pServerInfo)
        self.assertTrue(isinstance(obj, POINTER(UIAutomationClient.IUIAutomation)))
        self.assertTrue(isinstance(obj, UIAutomationClient.IUIAutomation))

In most cases, I believe that testing the behavior of COM object methods is unnecessary. When testing methods, including their behavior, we should try them on more primitive objects (such as Scripting.IDictionary) rather than on objects with more complex necessary conditions (such as UIAutomationClient.CUIAutomation and some web browser).

junkmd avatar Jun 15 '22 15:06 junkmd

we should try them on more primitive objects

100% concur

dmwyatt avatar Jun 15 '22 19:06 dmwyatt

Ideas for test_csesensitivity

import unittest

from comtypes.client import GetModule
GetModule("UIAutomationCore.dll")
from comtypes.gen import UIAutomationClient as uia


class TestCase(unittest.TestCase):
    def test(self):
        self.assertTrue(issubclass(uia.IUIAutomation2, uia.IUIAutomation))
        self.assertTrue(issubclass(uia.IUIAutomation3, uia.IUIAutomation2))
        for name in uia.IUIAutomation.__map_case__:
            self.assertTrue(name in uia.IUIAutomation2.__map_case__, "%s missing" % name)
            self.assertTrue(name in uia.IUIAutomation3.__map_case__, "%s missing" % name)

        for name in uia.IUIAutomation2.__map_case__:
            self.assertTrue(name in uia.IUIAutomation3.__map_case__, "%s missing" % name)


if __name__ == "__main__":
    unittest.main()

import unittest

from comtypes.client import GetModule
GetModule(("{C866CA3A-32F7-11D2-9602-00C04F8EE628}",))
from comtypes.gen import SpeechLib as sapi


class TestCase(unittest.TestCase):
    def test(self):
        self.assertTrue(issubclass(sapi.IStream, sapi.ISequentialStream))
        self.assertTrue(issubclass(sapi.ISpStreamFormat, sapi.IStream))

        # names in the base class __map_case__ must also appear in the
        # subclass.
        for name in sapi.ISequentialStream.__map_case__:
            self.assertTrue(name in sapi.IStream.__map_case__, "%s missing" % name)
            self.assertTrue(name in sapi.ISpStreamFormat.__map_case__, "%s missing" % name)

        for name in sapi.IStream.__map_case__:
            self.assertTrue(name in sapi.ISpStreamFormat.__map_case__, "%s missing" % name)


if __name__ == "__main__":
    unittest.main()

junkmd avatar Jul 02 '22 02:07 junkmd