Bug 1641649 - Moar Python 3 support updates for Marionette harness. r=marionette-reviewers,whimboo
authorBob Clary <bclary@bclary.com>
Thu, 04 Jun 2020 14:13:01 +0000
changeset 533900 05abde20a94b913447b8279ea6d7035b1266d17a
parent 533899 709e96d0590f4a37db4d8f64077f11221e3816c4
child 533901 9725a27f0a9d9dbbd72b381eb62112d62a028378
push id37480
push userncsoregi@mozilla.com
push dateThu, 04 Jun 2020 22:00:12 +0000
treeherdermozilla-central@e33aea19d0c5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarionette-reviewers, whimboo
bugs1641649
milestone79.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1641649 - Moar Python 3 support updates for Marionette harness. r=marionette-reviewers,whimboo Differential Revision: https://phabricator.services.mozilla.com/D77347
testing/marionette/client/marionette_driver/geckoinstance.py
testing/marionette/harness/marionette_harness/marionette_test/testcases.py
testing/marionette/harness/marionette_harness/runner/base.py
testing/marionette/harness/marionette_harness/tests/harness_unit/test_httpd.py
testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_harness.py
testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_runner.py
testing/marionette/harness/marionette_harness/tests/harness_unit/test_serve.py
testing/marionette/harness/marionette_harness/tests/unit/test_context.py
testing/marionette/mach_test_package_commands.py
--- a/testing/marionette/client/marionette_driver/geckoinstance.py
+++ b/testing/marionette/client/marionette_driver/geckoinstance.py
@@ -291,17 +291,17 @@ class GeckoInstance(object):
         try:
             if not app and kwargs["bin"] is not None:
                 app_id = mozversion.get_version(binary=kwargs["bin"])["application_id"]
                 app = app_ids[app_id]
 
             instance_class = apps[app]
         except (IOError, KeyError):
             exc, val, tb = sys.exc_info()
-            msg = 'Application "{0}" unknown (should be one of {1})'.format(app, apps.keys())
+            msg = 'Application "{0}" unknown (should be one of {1})'.format(app, list(apps.keys()))
             reraise(NotImplementedError, NotImplementedError(msg), tb)
 
         return instance_class(*args, **kwargs)
 
     def start(self):
         self._update_profile(self.profile)
         self.runner = self.runner_class(**self._get_runner_args())
         self.runner.start()
--- a/testing/marionette/harness/marionette_harness/marionette_test/testcases.py
+++ b/testing/marionette/harness/marionette_harness/marionette_test/testcases.py
@@ -120,16 +120,21 @@ class CommonTestCase(unittest.TestCase):
         addSkip = getattr(result, 'addSkip', None)
         if addSkip is not None:
             addSkip(self, reason)
         else:
             warnings.warn("TestResult has no addSkip method, skips not reported",
                           RuntimeWarning, 2)
             result.addSuccess(self)
 
+    def assertRaisesRegxp(self, expected_exception, expected_regexp, callable_obj=None,
+                          *args, **kwargs):
+        return six.assertRaisesRegex(self, expected_exception, expected_regexp,
+                                     callable_obj=None, *args, **kwargs)
+
     def run(self, result=None):
         # Bug 967566 suggests refactoring run, which would hopefully
         # mean getting rid of this inner function, which only sits
         # here to reduce code duplication:
         def expected_failure(result, exc_info):
             addExpectedFailure = getattr(result, "addExpectedFailure", None)
             if addExpectedFailure is not None:
                 addExpectedFailure(self, exc_info)
--- a/testing/marionette/harness/marionette_harness/runner/base.py
+++ b/testing/marionette/harness/marionette_harness/runner/base.py
@@ -13,16 +13,18 @@ import sys
 import time
 import traceback
 import unittest
 
 from argparse import ArgumentParser
 from collections import defaultdict
 from copy import deepcopy
 
+import six
+
 import mozinfo
 import moznetwork
 import mozprofile
 import mozversion
 
 from manifestparser import TestManifest
 from manifestparser.filters import tags
 from marionette_driver.marionette import Marionette
@@ -633,17 +635,17 @@ class BaseMarionetteTestRunner(object):
     def testvars(self):
         if self._testvars is not None:
             return self._testvars
 
         self._testvars = {}
 
         def update(d, u):
             """Update a dictionary that may contain nested dictionaries."""
