Code review comment for lp:~thomir-deactivatedaccount/autopilot/merge-private-code

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Hi Oliver

> I built a package from this MR, installed on my raring desktop, and tried to
> run the autopilot tests for lp:webbrowser-app.
>

Autopilot 1.3 (the version number has now been updated) contains API breaks from 1.2, you won't be able to run your old tests without changing them. However, see my comments below:

> Listing the tests fails with the following error:
>
> ImportError: cannot import name QtIntrospectionTestMixin
>
> but can be easily fixed by simply removing this import, and not inheriting
> from QtIntrospectionTestMixin.

Yes - these Mixin Classes were rather nasty, and were the cause of many errors.

>
> Running the tests fails with the following error:
>
> _StringException: Traceback (most recent call last):
> File "/tmp/webbrowser-
> app/tests/autopilot/webbrowser_app/tests/test_mainwindow.py", line 263, in
> setUp
> super(TestMainWindowStartOpenRemotePageBase, self).setUp()
> File "/tmp/webbrowser-app/tests/autopilot/webbrowser_app/tests/__init__.py",
> line 161, in setUp
> super(BrowserTestCaseBaseWithHTTPServer, self).setUp()
> File "/tmp/webbrowser-app/tests/autopilot/webbrowser_app/tests/__init__.py",
> line 45, in setUp
> self.launch_test_local()
> File "/tmp/webbrowser-app/tests/autopilot/webbrowser_app/tests/__init__.py",
> line 62, in launch_test_local
> *self.ARGS)
> File "/usr/lib/python2.7/dist-packages/autopilot/testcase.py", line 450, in
> launch_test_application
> process = launch_application(launcher, application, *arguments, **kwargs)
> File "/usr/lib/python2.7/dist-packages/autopilot/introspection/__init__.py",
> line 80, in launch_application
> path, args = launcher.prepare_environment(application, list(arguments))
> AttributeError: 'NoneType' object has no attribute 'prepare_environment'
>
> Looks like a problem in autopilot itself.

Kind of :)

We should raise a better exception in this case, which I have just comitted to this branch:

        if launcher is None:
            raise RuntimeError("Autopilot could not determine the correct \
                introspection type to use. You can specify one by overriding \
                the AutopilotTestCase.pick_app_launcher method.")

What's happening is that autopilot is trying to guess what kind of introspection support to load - Gtk or Qt. Currently it simply does 'ldd <app_path>' and looks for 'qtcore' or 'gtk' - clearly this isn't going to work for python/Qt or python/Gtk apps. I have plans to extend that auto-detection routine, so it works for python scripts automatically. However, you can specify the introspection type manually, by overriding the pick_app_launcher method. In fact, there' san autopilot test that does exactly that, in autopilot/tests/test_ap_apps.py - I've pasted the relevant sections below:

class QtTests(ApplicationTests):

    def pick_app_launcher(self, app_path):
        # force Qt app introspection:
        from autopilot.introspection.qt import QtApplicationLauncher
        return QtApplicationLauncher()

    def test_can_launch_qt_script(self):
        path = self.write_script(dedent("""\
            #!/usr/bin/python
            from PyQt4.QtGui import QMainWindow, QApplication
            from sys import argv

            app = QApplication(argv)
            win = QMainWindow()
            win.show()
            app.exec_()
            """))
        app_proxy = self.launch_test_application(path)
        self.assertTrue(app_proxy is not None)

Thanks for testing autopilot 1.3 - rest assured that we're fixing these problems ASAP :)

« Back to merge proposal