Skip to content
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

Quit using shdocvw.dll(or ieframe.dll) in tests #302

Open
junkmd opened this issue Jun 15, 2022 · 3 comments
Open

Quit using shdocvw.dll(or ieframe.dll) in tests #302

junkmd opened this issue Jun 15, 2022 · 3 comments
Labels
tests enhance or fix tests

Comments

@junkmd
Copy link
Collaborator

junkmd commented Jun 15, 2022

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 #267 (comment) 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
Copy link
Collaborator Author

junkmd commented Jun 15, 2022

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

Like below:

@ut.skip(
"This test uses IE which is not available on all machines anymore. "
"Find another API to use."
)
def test_remote(self):
ie = comtypes.client.CreateObject("InternetExplorer.Application",
machine="localhost")
self.assertEqual(ie.Visible, False)
ie.Visible = 1
# on a remote machine, this may not work. Probably depends on
# how the server is run.
self.assertEqual(ie.Visible, True)
self.assertEqual(0, ie.Quit()) # 0 == S_OK
@ut.skip(
"This test uses IE which is not available on all machines anymore. "
"Find another API to use."
)
def test_server_info(self):
serverinfo = COSERVERINFO()
serverinfo.pwszName = 'localhost'
pServerInfo = byref(serverinfo)
self.assertRaises(ValueError, comtypes.client.CreateObject,
"InternetExplorer.Application", machine='localhost',
pServerInfo=pServerInfo)
ie = comtypes.client.CreateObject("InternetExplorer.Application",
pServerInfo=pServerInfo)
self.assertEqual(ie.Visible, False)
ie.Visible = 1
# on a remote machine, this may not work. Probably depends on
# how the server is run.
self.assertEqual(ie.Visible, True)
self.assertEqual(0, ie.Quit()) # 0 == S_OK

    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).

@dmwyatt
Copy link
Contributor

dmwyatt commented Jun 15, 2022

we should try them on more primitive objects

100% concur

@junkmd
Copy link
Collaborator Author

junkmd commented Jul 2, 2022

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests enhance or fix tests
Projects
None yet
Development

No branches or pull requests

3 participants