-            for k, v in u.iteritems():
+            for k, v in six.iteritems(u):
                 o = d.get(k, {})
                 if isinstance(v, dict) and isinstance(o, dict):
                     d[k] = update(d.get(k, {}), v)
                 else:
                     d[k] = u[k]
             return d
 
         json_testvars = self._load_testvars()
--- a/testing/marionette/harness/marionette_harness/tests/harness_unit/test_httpd.py
+++ b/testing/marionette/harness/marionette_harness/tests/harness_unit/test_httpd.py
@@ -4,16 +4,19 @@
 
 from __future__ import absolute_import
 
 import json
 import os
 import types
 import urllib2
 
+import six
+from six.moves.urllib_request import urlopen
+
 import mozunit
 import pytest
 
 from wptserve.handlers import json_handler
 
 from marionette_harness.runner import httpd
 
 here = os.path.abspath(os.path.dirname(__file__))
@@ -37,29 +40,29 @@ def test_ctor():
 def test_start_stop(server):
     server.start()
     server.stop()
 
 
 def test_get_url(server):
     server.start()
     url = server.get_url("/")
-    assert isinstance(url, types.StringTypes)
+    assert isinstance(url, six.string_types)
     assert "http://" in url
 
     server.stop()
     with pytest.raises(httpd.NotAliveError):
         server.get_url("/")
 
 
 def test_doc_root(server):
     server.start()
-    assert isinstance(server.doc_root, types.StringTypes)
+    assert isinstance(server.doc_root, six.string_types)
     server.stop()
-    assert isinstance(server.doc_root, types.StringTypes)
+    assert isinstance(server.doc_root, six.string_types)
 
 
 def test_router(server):
     assert server.router is not None
 
 
 def test_routes(server):
     assert server.routes is not None
@@ -78,15 +81,15 @@ def test_handler(server):
     def handler(request, response):
         return {"count": counter}
 
     route = ("GET", "/httpd/test_handler", handler)
     server.router.register(*route)
     server.start()
 
     url = server.get_url("/httpd/test_handler")
-    body = urllib2.urlopen(url).read()
+    body = urlopen(url).read()
     res = json.loads(body)
     assert res["count"] == counter
 
 
 if __name__ == "__main__":
     mozunit.main('-p', 'no:terminalreporter', '--log-tbpl=-', '--capture', 'no')
--- a/testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_harness.py
+++ b/testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_harness.py
@@ -80,17 +80,17 @@ def test_call_harness_with_no_args_yield
         return_value={'tests': []}
     ) as parse_args:
         failed_or_crashed = MarionetteHarness(runner_class).run()
         assert parse_args.call_count == 1
     assert failed_or_crashed == 0
 
 
 def test_args_passed_to_runner_class(mach_parsed_kwargs, runner_class):
-    arg_list = mach_parsed_kwargs.keys()
+    arg_list = list(mach_parsed_kwargs.keys())
     arg_list.remove('tests')
     mach_parsed_kwargs.update([(a, getattr(sentinel, a)) for a in arg_list])
     harness = MarionetteHarness(runner_class, args=mach_parsed_kwargs)
     harness.process_args = Mock()
     harness.run()
     for arg in arg_list:
         assert harness._runner_class.call_args[1][arg] is getattr(sentinel, arg)
 
--- a/testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_runner.py
+++ b/testing/marionette/harness/marionette_harness/tests/harness_unit/test_marionette_runner.py
@@ -104,17 +104,17 @@ def manifest_with_tests(request):
     included = []
     if 'enabled' in request.param:
         included += [(u'test_expected_pass.py', 'pass'),
                      (u'test_expected_fail.py', 'fail')]
     if 'disabled' in request.param:
         included += [(u'test_pass_disabled.py', 'pass', 'skip-if: true'),
                      (u'test_fail_disabled.py', 'fail', 'skip-if: true')]
     keys = ('path', 'expected', 'disabled')
-    active_tests = [dict(zip(keys, values)) for values in included]
+    active_tests = [dict(list(zip(keys, values))) for values in included]
 
     return ManifestFixture(request.param, active_tests)
 
 
 def test_args_passed_to_driverclass(mock_runner):
     built_kwargs = {'arg1': 'value1', 'arg2': 'value2'}
     mock_runner._build_kwargs = Mock(return_value=built_kwargs)
     with pytest.raises(IOError):
