Bug 1471920 - [mozversion] Enable some tests on Python 3 by using shutil.which in mozbuild where available;r?davehunt
MozReview-Commit-ID: 81TPUyrjUtA
--- a/python/mozbuild/mozbuild/base.py
+++ b/python/mozbuild/mozbuild/base.py
@@ -6,17 +6,22 @@ from __future__ import absolute_import,
import json
import logging
import mozpack.path as mozpath
import multiprocessing
import os
import subprocess
import sys
-import which
+
+try:
+ from shutil import which
+except ImportError:
+ # shutil.which is not available in Python 2.7
+ import which
from mach.mixin.process import ProcessExecutionMixin
from mozversioncontrol import (
get_repository_from_build_config,
get_repository_object,
InvalidRepoPath,
)
--- a/testing/mozbase/mozlog/mozlog/commandline.py
+++ b/testing/mozbase/mozlog/mozlog/commandline.py
@@ -259,17 +259,17 @@ def setup_logging(logger, args, defaults
# or ['valgrind']
if parts[0] == 'log' and values is not None:
if len(parts) == 1 or parts[1] not in log_formatters:
continue
if len(parts) == 2:
_, formatter = parts
for value in values:
found = True
- if isinstance(value, six.string_types):
+ if isinstance(value, basestring):
value = log_file(value)
if value == sys.stdout:
found_stdout_logger = True
formatters[formatter].append(value)
if len(parts) == 3:
_, formatter, opt = parts
if formatter not in formatter_options:
formatter_options[formatter] = default_formatter_options(formatter,
--- a/testing/mozbase/mozlog/mozlog/formatters/machformatter.py
+++ b/testing/mozbase/mozlog/mozlog/formatters/machformatter.py
@@ -57,17 +57,17 @@ class MachFormatter(base.BaseFormatter):
def _get_test_id(self, data):
test_id = data.get("test")
if isinstance(test_id, list):
test_id = tuple(test_id)
return test_id
def _get_file_name(self, test_id):
- if isinstance(test_id, (str, six.text_type)):
+ if isinstance(test_id, (str, unicode)):
return test_id
if isinstance(test_id, tuple):
return "".join(test_id)
assert False, "unexpected test_id"
def suite_start(self, data):
--- a/testing/mozbase/mozlog/mozlog/formatters/tbplformatter.py
+++ b/testing/mozbase/mozlog/mozlog/formatters/tbplformatter.py
@@ -253,17 +253,17 @@ class TbplFormatter(BaseFormatter):
def suite_end(self, data):
start_time = self.suite_start_time
time = int((data["time"] - start_time) / 1000)
return "SUITE-END | took %is\n" % time
def test_id(self, test_id):
- if isinstance(test_id, (str, six.text_type)):
+ if isinstance(test_id, (str, unicode)):
return test_id
else:
return tuple(test_id)
@output_subtests
def valgrind_error(self, data):
rv = "TEST-UNEXPECTED-VALGRIND-ERROR | " + data['primary'] + "\n"
for line in data['secondary']:
--- a/testing/mozbase/mozlog/mozlog/formatters/xunit.py
+++ b/testing/mozbase/mozlog/mozlog/formatters/xunit.py
@@ -5,17 +5,17 @@ from xml.etree import ElementTree
import six
from . import base
def format_test_id(test_id):
"""Take a test id and return something that looks a bit like
a class path"""
- if not isinstance(test_id, six.string_types):
+ if type(test_id) not in types.StringTypes:
# Not sure how to deal with reftests yet
raise NotImplementedError
# Turn a path into something like a class heirachy
return test_id.replace('.', '_').replace('/', ".")
class XUnitFormatter(base.BaseFormatter):
--- a/testing/mozbase/mozlog/mozlog/handlers/base.py
+++ b/testing/mozbase/mozlog/mozlog/handlers/base.py
@@ -93,16 +93,16 @@ class StreamHandler(BaseHandler):
def __call__(self, data):
"""Write a log message.
:param data: Structured log message dictionary."""
formatted = self.formatter(data)
if not formatted:
return
with self._lock:
- if isinstance(formatted, six.text_type):
+ if isinstance(formatted, unicode):
self.stream.write(formatted.encode("utf-8", "replace"))
elif isinstance(formatted, str):
self.stream.write(formatted)
else:
assert False, "Got output from the formatter of an unexpected type"
self.stream.flush()
--- a/testing/mozbase/mozlog/mozlog/logtypes.py
+++ b/testing/mozbase/mozlog/mozlog/logtypes.py
@@ -155,25 +155,25 @@ class ContainerType(DataType):
return item_type
class Unicode(DataType):
def convert(self, data):
if isinstance(data, six.text_type):
return data
- if isinstance(data, str):
+ if isinstance(data, unicode):
return data.decode("utf8", "replace")
return six.text_type(data)
class TestId(DataType):
def convert(self, data):
- if isinstance(data, six.text_type):
+ if isinstance(data, unicode):
return data
elif isinstance(data, bytes):
return data.decode("utf-8", "replace")
elif isinstance(data, (tuple, list)):
# This is really a bit of a hack; should really split out convertors from the
# fields they operate on
func = Unicode(None).convert
return tuple(func(item) for item in data)
@@ -212,17 +212,17 @@ class Dict(ContainerType):
return {key_type.convert(k): value_type.convert(v) for k, v in dict(data).items()}
class List(ContainerType):
def convert(self, data):
# while dicts and strings _can_ be cast to lists,
# doing so is likely not intentional behaviour
- if isinstance(data, (six.string_types, dict)):
+ if isinstance(data, (basestring, dict)):
raise ValueError("Expected list but got %s" % type(data))
return [self.item_type.convert(item) for item in data]
class TestList(DataType):
"""A TestList is a list of tests that can be either keyed by a group name,
or specified as a flat list.
"""
--- a/testing/mozbase/mozlog/mozlog/pytest_mozlog/plugin.py
+++ b/testing/mozbase/mozlog/mozlog/pytest_mozlog/plugin.py
@@ -85,17 +85,17 @@ class MozLog(object):
if hasattr(report, 'wasxfail'):
expected = 'FAIL'
if report.failed or report.outcome == 'rerun':
status = 'FAIL' if report.when == 'call' else 'ERROR'
if report.skipped:
status = 'SKIP' if not hasattr(report, 'wasxfail') else 'FAIL'
if report.longrepr is not None:
longrepr = report.longrepr
- if isinstance(longrepr, six.string_types):
+ if isinstance(longrepr, basestring):
# When using pytest-xdist, longrepr is serialised as a str
message = stack = longrepr
if longrepr.startswith('[XPASS(strict)]'):
# Strict expected failures have an outcome of failed when
# they unexpectedly pass.
expected, status = ('FAIL', 'PASS')
elif hasattr(longrepr, "reprcrash"):
# For failures, longrepr is a ReprExceptionInfo
--- a/testing/mozbase/mozlog/mozlog/scripts/unstable.py
+++ b/testing/mozbase/mozlog/mozlog/scripts/unstable.py
@@ -11,17 +11,17 @@ import six
class StatusHandler(reader.LogHandler):
def __init__(self):
self.run_info = None
self.statuses = defaultdict(lambda: defaultdict(
lambda: defaultdict(lambda: defaultdict(int))))
def test_id(self, test):
- if type(test) in (str, six.text_type):
+ if type(test) in (str, unicode):
return test
else:
return tuple(test)
def suite_start(self, item):
self.run_info = tuple(sorted(item.get("run_info", {}).items()))
def test_status(self, item):
--- a/testing/mozbase/mozlog/tests/manifest.ini
+++ b/testing/mozbase/mozlog/tests/manifest.ini
@@ -1,9 +1,9 @@
[DEFAULT]
subsuite = mozbase, os == "linux"
[test_logger.py]
-skip-if = python == 3
+
[test_logtypes.py]
[test_formatters.py]
-skip-if = python == 3
+
[test_structured.py]
-skip-if = python == 3
+
--- a/testing/mozbase/mozversion/tests/manifest.ini
+++ b/testing/mozbase/mozversion/tests/manifest.ini
@@ -1,5 +1,5 @@
[DEFAULT]
subsuite = mozbase, os == "linux"
-skip-if = python == 3
[test_binary.py]
[test_apk.py]
+skip-if = python == 3
--- a/third_party/python/which/which.py
+++ b/third_party/python/which/which.py
@@ -276,17 +276,17 @@ def whichall(command, path=None, verbose
def main(argv):
all = 0
verbose = 0
altpath = None
exts = None
try:
optlist, args = getopt.getopt(argv[1:], 'haVvqp:e:',
['help', 'all', 'version', 'verbose', 'quiet', 'path=', 'exts='])
- except getopt.GetoptError, msg:
+ except getopt.GetoptError,msg:
sys.stderr.write("which: error: %s. Your invocation was: %s\n"\
% (msg, argv))
sys.stderr.write("Try 'which --help'.\n")
return 1
for opt, optarg in optlist:
if opt in ('-h', '--help'):
print _cmdlnUsage
return 0