diff --git a/build-support/known_py3_failures.txt b/build-support/known_py3_failures.txt index 3ec141c56ebd..f3e9ce912b16 100644 --- a/build-support/known_py3_failures.txt +++ b/build-support/known_py3_failures.txt @@ -1,55 +1,9 @@ -tests/python/pants_test/backend/codegen/antlr/java:java -tests/python/pants_test/backend/codegen/antlr/python:python -tests/python/pants_test/backend/codegen/jaxb:jaxb tests/python/pants_test/backend/codegen/thrift/java:java tests/python/pants_test/backend/codegen/thrift/python:python -tests/python/pants_test/backend/docgen/targets:wiki_page -tests/python/pants_test/backend/graph_info/tasks:cloc -tests/python/pants_test/backend/graph_info/tasks:dependees -tests/python/pants_test/backend/graph_info/tasks:filemap -tests/python/pants_test/backend/graph_info/tasks:filter -tests/python/pants_test/backend/graph_info/tasks:listtargets -tests/python/pants_test/backend/graph_info/tasks:minimal_cover -tests/python/pants_test/backend/graph_info/tasks:paths -tests/python/pants_test/backend/graph_info/tasks:sorttargets -tests/python/pants_test/backend/jvm/subsystems:custom_scala -tests/python/pants_test/backend/jvm/targets:jvm_app -tests/python/pants_test/backend/jvm/targets:jvm_binary -tests/python/pants_test/backend/jvm/tasks/reports:reports -tests/python/pants_test/backend/jvm/tasks:benchmark_run -tests/python/pants_test/backend/jvm/tasks:binary_create -tests/python/pants_test/backend/jvm/tasks:bootstrap_jvm_tools -tests/python/pants_test/backend/jvm/tasks:bundle_create -tests/python/pants_test/backend/jvm/tasks:check_published_deps -tests/python/pants_test/backend/jvm/tasks:checkstyle -tests/python/pants_test/backend/jvm/tasks:classmap -tests/python/pants_test/backend/jvm/tasks:consolidate_classpath tests/python/pants_test/backend/jvm/tasks:coursier_resolve -tests/python/pants_test/backend/jvm/tasks:detect_duplicates -tests/python/pants_test/backend/jvm/tasks:ivy_imports -tests/python/pants_test/backend/jvm/tasks:ivy_resolve -tests/python/pants_test/backend/jvm/tasks:ivy_utils -tests/python/pants_test/backend/jvm/tasks:jar_create -tests/python/pants_test/backend/jvm/tasks:jar_publish -tests/python/pants_test/backend/jvm/tasks:jar_task tests/python/pants_test/backend/jvm/tasks:junit_run -tests/python/pants_test/backend/jvm/tasks:jvm_platform_analysis -tests/python/pants_test/backend/jvm/tasks:jvm_run -tests/python/pants_test/backend/jvm/tasks:jvm_task -tests/python/pants_test/backend/jvm/tasks:jvmdoc_gen tests/python/pants_test/backend/jvm/tasks:resources_task -tests/python/pants_test/backend/jvm/tasks:scalafmt -tests/python/pants_test/backend/jvm/tasks:scalastyle -tests/python/pants_test/backend/jvm/tasks:unpack_jars -tests/python/pants_test/backend/native/subsystems:subsystems -tests/python/pants_test/backend/native/tasks:tasks -tests/python/pants_test/backend/project_info/tasks:dependencies -tests/python/pants_test/backend/project_info/tasks:depmap -tests/python/pants_test/backend/project_info/tasks:export -tests/python/pants_test/backend/project_info/tasks:filedeps -tests/python/pants_test/backend/python/tasks:isort_run tests/python/pants_test/backend/python/tasks:tasks -tests/python/pants_test/backend/python:interpreter_cache tests/python/pants_test/binaries:binaries tests/python/pants_test/build_graph:build_file_parser tests/python/pants_test/build_graph:build_graph diff --git a/src/python/pants/backend/graph_info/tasks/cloc.py b/src/python/pants/backend/graph_info/tasks/cloc.py index 36b2411a26e0..63d92da4c9a0 100644 --- a/src/python/pants/backend/graph_info/tasks/cloc.py +++ b/src/python/pants/backend/graph_info/tasks/cloc.py @@ -87,7 +87,7 @@ def console_output(self, targets): [exec_result.output_directory_digest] )[0].dependencies - files_content = {fc.path: fc.content for fc in files_content_tuple} + files_content = {fc.path: fc.content.decode('utf-8') for fc in files_content_tuple} for line in files_content['report'].split('\n'): yield line diff --git a/src/python/pants/backend/jvm/argfile.py b/src/python/pants/backend/jvm/argfile.py index 6d809d43034b..f8f0073389a0 100644 --- a/src/python/pants/backend/jvm/argfile.py +++ b/src/python/pants/backend/jvm/argfile.py @@ -53,7 +53,7 @@ def create_argfile(f): if delete and os.path.exists(argfile): os.unlink(argfile) else: - with temporary_file(cleanup=delete) as fp: + with temporary_file(cleanup=delete, binary_mode=False) as fp: yield create_argfile(fp) else: yield args diff --git a/src/python/pants/backend/jvm/ivy_utils.py b/src/python/pants/backend/jvm/ivy_utils.py index 854997c421ea..04c58640a4ae 100644 --- a/src/python/pants/backend/jvm/ivy_utils.py +++ b/src/python/pants/backend/jvm/ivy_utils.py @@ -539,8 +539,8 @@ def __eq__(self, other): # TODO(python3port): Return NotImplemented if other does not have attributes def __lt__(self, other): # We can't just re-use __repr__ or __str_ because we want to order rev last - return ((self.org, self.name, self.classifier, self.ext, self.rev) < - (other.org, other.name, other.classifier, other.ext, other.rev)) + return ((self.org, self.name, self.classifier or '', self.ext, self.rev) < + (other.org, other.name, other.classifier or '', other.ext, other.rev)) def __hash__(self): return hash(self._id) diff --git a/src/python/pants/backend/jvm/targets/jvm_binary.py b/src/python/pants/backend/jvm/targets/jvm_binary.py index 89b6a6e8dbe2..d8b09c7d8ec9 100644 --- a/src/python/pants/backend/jvm/targets/jvm_binary.py +++ b/src/python/pants/backend/jvm/targets/jvm_binary.py @@ -238,9 +238,9 @@ def rules(self): def fingerprint(self): hasher = sha1() - hasher.update(self.payload.fingerprint()) + hasher.update(self.payload.fingerprint().encode('utf-8')) for rule in self.rules: - hasher.update(rule.fingerprint()) + hasher.update(rule.fingerprint().encode('utf-8')) return hasher.hexdigest() if PY3 else hasher.hexdigest().decode('utf-8') @property diff --git a/src/python/pants/backend/jvm/tasks/bootstrap_jvm_tools.py b/src/python/pants/backend/jvm/tasks/bootstrap_jvm_tools.py index e438f89d1974..77009a4acb9b 100644 --- a/src/python/pants/backend/jvm/tasks/bootstrap_jvm_tools.py +++ b/src/python/pants/backend/jvm/tasks/bootstrap_jvm_tools.py @@ -46,15 +46,15 @@ def compute_fingerprint(self, target): if base_fingerprint is None: return None - hasher.update('version=2') + hasher.update(b'version=2') hasher.update(base_fingerprint.encode('utf-8')) # NB: this series of updates must always cover the same fields that populate `_tuple`'s slots # to ensure proper invalidation. - hasher.update(self._main) + hasher.update(self._main.encode('utf-8')) if self._custom_rules: for rule in self._custom_rules: - hasher.update(rule.render()) + hasher.update(rule.render().encode('utf-8')) return hasher.hexdigest() if PY3 else hasher.hexdigest().decode('utf-8') diff --git a/src/python/pants/backend/jvm/tasks/coursier_resolve.py b/src/python/pants/backend/jvm/tasks/coursier_resolve.py index a8f1f4cd3c94..d5a30cb47fe6 100644 --- a/src/python/pants/backend/jvm/tasks/coursier_resolve.py +++ b/src/python/pants/backend/jvm/tasks/coursier_resolve.py @@ -723,7 +723,7 @@ def compute_fingerprint(self, target): hasher.update(target.payload.fingerprint().encode('utf-8')) for conf in self._confs: - hasher.update(conf) + hasher.update(conf.encode('utf-8')) for element in hash_elements_for_target: hasher.update(element.encode('utf-8')) diff --git a/src/python/pants/backend/jvm/tasks/coverage/cobertura.py b/src/python/pants/backend/jvm/tasks/coverage/cobertura.py index b7c93aa8d46a..55f976478696 100644 --- a/src/python/pants/backend/jvm/tasks/coverage/cobertura.py +++ b/src/python/pants/backend/jvm/tasks/coverage/cobertura.py @@ -219,7 +219,7 @@ def instrument(self, output_dir): for pattern in self._exclude_classes: args += ["--excludeClasses", pattern] - with temporary_file() as tmp_file: + with temporary_file(binary_mode=False) as tmp_file: tmp_file.write("\n".join(unique_files)) tmp_file.flush() diff --git a/src/python/pants/backend/jvm/tasks/jar_publish.py b/src/python/pants/backend/jvm/tasks/jar_publish.py index ef1da2641d1e..9540647e460c 100644 --- a/src/python/pants/backend/jvm/tasks/jar_publish.py +++ b/src/python/pants/backend/jvm/tasks/jar_publish.py @@ -876,7 +876,7 @@ def exportable(tgt): def entry_fingerprint(self, target, fingerprint_internal): sha = hashlib.sha1() - sha.update(target.invalidation_hash()) + sha.update(target.invalidation_hash().encode('utf-8')) # TODO(Tejal Desai): pantsbuild/pants/65: Remove java_sources attribute for ScalaLibrary if isinstance(target, ScalaLibrary): @@ -892,7 +892,7 @@ def entry_fingerprint(self, target, fingerprint_internal): internal_dependencies = sorted(target_internal_dependencies(target), key=lambda t: t.id) for internal_target in internal_dependencies: fingerprint = fingerprint_internal(internal_target) - sha.update(fingerprint) + sha.update(fingerprint.encode('utf-8')) return sha.hexdigest() if PY3 else sha.hexdigest().decode('utf-8') diff --git a/src/python/pants/backend/jvm/tasks/jvm_platform_analysis.py b/src/python/pants/backend/jvm/tasks/jvm_platform_analysis.py index 0dafb853d1bb..25d297bdf2ef 100644 --- a/src/python/pants/backend/jvm/tasks/jvm_platform_analysis.py +++ b/src/python/pants/backend/jvm/tasks/jvm_platform_analysis.py @@ -138,7 +138,7 @@ class PlatformFingerprintStrategy(FingerprintStrategy): def compute_fingerprint(self, target): hasher = sha1() if hasattr(target, 'platform'): - hasher.update(str(tuple(target.platform))) + hasher.update(str(tuple(target.platform)).encode('utf-8')) return hasher.hexdigest() if PY3 else hasher.hexdigest().decode('utf-8') def __eq__(self, other): diff --git a/src/python/pants/backend/native/targets/native_artifact.py b/src/python/pants/backend/native/targets/native_artifact.py index f2024d7f5c8c..54f10a8028c4 100644 --- a/src/python/pants/backend/native/targets/native_artifact.py +++ b/src/python/pants/backend/native/targets/native_artifact.py @@ -29,4 +29,5 @@ def as_shared_lib(self, platform): def _compute_fingerprint(self): # FIXME: can we just use the __hash__ method here somehow? - return sha1(self.lib_name).hexdigest() if PY3 else sha1(self.lib_name).hexdigest().decode('utf-8') + hasher = sha1(self.lib_name.encode('utf-8')) + return hasher.hexdigest() if PY3 else hasher.hexdigest().decode('utf-8') diff --git a/src/python/pants/backend/python/tasks/pytest_run.py b/src/python/pants/backend/python/tasks/pytest_run.py index 64a522e5b3c5..9d6a47723a40 100644 --- a/src/python/pants/backend/python/tasks/pytest_run.py +++ b/src/python/pants/backend/python/tasks/pytest_run.py @@ -240,7 +240,7 @@ def _cov_setup(self, workdirs, coverage_morfs, src_to_target_base): # Note that it's important to put the tmpfile under the workdir, because pytest # uses all arguments that look like paths to compute its rootdir, and we want # it to pick the buildroot. - with temporary_file(root_dir=workdirs.root_dir) as fp: + with temporary_file(root_dir=workdirs.root_dir, binary_mode=False) as fp: cp.write(fp) fp.close() coverage_rc = fp.name diff --git a/src/python/pants/backend/python/tasks/python_execution_task_base.py b/src/python/pants/backend/python/tasks/python_execution_task_base.py index 6cae9ab52ae9..9035f758dbdb 100644 --- a/src/python/pants/backend/python/tasks/python_execution_task_base.py +++ b/src/python/pants/backend/python/tasks/python_execution_task_base.py @@ -7,6 +7,7 @@ import os from builtins import str +from future.utils import binary_type, text_type from pex.interpreter import PythonInterpreter from pex.pex import PEX @@ -46,7 +47,7 @@ def extra_requirements(self): """ return () - class ExtraFile(datatype(['path', 'content'])): + class ExtraFile(datatype([('path', text_type), ('content', binary_type)])): """Models an extra file to place in a PEX.""" @classmethod @@ -56,7 +57,7 @@ def empty(cls, path): :param str path: The path this extra file should have when added to a PEX. :rtype: :class:`ExtraFile` """ - return cls(path=path, content='') + return cls(path=path, content=b'') def add_to(self, builder): """Adds this extra file to a PEX builder. diff --git a/src/python/pants/backend/python/tasks/select_interpreter.py b/src/python/pants/backend/python/tasks/select_interpreter.py index 94cc6643a2e5..ac9ef8a3601c 100644 --- a/src/python/pants/backend/python/tasks/select_interpreter.py +++ b/src/python/pants/backend/python/tasks/select_interpreter.py @@ -34,7 +34,7 @@ def compute_fingerprint(self, python_target): return None hasher = hashlib.sha1() for element in hash_elements_for_target: - hasher.update(element) + hasher.update(element.encode('utf-8')) return hasher.hexdigest() if PY3 else hasher.hexdigest().decode('utf-8') diff --git a/src/python/pants/backend/python/tasks/setup_py.py b/src/python/pants/backend/python/tasks/setup_py.py index 8c76453a2538..098e9c89e09c 100644 --- a/src/python/pants/backend/python/tasks/setup_py.py +++ b/src/python/pants/backend/python/tasks/setup_py.py @@ -13,7 +13,7 @@ from builtins import map, object, str, zip from collections import OrderedDict, defaultdict -from pex.compatibility import string, to_bytes +from future.utils import PY2, PY3 from pex.installer import InstallerBase, Packager from pex.interpreter import PythonInterpreter from twitter.common.collections import OrderedSet @@ -300,7 +300,7 @@ def collect_reduced_dependencies(current): class SetupPy(Task): """Generate setup.py-based Python projects.""" - SOURCE_ROOT = b'src' + SOURCE_ROOT = 'src' if PY3 else b'src' PYTHON_DISTS_PRODUCT = 'python_dists' @@ -514,18 +514,23 @@ def write_setup(self, root_target, reduced_dependencies, chroot): setup_keywords = root_target.provides.setup_py_keywords.copy() - package_dir = {b'': self.SOURCE_ROOT} + package_dir = {'' if PY3 else b'': self.SOURCE_ROOT} packages, namespace_packages, resources = self.find_packages(chroot, self.context.log) if namespace_packages: setup_keywords['namespace_packages'] = list(sorted(namespace_packages)) if packages: + normalized_package_data = ( + resources.items() + if PY3 else + ((package.encode('utf-8'), [v.encode('utf-8') for v in rs]) + for (package, rs) in resources.items()) + ) setup_keywords.update( package_dir=package_dir, packages=list(sorted(packages)), - package_data=dict((str(package), list(map(str, rs))) - for (package, rs) in resources.items())) + package_data=dict(normalized_package_data)) setup_keywords['install_requires'] = list(self.install_requires(reduced_dependencies)) @@ -546,8 +551,8 @@ def convert(input): return out elif isinstance(input, list): return [convert(element) for element in input] - elif isinstance(input, string): - return to_bytes(input) + elif PY2 and isinstance(input, str): + return input.encode('utf-8') else: return input @@ -571,7 +576,7 @@ def convert(input): chroot.write(self._setup_boilerplate().format( setup_dict=pprint.pformat(convert(setup_keywords), indent=4), setup_target=repr(root_target) - ), 'setup.py') + ).encode('utf-8'), 'setup.py') # make sure that setup.py is included chroot.write('include *.py'.encode('utf8'), 'MANIFEST.in') diff --git a/src/python/pants/build_graph/app_base.py b/src/python/pants/build_graph/app_base.py index 85841603ab93..c41b2915121b 100644 --- a/src/python/pants/build_graph/app_base.py +++ b/src/python/pants/build_graph/app_base.py @@ -174,7 +174,7 @@ class BundleField(tuple, PayloadField): @staticmethod def _hash_bundle(bundle): hasher = sha1() - hasher.update(bundle.rel_path) + hasher.update(bundle.rel_path.encode('utf-8')) for abs_path in sorted(bundle.filemap.keys()): buildroot_relative_path = os.path.relpath(abs_path, get_buildroot()).encode('utf-8') hasher.update(buildroot_relative_path) diff --git a/src/python/pants/build_graph/intermediate_target_factory.py b/src/python/pants/build_graph/intermediate_target_factory.py index ae276429b89b..2ae267c0dcd2 100644 --- a/src/python/pants/build_graph/intermediate_target_factory.py +++ b/src/python/pants/build_graph/intermediate_target_factory.py @@ -7,7 +7,7 @@ from builtins import str from hashlib import sha1 -from future.utils import string_types +from future.utils import PY3, string_types from pants.base.exceptions import TargetDefinitionException from pants.build_graph.address import Address @@ -16,9 +16,9 @@ def hash_target(address, suffix): hasher = sha1() - hasher.update(address) - hasher.update(suffix) - return hasher.hexdigest() + hasher.update(address.encode('utf-8')) + hasher.update(suffix.encode('utf-8')) + return hasher.hexdigest() if PY3 else hasher.hexdigest().decode('utf-8') class IntermediateTargetFactoryBase(AbstractClass): diff --git a/src/python/pants/java/jar/manifest.py b/src/python/pants/java/jar/manifest.py index 8d65fc74b7f5..3f429cdc766d 100644 --- a/src/python/pants/java/jar/manifest.py +++ b/src/python/pants/java/jar/manifest.py @@ -25,7 +25,7 @@ def _wrap(text): chunk = fp.read(69) if not chunk: return - yield ' {}'.format(chunk) + yield b' ' + chunk PATH = 'META-INF/MANIFEST.MF' diff --git a/src/python/pants/task/console_task.py b/src/python/pants/task/console_task.py index c3adee81d8f1..0ceb319b2c34 100644 --- a/src/python/pants/task/console_task.py +++ b/src/python/pants/task/console_task.py @@ -29,7 +29,7 @@ def register_options(cls, register): def __init__(self, *args, **kwargs): super(ConsoleTask, self).__init__(*args, **kwargs) - self._console_separator = self.get_options().sep.decode('unicode_escape') + self._console_separator = self.get_options().sep.encode('ascii').decode('unicode_escape') if self.get_options().output_file: try: self._outstream = safe_open(os.path.abspath(self.get_options().output_file), 'wb') @@ -55,7 +55,7 @@ def execute(self): targets = self.context.targets() for value in self.console_output(targets) or tuple(): self._outstream.write(value.encode('utf-8')) - self._outstream.write(self._console_separator.encode('utf-8')) + self._outstream.write(self._console_separator.encode('ascii')) finally: self._outstream.flush() if self.get_options().output_file: diff --git a/src/python/pants/task/scm_publish_mixin.py b/src/python/pants/task/scm_publish_mixin.py index 074ae3e64998..d59674203430 100644 --- a/src/python/pants/task/scm_publish_mixin.py +++ b/src/python/pants/task/scm_publish_mixin.py @@ -8,6 +8,7 @@ import traceback from abc import abstractmethod from builtins import object, range +from functools import total_ordering from pants.base.exceptions import TaskError from pants.scm.scm import Scm @@ -28,6 +29,7 @@ def version(self): """Returns the string representation of this Version.""" +@total_ordering class Namedver(Version): """A less restrictive versioning scheme that does not conflict with Semver @@ -65,13 +67,14 @@ def version(self): def __eq__(self, other): return self._version == other._version - def __cmp__(self, other): + def __lt__(self, other): raise ValueError("{0} is not comparable to {1}".format(self, other)) def __repr__(self): return 'Namedver({0})'.format(self.version()) +@total_ordering class Semver(Version): """Semantic versioning. See http://semver.org""" @@ -109,22 +112,17 @@ def version(self): ('{}-SNAPSHOT'.format(self.patch)) if self.snapshot else self.patch) def __eq__(self, other): - return self.__cmp__(other) == 0 + return (self.major, self.minor, self.patch, self.snapshot) == \ + (other.major, other.minor, other.patch, other.snapshot) - def __cmp__(self, other): + def __lt__(self, other): diff = self.major - other.major - if not diff: - diff = self.minor - other.minor - if not diff: - diff = self.patch - other.patch - if not diff: - if self.snapshot and not other.snapshot: - diff = 1 - elif not self.snapshot and other.snapshot: - diff = -1 - else: - diff = 0 - return diff + if diff: + return self.major < other.major + diff = self.minor - other.minor + if diff: + return self.patch < other.patch + return self.snapshot < other.snapshot def __repr__(self): return 'Semver({})'.format(self.version()) @@ -231,13 +229,14 @@ def _push_and_tag_changes(self, tag_name, tag_message): @staticmethod def _push_with_retry(scm, log, attempts): - scm_exception = None + global_scm_exception = None for attempt in range(attempts): try: log.debug("Trying scm push") scm.push() break # success except Scm.RemoteException as scm_exception: + global_scm_exception = scm_exception log.debug("Scm push failed, trying to refresh.") # This might fail in the event that there is a real conflict, throwing # a Scm.LocalException (in case of a rebase failure) or a Scm.RemoteException @@ -249,9 +248,9 @@ def _push_with_retry(scm, log, attempts): try: scm.refresh(leave_clean=True) except Scm.LocalException as local_exception: - exc = traceback.format_exc(scm_exception) + exc = traceback.format_exc() log.debug("SCM exception while pushing: {}".format(exc)) raise local_exception - else: - raise scm_exception + else: # no more retries + raise global_scm_exception diff --git a/src/python/pants/task/testrunner_task_mixin.py b/src/python/pants/task/testrunner_task_mixin.py index 77c596400aaf..326c7cfe0155 100644 --- a/src/python/pants/task/testrunner_task_mixin.py +++ b/src/python/pants/task/testrunner_task_mixin.py @@ -472,7 +472,7 @@ def _execute(self, all_targets): else: log = self.context.log.info result = self.result_class.successful() - log('{0:80}.....{1:>10}'.format(target.address.reference(), result)) + log('{0:80}.....{1:>10}'.format(target.address.reference(), str(result))) msgs = [str(_rv) for _rv in results.values() if not _rv.success] failed_targets = [target diff --git a/tests/python/pants_test/backend/codegen/protobuf/java/test_protobuf_integration.py b/tests/python/pants_test/backend/codegen/protobuf/java/test_protobuf_integration.py index 8d2041fd133f..4c1c944cfa78 100644 --- a/tests/python/pants_test/backend/codegen/protobuf/java/test_protobuf_integration.py +++ b/tests/python/pants_test/backend/codegen/protobuf/java/test_protobuf_integration.py @@ -35,7 +35,7 @@ def test_bundle_protobuf_normal(self): stdout=subprocess.PIPE, cwd=out_path) java_retcode = java_run.wait() - java_out = java_run.stdout.read() + java_out = java_run.stdout.read().decode('utf-8') self.assertEqual(java_retcode, 0) self.assertIn("parsec", java_out) @@ -54,7 +54,7 @@ def test_bundle_protobuf_imports(self): stdout=subprocess.PIPE, cwd=out_path) java_retcode = java_run.wait() - java_out = java_run.stdout.read() + java_out = java_run.stdout.read().decode('utf-8') self.assertEqual(java_retcode, 0) self.assertIn("very test", java_out) @@ -76,7 +76,7 @@ def test_bundle_protobuf_unpacked_jars(self): 'org.pantsbuild.example.protobuf.unpacked_jars.ExampleProtobufExternalArchive'] java_run = subprocess.Popen(args, stdout=subprocess.PIPE, cwd=out_path) java_retcode = java_run.wait() - java_out = java_run.stdout.read() + java_out = java_run.stdout.read().decode('utf-8') self.assertEqual(java_retcode, 0) self.assertIn("Message is: Hello World!", java_out) diff --git a/tests/python/pants_test/backend/codegen/thrift/python/test_apache_thrift_py_gen.py b/tests/python/pants_test/backend/codegen/thrift/python/test_apache_thrift_py_gen.py index 9bd2fbc151cd..789db883445a 100644 --- a/tests/python/pants_test/backend/codegen/thrift/python/test_apache_thrift_py_gen.py +++ b/tests/python/pants_test/backend/codegen/thrift/python/test_apache_thrift_py_gen.py @@ -154,7 +154,7 @@ def test_namespace_effective(self): # TODO(John Sirois): We really should be emitting setuptools in a # `synthetic_target_extra_dependencies` override in `ApacheThriftPyGen`: # https://github.com/pantsbuild/pants/issues/5975 - pythonpath = interpreter.extras.values() + pythonpath = list(interpreter.extras.values()) pythonpath.extend(os.path.join(get_buildroot(), t.target_base) for t in targets) for dist in resolve(['thrift=={}'.format(self.get_thrift_version(apache_thrift_gen))], interpreter=interpreter, diff --git a/tests/python/pants_test/backend/codegen/wire/java/test_wire_integration.py b/tests/python/pants_test/backend/codegen/wire/java/test_wire_integration.py index 5e3c1dc87869..d22f8bc98a2f 100644 --- a/tests/python/pants_test/backend/codegen/wire/java/test_wire_integration.py +++ b/tests/python/pants_test/backend/codegen/wire/java/test_wire_integration.py @@ -46,7 +46,7 @@ def test_bundle_wire_normal(self): 'org.pantsbuild.example.wire.temperatureservice.WireTemperatureExample'] java_run = subprocess.Popen(args, stdout=subprocess.PIPE, cwd=out_path) java_retcode = java_run.wait() - java_out = java_run.stdout.read() + java_out = java_run.stdout.read().decode('utf-8') self.assertEqual(java_retcode, 0) self.assertIn('19 degrees celsius', java_out) @@ -63,7 +63,7 @@ def test_bundle_wire_dependent_targets(self): stdout=subprocess.PIPE, cwd=out_path) java_retcode = java_run.wait() - java_out = java_run.stdout.read() + java_out = java_run.stdout.read().decode('utf-8') self.assertEqual(java_retcode, 0) self.assertIn('Element{symbol=Hg, name=Mercury, atomic_number=80, ' 'melting_point=Temperature{unit=celsius, number=-39}, ' diff --git a/tests/python/pants_test/backend/graph_info/tasks/BUILD b/tests/python/pants_test/backend/graph_info/tasks/BUILD index 8b3092a37e1e..e12cf813975b 100644 --- a/tests/python/pants_test/backend/graph_info/tasks/BUILD +++ b/tests/python/pants_test/backend/graph_info/tasks/BUILD @@ -20,7 +20,6 @@ python_tests( name='cloc_integration', sources=['test_cloc_integration.py'], dependencies=[ - '3rdparty/python:future', 'tests/python/pants_test:int-test', ], tags = {'integration'}, diff --git a/tests/python/pants_test/backend/graph_info/tasks/test_cloc_integration.py b/tests/python/pants_test/backend/graph_info/tasks/test_cloc_integration.py index 36d499cfc115..cecb964451e3 100644 --- a/tests/python/pants_test/backend/graph_info/tasks/test_cloc_integration.py +++ b/tests/python/pants_test/backend/graph_info/tasks/test_cloc_integration.py @@ -4,8 +4,6 @@ from __future__ import absolute_import, division, print_function, unicode_literals -from builtins import str - from pants_test.pants_run_integration_test import PantsRunIntegrationTest @@ -17,11 +15,11 @@ def test_cloc(self): ]) self.assert_success(pants_run) # Strip out the header which is non-deterministic because it has speed information in it. - stdout = str('\n'.join(pants_run.stdout_data.split('\n')[1:])) - self.assertEqual(stdout, str("""------------------------------------------------------------------------------- + stdout = '\n'.join(pants_run.stdout_data.split('\n')[1:]) + self.assertEqual(stdout, """------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- Python 1 3 3 4 ------------------------------------------------------------------------------- -""")) +""") diff --git a/tests/python/pants_test/backend/jvm/tasks/BUILD b/tests/python/pants_test/backend/jvm/tasks/BUILD index 92321e8cffbd..6cd6c73ab0ef 100644 --- a/tests/python/pants_test/backend/jvm/tasks/BUILD +++ b/tests/python/pants_test/backend/jvm/tasks/BUILD @@ -406,6 +406,7 @@ python_tests( 'src/python/pants/build_graph', 'src/python/pants/util:contextutil', 'src/python/pants/util:dirutil', + 'tests/python/pants_test/jvm:jar_task_test_base', 'tests/python/pants_test/jvm:jvm_tool_task_test_base', ] ) diff --git a/tests/python/pants_test/backend/jvm/tasks/jvm_compile/java/jvm_platform_integration_mixin.py b/tests/python/pants_test/backend/jvm/tasks/jvm_compile/java/jvm_platform_integration_mixin.py index 34b21d204ade..c0cb1c37be24 100644 --- a/tests/python/pants_test/backend/jvm/tasks/jvm_compile/java/jvm_platform_integration_mixin.py +++ b/tests/python/pants_test/backend/jvm/tasks/jvm_compile/java/jvm_platform_integration_mixin.py @@ -39,7 +39,7 @@ def determine_version(self, path): p = Popen(['file', path], stdout=PIPE, stderr=PIPE) out, err = p.communicate() self.assertEqual(0, p.returncode, 'Failed to run file on {}.'.format(path)) - match = re.search(r'version (\d+[.]\d+)', out) + match = re.search(r'version (\d+[.]\d+)', out.decode('utf-8')) self.assertTrue(match is not None, 'Could not determine version for {}'.format(path)) return version_map[match.group(1)] diff --git a/tests/python/pants_test/backend/jvm/tasks/test_binary_create_integration.py b/tests/python/pants_test/backend/jvm/tasks/test_binary_create_integration.py index ad035aa6af16..d65a28387ba2 100644 --- a/tests/python/pants_test/backend/jvm/tasks/test_binary_create_integration.py +++ b/tests/python/pants_test/backend/jvm/tasks/test_binary_create_integration.py @@ -76,7 +76,8 @@ def test_agent_dependency(self): jar = "dist/manifest-with-agent.jar" with open_zip(jar, mode='r') as j: with j.open("META-INF/MANIFEST.MF") as jar_entry: - entries = {tuple(line.strip().split(": ", 2)) for line in jar_entry.readlines() if line.strip()} + normalized_lines = (line.strip().decode('utf-8') for line in jar_entry.readlines() if line.strip()) + entries = {tuple(line.split(": ", 2)) for line in normalized_lines} self.assertIn(('Agent-Class', 'org.pantsbuild.testproject.manifest.Agent'), entries) def test_deploy_excludes(self): @@ -130,6 +131,8 @@ def run_java(self, java_args, expected_returncode=0, expected_output=None, cwd=N stderr=subprocess.PIPE, cwd=cwd) stdout, stderr = process.communicate() + stdout = stdout.decode('utf-8') + stderr = stderr.decode('utf-8') self.assertEqual(expected_returncode, process.returncode, ('Expected exit code {} from command `{}` but got {}:\n' diff --git a/tests/python/pants_test/backend/jvm/tasks/test_bootstrap_jvm_tools.py b/tests/python/pants_test/backend/jvm/tasks/test_bootstrap_jvm_tools.py index dbcc64c04f2d..ab7a3c7e64bb 100644 --- a/tests/python/pants_test/backend/jvm/tasks/test_bootstrap_jvm_tools.py +++ b/tests/python/pants_test/backend/jvm/tasks/test_bootstrap_jvm_tools.py @@ -30,8 +30,8 @@ def execute_tool(self, classpath, main, args=None): stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = process.communicate() self.assertEqual(0, process.returncode) - self.assertEqual('', err.strip()) - yield out + self.assertEqual('', err.strip().decode('utf-8')) + yield out.decode('utf-8') class BootstrapJvmToolsShadingTest(BootstrapJvmToolsTestBase): diff --git a/tests/python/pants_test/backend/jvm/tasks/test_bundle_create.py b/tests/python/pants_test/backend/jvm/tasks/test_bundle_create.py index c6800680bdde..94085f0077e3 100644 --- a/tests/python/pants_test/backend/jvm/tasks/test_bundle_create.py +++ b/tests/python/pants_test/backend/jvm/tasks/test_bundle_create.py @@ -38,7 +38,7 @@ def add_consolidated_bundle(self, context, tgt, files_dict): entry_path = safe_mkdtemp(dir=target_dir) classpath_dir = safe_mkdtemp(dir=target_dir) for rel_path, content in files_dict.items(): - safe_file_dump(os.path.join(entry_path, rel_path), content) + safe_file_dump(os.path.join(entry_path, rel_path), content, binary_mode=False) # Create Jar to mimic consolidate classpath behavior. jarpath = os.path.join(classpath_dir, 'output-0.jar') @@ -71,12 +71,12 @@ def setUp(self): JarDependency(org='org.gnu', name='gary', rev='4.0.0', ext='tar.gz')]) - safe_file_dump(os.path.join(self.build_root, 'resources/foo/file'), '// dummy content') + safe_file_dump(os.path.join(self.build_root, 'resources/foo/file'), '// dummy content', binary_mode=False) self.resources_target = self.make_target('//resources:foo-resources', Resources, sources=['foo/file']) # This is so that payload fingerprint can be computed. - safe_file_dump(os.path.join(self.build_root, 'foo/Foo.java'), '// dummy content') + safe_file_dump(os.path.join(self.build_root, 'foo/Foo.java'), '// dummy content', binary_mode=False) self.java_lib_target = self.make_target('//foo:foo-library', JavaLibrary, sources=['Foo.java']) self.binary_target = self.make_target(spec='//foo:foo-binary', diff --git a/tests/python/pants_test/backend/jvm/tasks/test_consolidate_classpath.py b/tests/python/pants_test/backend/jvm/tasks/test_consolidate_classpath.py index c05d58698153..b30dbf7a17c8 100644 --- a/tests/python/pants_test/backend/jvm/tasks/test_consolidate_classpath.py +++ b/tests/python/pants_test/backend/jvm/tasks/test_consolidate_classpath.py @@ -48,12 +48,12 @@ def setUp(self): JarDependency(org='org.gnu', name='gary', rev='4.0.0', ext='tar.gz')]) - safe_file_dump(os.path.join(self.build_root, 'resources/foo/file'), '// dummy content') + safe_file_dump(os.path.join(self.build_root, 'resources/foo/file'), '// dummy content', binary_mode=False) self.resources_target = self.make_target('//resources:foo-resources', Resources, sources=['foo/file']) # This is so that payload fingerprint can be computed. - safe_file_dump(os.path.join(self.build_root, 'foo/Foo.java'), '// dummy content') + safe_file_dump(os.path.join(self.build_root, 'foo/Foo.java'), '// dummy content', binary_mode=False) self.java_lib_target = self.make_target('//foo:foo-library', JavaLibrary, sources=['Foo.java']) self.binary_target = self.make_target(spec='//foo:foo-binary', @@ -94,7 +94,7 @@ def test_remove_raw_deps(self): ) # Confirm that we haven't destroyed deps. - expected_non_deps = set(['output-0.jar', 'Foo.class', 'foo.txt', 'file']) + expected_non_deps = {'output-0.jar', 'Foo.class', 'foo.txt', 'file'} found = set(os.listdir(self.pants_workdir)) print(expected_non_deps - found) self.assertTrue(expected_non_deps - found == expected_non_deps) @@ -119,9 +119,9 @@ def test_consolidate_classpath(self): ) # Confirm that we haven't destroyed deps. - expected_deps = set(['org.apache-baz-3.0.0-tests.jar', - 'org.example-foo-1.0.0.jar', - 'org.gnu-gary-4.0.0.tar.gz', - 'org.pantsbuild-bar-2.0.0.zip']) + expected_deps = {'org.apache-baz-3.0.0-tests.jar', + 'org.example-foo-1.0.0.jar', + 'org.gnu-gary-4.0.0.tar.gz', + 'org.pantsbuild-bar-2.0.0.zip'} found = set(os.listdir(self.pants_workdir)) self.assertTrue(expected_deps - found == set()) diff --git a/tests/python/pants_test/backend/jvm/tasks/test_coursier_resolve.py b/tests/python/pants_test/backend/jvm/tasks/test_coursier_resolve.py index 5cadecc9dbde..6ffb065d686e 100644 --- a/tests/python/pants_test/backend/jvm/tasks/test_coursier_resolve.py +++ b/tests/python/pants_test/backend/jvm/tasks/test_coursier_resolve.py @@ -8,6 +8,7 @@ from builtins import str from contextlib import contextmanager +from future.utils import PY3 from mock import MagicMock from psutil.tests import safe_remove @@ -130,7 +131,9 @@ def test_resolve_ignores_jars_with_rev_left_off(self): self.resolve([lib]) self.assertEqual( - 'Undefined revs for jars unsupported by Coursier. "jar(org=u\'com.google.guava\', name=u\'guava\', rev=None, classifier=None, ext=u\'jar\')"', + "Undefined revs for jars unsupported by Coursier. " + "\"jar(org={unicode_literal}'com.google.guava', name={unicode_literal}'guava', " + "rev=None, classifier=None, ext={unicode_literal}'jar')\"".format(unicode_literal='' if PY3 else 'u'), str(cm.exception)) def test_resolve_multiple_artifacts(self): diff --git a/tests/python/pants_test/backend/jvm/tasks/test_export_classpath_integration.py b/tests/python/pants_test/backend/jvm/tasks/test_export_classpath_integration.py index d6a822b202de..c98f76882fb3 100644 --- a/tests/python/pants_test/backend/jvm/tasks/test_export_classpath_integration.py +++ b/tests/python/pants_test/backend/jvm/tasks/test_export_classpath_integration.py @@ -40,7 +40,7 @@ def test_export_classpath_file_with_excludes(self): with open_zip(manifest_jar_path) as synthetic_jar: self.assertListEqual([Manifest.PATH], synthetic_jar.namelist()) - oneline_classpath = synthetic_jar.read(Manifest.PATH).replace('\n', '').replace(' ', '') + oneline_classpath = synthetic_jar.read(Manifest.PATH).decode('utf-8').replace('\n', '').replace(' ', '') self.assertNotIn('sbt-interface', oneline_classpath) self.assertIn('foo', oneline_classpath) self.assertIn('baz', oneline_classpath) diff --git a/tests/python/pants_test/backend/jvm/tasks/test_jar_create.py b/tests/python/pants_test/backend/jvm/tasks/test_jar_create.py index 07730ac58206..66f592050752 100644 --- a/tests/python/pants_test/backend/jvm/tasks/test_jar_create.py +++ b/tests/python/pants_test/backend/jvm/tasks/test_jar_create.py @@ -133,7 +133,7 @@ def assert_jar_contents(self, context, product_type, target, *contents): for content in content_set: if not content.endswith('/'): with closing(jar.open(content)) as fp: - self.assertEqual(os.path.basename(content), fp.read()) + self.assertEqual(os.path.basename(content), fp.read().decode('utf-8')) @ensure_cached(JarCreate) def test_classfile_jar_contents(self): diff --git a/tests/python/pants_test/backend/jvm/tasks/test_jar_task.py b/tests/python/pants_test/backend/jvm/tasks/test_jar_task.py index a65000f98048..0185a4389508 100644 --- a/tests/python/pants_test/backend/jvm/tasks/test_jar_task.py +++ b/tests/python/pants_test/backend/jvm/tasks/test_jar_task.py @@ -86,7 +86,7 @@ def test_update_write(self): with open_zip(existing_jarfile) as jar: self.assert_listing(jar, 'f/', 'f/g/', 'f/g/h') - self.assertEqual('e', jar.read('f/g/h')) + self.assertEqual(b'e', jar.read('f/g/h')) def test_update_writestr(self): def assert_writestr(path, contents, *entries): @@ -115,7 +115,7 @@ def test_overwrite_write(self): with open_zip(existing_jarfile) as jar: self.assert_listing(jar, 'f/', 'f/g/', 'f/g/h') - self.assertEqual('e', jar.read('f/g/h')) + self.assertEqual(b'e', jar.read('f/g/h')) def test_overwrite_writestr(self): with self.jarfile() as existing_jarfile: @@ -124,7 +124,7 @@ def test_overwrite_writestr(self): with open_zip(existing_jarfile) as jar: self.assert_listing(jar, 'README') - self.assertEqual('42', jar.read('README')) + self.assertEqual(b'42', jar.read('README')) @contextmanager def _test_custom_manifest(self): @@ -136,7 +136,7 @@ def _test_custom_manifest(self): with open_zip(existing_jarfile) as jar: self.assert_listing(jar, 'README') - self.assertEqual('42', jar.read('README')) + self.assertEqual(b'42', jar.read('README')) self.assertNotEqual(manifest_contents, jar.read('META-INF/MANIFEST.MF')) with self.jar_task.open_jar(existing_jarfile, overwrite=False) as jar: @@ -144,7 +144,7 @@ def _test_custom_manifest(self): with open_zip(existing_jarfile) as jar: self.assert_listing(jar, 'README') - self.assertEqual('42', jar.read('README')) + self.assertEqual(b'42', jar.read('README')) self.assertEqual(manifest_contents, jar.read('META-INF/MANIFEST.MF')) def test_custom_manifest_str(self): @@ -173,10 +173,10 @@ def test_custom_manifest_dir_custom_dest(self): def test_classpath(self): def manifest_content(classpath): - return (b'Manifest-Version: 1.0\r\n' + - b'Class-Path: {}\r\n' + - b'Created-By: org.pantsbuild.tools.jar.JarBuilder\r\n\r\n').format( - ' '.join(maybe_list(classpath))) + return ('Manifest-Version: 1.0\r\n' + + 'Class-Path: {}\r\n' + + 'Created-By: org.pantsbuild.tools.jar.JarBuilder\r\n\r\n').format( + ' '.join(maybe_list(classpath))).encode('utf-8') def assert_classpath(classpath): with self.jarfile() as existing_jarfile: @@ -269,9 +269,9 @@ def test_agent_manifest(self): with open_zip(existing_jarfile) as jar: self.assert_listing(jar, 'FakeAgent.class') - self.assertEqual('0xCAFEBABE', jar.read('FakeAgent.class')) + self.assertEqual(b'0xCAFEBABE', jar.read('FakeAgent.class')) - manifest = jar.read('META-INF/MANIFEST.MF').strip() + manifest = jar.read('META-INF/MANIFEST.MF').decode('utf-8').strip() all_entries = dict(tuple(re.split(r'\s*:\s*', line, 1)) for line in manifest.splitlines()) expected_entries = { 'Agent-Class': 'fred', @@ -306,7 +306,7 @@ def test_manifest_items(self): jar_builder.add_target(binary_target) with open_zip(existing_jarfile) as jar: - manifest = jar.read('META-INF/MANIFEST.MF').strip() + manifest = jar.read('META-INF/MANIFEST.MF').decode('utf-8').strip() all_entries = dict(tuple(re.split(r'\s*:\s*', line, 1)) for line in manifest.splitlines()) expected_entries = { 'Foo': 'foo-value', diff --git a/tests/python/pants_test/backend/native/subsystems/test_native_toolchain.py b/tests/python/pants_test/backend/native/subsystems/test_native_toolchain.py index 0c256e1cff25..e7e9fe571c52 100644 --- a/tests/python/pants_test/backend/native/subsystems/test_native_toolchain.py +++ b/tests/python/pants_test/backend/native/subsystems/test_native_toolchain.py @@ -134,7 +134,7 @@ def _invoke_capturing_output(self, cmd, env=None): env = os.environ.copy() try: with environment_as(**env): - return subprocess.check_output(cmd, stderr=subprocess.STDOUT) + return subprocess.check_output(cmd, stderr=subprocess.STDOUT).decode('utf-8') except subprocess.CalledProcessError as e: raise Exception( "Command failed while invoking the native toolchain " diff --git a/tests/python/pants_test/backend/python/tasks/test_pytest_run.py b/tests/python/pants_test/backend/python/tasks/test_pytest_run.py index 6b23c161bc29..8e889e81149c 100644 --- a/tests/python/pants_test/backend/python/tasks/test_pytest_run.py +++ b/tests/python/pants_test/backend/python/tasks/test_pytest_run.py @@ -479,7 +479,7 @@ def load_coverage_data_for(self, context, covered_path, expect_coverage=True): PytestRun._add_plugin_config(cp, src_chroot_path=src_chroot_path, src_to_target_base=src_to_target_base) - with temporary_file() as fp: + with temporary_file(binary_mode=False) as fp: cp.write(fp) fp.close() diff --git a/tests/python/pants_test/backend/python/tasks/test_python_distribution_integration.py b/tests/python/pants_test/backend/python/tasks/test_python_distribution_integration.py index 0311f56bba10..fbc804ffc8d3 100644 --- a/tests/python/pants_test/backend/python/tasks/test_python_distribution_integration.py +++ b/tests/python/pants_test/backend/python/tasks/test_python_distribution_integration.py @@ -41,7 +41,7 @@ def test_pants_binary(self): # Check that the pex was built. self.assertTrue(os.path.isfile(pex)) # Check that the pex runs. - output = subprocess.check_output(pex) + output = subprocess.check_output(pex).decode('utf-8') self._assert_native_greeting(output) # Check that we have exact one wheel output self.assertEqual(len(glob.glob(wheel_glob)), 1) @@ -141,11 +141,11 @@ def test_pants_binary_dep_isolation_with_multiple_targets(self): self.assertTrue(os.path.isfile(pex1)) self.assertTrue(os.path.isfile(pex2)) # Check that the pex 1 runs. - output = subprocess.check_output(pex1) + output = subprocess.check_output(pex1).decode('utf-8') self._assert_native_greeting(output) # Check that the pex 2 fails due to no python_dists leaked into it. try: - output = subprocess.check_output(pex2) + subprocess.check_output(pex2) except subprocess.CalledProcessError as e: self.assertNotEqual(0, e.returncode) @@ -172,7 +172,7 @@ def test_pants_resolves_local_dists_for_current_platform_only(self): # Check that the pex was built. self.assertTrue(os.path.isfile(pex)) # Check that the pex runs. - output = subprocess.check_output(pex) + output = subprocess.check_output(pex).decode('utf-8') self._assert_native_greeting(output) def _get_current_platform_string(self): @@ -229,7 +229,7 @@ def test_python_distribution_with_setup_requires(self): # Check that the pex was built. self.assertTrue(os.path.isfile(pex)) # Check that the pex runs. - output = subprocess.check_output(pex) + output = subprocess.check_output(pex).decode('utf-8') self.assertIn('Hello, world!', output) finally: if os.path.exists(pex): diff --git a/tests/python/pants_test/backend/python/tasks/test_resolve_requirements.py b/tests/python/pants_test/backend/python/tasks/test_resolve_requirements.py index 2799d3a29b3f..858da23f6193 100644 --- a/tests/python/pants_test/backend/python/tasks/test_resolve_requirements.py +++ b/tests/python/pants_test/backend/python/tasks/test_resolve_requirements.py @@ -7,6 +7,7 @@ import os from builtins import str +from future.utils import PY3 from pex.interpreter import PythonInterpreter from pants.backend.python.interpreter_cache import PythonInterpreterCache @@ -34,7 +35,12 @@ def test_resolve_simple_requirements(self): # the requirement isn't sneaking in some other way, which would render the remainder # of this test moot.) _, stderr_data = self._exercise_module(self._resolve_requirements([noreqs_tgt]), 'colors') - self.assertIn('ImportError: No module named colors', stderr_data) + + try: + self.assertIn("ModuleNotFoundError: No module named 'colors'", stderr_data) + except AssertionError: + # < Python 3.6 uses ImportError instead of ModuleNotFoundError. + self.assertIn('ImportError: No module named colors', stderr_data) # Check that the module is available if specified as a requirement. stdout_data, stderr_data = self._exercise_module(self._resolve_requirements([ansicolors_tgt]), @@ -43,7 +49,7 @@ def test_resolve_simple_requirements(self): path = stdout_data.strip() # Check that the requirement resolved to what we expect. - self.assertTrue(path.endswith('/.deps/ansicolors-1.0.2-py2-none-any.whl/colors.py')) + self.assertTrue(path.endswith('/.deps/ansicolors-1.0.2-{}-none-any.whl/colors.py'.format('py3' if PY3 else 'py2'))) # Check that the path is under the test's build root, so we know the pex was created there. self.assertTrue(path.startswith(os.path.realpath(get_buildroot()))) @@ -136,9 +142,10 @@ def _resolve_requirements(self, target_roots, options=None): return context.products.get_data(ResolveRequirements.REQUIREMENTS_PEX) def _exercise_module(self, pex, expected_module): - with temporary_file() as f: + with temporary_file(binary_mode=False) as f: f.write('import {m}; print({m}.__file__)'.format(m=expected_module)) f.close() proc = pex.run(args=[f.name], blocking=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - return proc.communicate() + stdout, stderr = proc.communicate() + return (stdout.decode('utf-8'), stderr.decode('utf-8')) diff --git a/tests/python/pants_test/backend/python/tasks/test_setup_py.py b/tests/python/pants_test/backend/python/tasks/test_setup_py.py index 735eed449392..4c66b8017011 100644 --- a/tests/python/pants_test/backend/python/tasks/test_setup_py.py +++ b/tests/python/pants_test/backend/python/tasks/test_setup_py.py @@ -601,7 +601,7 @@ def test_prep_command_case(self): def test_detect_namespace_packages(): def has_ns(stmt): - with temporary_file() as fp: + with temporary_file(binary_mode=False) as fp: fp.write(stmt) fp.flush() return SetupPy.declares_namespace_package(fp.name) diff --git a/tests/python/pants_test/backend/python/test_interpreter_cache.py b/tests/python/pants_test/backend/python/test_interpreter_cache.py index 168dadec1df1..cc2832aa905a 100644 --- a/tests/python/pants_test/backend/python/test_interpreter_cache.py +++ b/tests/python/pants_test/backend/python/test_interpreter_cache.py @@ -9,6 +9,7 @@ from contextlib import contextmanager import mock +from future.utils import PY3 from pex.package import EggPackage, Package, SourcePackage from pex.resolver import Unsatisfiable, resolve @@ -28,7 +29,7 @@ def _make_bad_requirement(requirement): E.g. 'CPython==2.7.5' becomes 'CPython==99.7.5' """ - return str(requirement).replace('==2.', '==99.') + return str(requirement).replace('==3', '==99') if PY3 else str(requirement).replace('==2.', '==99') def setUp(self): super(TestInterpreterCache, self).setUp() diff --git a/tests/python/pants_test/cache/cache_server.py b/tests/python/pants_test/cache/cache_server.py index eb7539a90864..9dccfd2e7716 100644 --- a/tests/python/pants_test/cache/cache_server.py +++ b/tests/python/pants_test/cache/cache_server.py @@ -29,7 +29,7 @@ def do_HEAD(self): def do_PUT(self): path = self.translate_path(self.path) - content_length = int(self.headers.getheader('content-length')) + content_length = int(self.headers.get('content-length')) content = self.rfile.read(content_length) safe_mkdir(os.path.dirname(path)) with open(path, 'wb') as outfile: diff --git a/tests/python/pants_test/jvm/jvm_task_test_base.py b/tests/python/pants_test/jvm/jvm_task_test_base.py index 01eaf3472227..4186a33f2959 100644 --- a/tests/python/pants_test/jvm/jvm_task_test_base.py +++ b/tests/python/pants_test/jvm/jvm_task_test_base.py @@ -43,7 +43,7 @@ def add_to_runtime_classpath(self, context, tgt, files_dict): safe_mkdir(target_dir) classpath_dir = safe_mkdtemp(dir=target_dir) for rel_path, content in files_dict.items(): - safe_file_dump(os.path.join(classpath_dir, rel_path), content) + safe_file_dump(os.path.join(classpath_dir, rel_path), content, binary_mode=False) # Add to the classpath. runtime_classpath.add_for_target(tgt, [('default', classpath_dir)]) diff --git a/tests/python/pants_test/pants_run_integration_test.py b/tests/python/pants_test/pants_run_integration_test.py index bf2f9a847b98..48d1c9ba1c83 100644 --- a/tests/python/pants_test/pants_run_integration_test.py +++ b/tests/python/pants_test/pants_run_integration_test.py @@ -411,7 +411,7 @@ def bundle_and_run(self, target, bundle_name, bundle_jar_name=None, bundle_optio stdout, _ = java_run.communicate() java_returncode = java_run.returncode self.assertEqual(java_returncode, 0) - return stdout + return stdout.decode('utf-8') def assert_success(self, pants_run, msg=None): self.assert_result(pants_run, self.PANTS_SUCCESS_CODE, expected=True, msg=msg) diff --git a/tests/python/pants_test/task_test_base.py b/tests/python/pants_test/task_test_base.py index 0ecfd1a80719..633faee3afef 100644 --- a/tests/python/pants_test/task_test_base.py +++ b/tests/python/pants_test/task_test_base.py @@ -198,7 +198,7 @@ def execute_task(self, targets=None, options=None): context = self.context(target_roots=targets, console_outstream=output) task = self.create_task(context) task.execute() - return output.getvalue() + return output.getvalue().decode('utf-8') def execute_console_task(self, targets=None, extra_targets=None, options=None, passthru_args=None, workspace=None, scheduler=None):