--- a/testing/marionette/harness/marionette_harness/tests/harness_unit/test_serve.py
+++ b/testing/marionette/harness/marionette_harness/tests/harness_unit/test_serve.py
@@ -1,16 +1,18 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import
 
 import types
 
+import six
+
 import mozunit
 import pytest
 
 from marionette_harness.runner import serve
 from marionette_harness.runner.serve import iter_proc, iter_url
 
 
 def teardown_function(func):
@@ -32,17 +34,17 @@ def test_globals():
 
 
 def test_start():
     serve.start()
     assert len(serve.servers) == 2
     assert "http" in serve.servers
     assert "https" in serve.servers
     for url in iter_url(serve.servers):
-        assert isinstance(url, types.StringTypes)
+        assert isinstance(url, six.string_types)
 
 
 def test_start_with_custom_root(tmpdir_factory):
     tdir = tmpdir_factory.mktemp("foo")
     serve.start(str(tdir))
     for server in iter_proc(serve.servers):
         assert server.doc_root == tdir
 
@@ -51,17 +53,17 @@ def test_iter_proc():
     serve.start()
     for server in iter_proc(serve.servers):
         server.stop()
 
 
 def test_iter_url():
     serve.start()
     for url in iter_url(serve.servers):
-        assert isinstance(url, types.StringTypes)
+        assert isinstance(url, six.string_types)
 
 
 def test_where_is():
     serve.start()
     assert serve.where_is("/") == serve.servers["http"][1].get_url("/")
     assert serve.where_is("/", on="https") == serve.servers["https"][1].get_url("/")
 
 
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_context.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_context.py
@@ -13,44 +13,44 @@ class ContextTestCase(MarionetteTestCase
 
     def setUp(self):
         super(ContextTestCase, self).setUp()
 
         # shortcuts to improve readability of these tests
         self.chrome = self.marionette.CONTEXT_CHROME
         self.content = self.marionette.CONTEXT_CONTENT
 
-        self.assertEquals(self.get_context(), self.content)
+        self.assertEqual(self.get_context(), self.content)
 
         test_url = self.marionette.absolute_url("empty.html")
         self.marionette.navigate(test_url)
 
     def get_context(self):
         return self.marionette._send_message("Marionette:GetContext", key="value")
 
 
 class TestSetContext(ContextTestCase):
 
     def test_switch_context(self):
         self.marionette.set_context(self.chrome)
-        self.assertEquals(self.get_context(), self.chrome)
+        self.assertEqual(self.get_context(), self.chrome)
 
         self.marionette.set_context(self.content)
-        self.assertEquals(self.get_context(), self.content)
+        self.assertEqual(self.get_context(), self.content)
 
     def test_invalid_context(self):
         with self.assertRaises(ValueError):
             self.marionette.set_context("foobar")
 
 
 class TestUsingContext(ContextTestCase):
 
     def test_set_different_context_using_with_block(self):
         with self.marionette.using_context(self.chrome):
-            self.assertEquals(self.get_context(), self.chrome)
+            self.assertEqual(self.get_context(), self.chrome)
         self.assertEquals(self.get_context(), self.content)
 
     def test_set_same_context_using_with_block(self):
         with self.marionette.using_context(self.content):
             self.assertEquals(self.get_context(), self.content)
         self.assertEquals(self.get_context(), self.content)
 
     def test_nested_with_blocks(self):
--- a/testing/marionette/mach_test_package_commands.py
+++ b/testing/marionette/mach_test_package_commands.py
@@ -29,17 +29,17 @@ def run_marionette(context, **kwargs):
     args.binary = args.binary or context.firefox_bin
 
     test_root = os.path.join(context.package_root, 'marionette', 'tests')
     if not args.tests:
         args.tests = [os.path.join(test_root, 'testing', 'marionette', 'harness',
                                    'marionette_harness', 'tests', 'unit-tests.ini')]
 
     normalize = partial(context.normalize_test_path, test_root)
-    args.tests = map(normalize, args.tests)
+    args.tests = list(map(normalize, args.tests))
 
     commandline.add_logging_group(parser)
     parser.verify_usage(args)
 
     args.logger = commandline.setup_logging("Marionette Unit Tests",
                                             args,
                                             {"mach": sys.stdout})
     status = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()