From 232596f70a5c7362e78e5c7d3c81bfef7a17b588 Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Fri, 27 Jul 2018 21:55:39 -0400 Subject: [PATCH 1/2] Port test/tasks and get passing on Py3 --- tests/python/pants_test/tasks/task_test_base.py | 10 +++++++--- tests/python/pants_test/tasks/test_execution_graph.py | 9 +++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/python/pants_test/tasks/task_test_base.py b/tests/python/pants_test/tasks/task_test_base.py index dcf15a2dfd7..a404b56938b 100644 --- a/tests/python/pants_test/tasks/task_test_base.py +++ b/tests/python/pants_test/tasks/task_test_base.py @@ -7,7 +7,9 @@ import glob import os from contextlib import closing, contextmanager -from StringIO import StringIO +from io import BytesIO + +from future.utils import PY2 from pants.base.deprecated import deprecated_module from pants.goal.goal import Goal @@ -107,7 +109,9 @@ def synthesize_task_subtype(self, task_type, options_scope): :param options_scope: The scope to give options on the generated task type. :return: A pair (type, options_scope) """ - subclass_name = b'test_{0}_{1}'.format(task_type.__name__, options_scope) + subclass_name = 'test_{0}_{1}'.format(task_type.__name__, options_scope) + if PY2: + subclass_name = subclass_name.encode('utf-8') return type(subclass_name, (task_type,), {'_stable_name': task_type._compute_stable_name(), 'options_scope': options_scope}) @@ -193,7 +197,7 @@ def execute_task(self, targets=None, options=None): Returns the text output of the task. """ options = options or {} - with closing(StringIO()) as output: + with closing(BytesIO()) as output: self.set_options(**options) context = self.context(target_roots=targets, console_outstream=output) task = self.create_task(context) diff --git a/tests/python/pants_test/tasks/test_execution_graph.py b/tests/python/pants_test/tasks/test_execution_graph.py index 03e2358eeff..dfb68566f70 100644 --- a/tests/python/pants_test/tasks/test_execution_graph.py +++ b/tests/python/pants_test/tasks/test_execution_graph.py @@ -6,8 +6,11 @@ import re import unittest +from builtins import object, str from collections import defaultdict +from future.utils import PY3 + from pants.backend.jvm.tasks.jvm_compile.execution_graph import (ExecutionFailure, ExecutionGraph, Job, JobExistsError, NoRootJobError, UnknownJobError) @@ -187,7 +190,8 @@ def test_non_existent_dependency_causes_failure(self): ExecutionGraph([self.job("A", passing_fn, []), self.job("B", passing_fn, ["Z"])], False) - self.assertEqual("Unexecutable graph: Undefined dependencies u'Z'", str(cm.exception)) + self.assertEqual("Unexecutable graph: Undefined dependencies " + "'Z'" if PY3 else "u'Z'", + str(cm.exception)) def test_on_success_callback_raises_error(self): exec_graph = ExecutionGraph([self.job("A", passing_fn, [], on_success=raising_fn)], False) @@ -210,7 +214,8 @@ def test_same_key_scheduled_twice_is_error(self): ExecutionGraph([self.job("Same", passing_fn, []), self.job("Same", passing_fn, [])], False) - self.assertEqual("Unexecutable graph: Job already scheduled u'Same'", str(cm.exception)) + self.assertEqual("Unexecutable graph: Job already scheduled " + "'Same'" if PY3 else "u'Same'", + str(cm.exception)) def test_priorities_for_chain_of_jobs(self): exec_graph = ExecutionGraph([self.job("A", passing_fn, [], 8), From a75770c51b98ece0c45d3b83ec62725902cc379e Mon Sep 17 00:00:00 2001 From: Eric Arellano Date: Fri, 27 Jul 2018 23:42:18 -0400 Subject: [PATCH 2/2] Fix Py2 test regression --- tests/python/pants_test/tasks/test_execution_graph.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/python/pants_test/tasks/test_execution_graph.py b/tests/python/pants_test/tasks/test_execution_graph.py index dfb68566f70..8c8918a7448 100644 --- a/tests/python/pants_test/tasks/test_execution_graph.py +++ b/tests/python/pants_test/tasks/test_execution_graph.py @@ -190,7 +190,7 @@ def test_non_existent_dependency_causes_failure(self): ExecutionGraph([self.job("A", passing_fn, []), self.job("B", passing_fn, ["Z"])], False) - self.assertEqual("Unexecutable graph: Undefined dependencies " + "'Z'" if PY3 else "u'Z'", + self.assertEqual("Unexecutable graph: Undefined dependencies " + ("'Z'" if PY3 else "u'Z'"), str(cm.exception)) def test_on_success_callback_raises_error(self): @@ -214,7 +214,7 @@ def test_same_key_scheduled_twice_is_error(self): ExecutionGraph([self.job("Same", passing_fn, []), self.job("Same", passing_fn, [])], False) - self.assertEqual("Unexecutable graph: Job already scheduled " + "'Same'" if PY3 else "u'Same'", + self.assertEqual("Unexecutable graph: Job already scheduled " + ("'Same'" if PY3 else "u'Same'"), str(cm.exception)) def test_priorities_for_chain_of_jobs(self):