diff --git a/contrib/avro/tests/python/pants_test/contrib/avro/tasks/test_avro_gen.py b/contrib/avro/tests/python/pants_test/contrib/avro/tasks/test_avro_gen.py index f76af01402c..8c3e7557f62 100644 --- a/contrib/avro/tests/python/pants_test/contrib/avro/tasks/test_avro_gen.py +++ b/contrib/avro/tests/python/pants_test/contrib/avro/tasks/test_avro_gen.py @@ -58,7 +58,7 @@ def test_avro_java_gen(self): ) ''')) - self.create_file(relpath='avro-build/src/avro/schema.avsc', contents=dedent(''' + self.create_file(relpath='avro-build/src/avro/schema.avsc', mode='w', contents=dedent(''' { "namespace": "", "type": "record", @@ -70,7 +70,7 @@ def test_avro_java_gen(self): } ''')) - self.create_file(relpath='avro-build/src/avro/record.avdl', contents=dedent(''' + self.create_file(relpath='avro-build/src/avro/record.avdl', mode='w', contents=dedent(''' protocol Test { void test(); } diff --git a/contrib/confluence/src/python/pants/contrib/confluence/util/confluence_util.py b/contrib/confluence/src/python/pants/contrib/confluence/util/confluence_util.py index 59c5c108e01..032563eb90d 100644 --- a/contrib/confluence/src/python/pants/contrib/confluence/util/confluence_util.py +++ b/contrib/confluence/src/python/pants/contrib/confluence/util/confluence_util.py @@ -9,6 +9,9 @@ import mimetypes from builtins import object, str from os.path import basename +from xmlrpc.client import Binary +from xmlrpc.client import Error as XMLRPCError +from xmlrpc.client import ServerProxy from future.moves.urllib.parse import quote_plus @@ -21,10 +24,6 @@ """Code to ease publishing text to Confluence wikis.""" -try: - from xmlrpc.client import ServerProxy, Error as XMLRPCError, Binary -except ImportError: - from xmlrpclib import ServerProxy, Error as XMLRPCError, Binary mimetypes.init() diff --git a/contrib/findbugs/tests/python/pants_test/contrib/findbugs/tasks/test_findbugs_integration.py b/contrib/findbugs/tests/python/pants_test/contrib/findbugs/tasks/test_findbugs_integration.py index 42cfcd168de..e277ac0d60a 100644 --- a/contrib/findbugs/tests/python/pants_test/contrib/findbugs/tasks/test_findbugs_integration.py +++ b/contrib/findbugs/tests/python/pants_test/contrib/findbugs/tasks/test_findbugs_integration.py @@ -79,7 +79,7 @@ def test_max_rank_fail_on_error(self): def test_exclude(self): cmd = ['compile', 'contrib/findbugs/tests/java/org/pantsbuild/contrib/findbugs::'] - with temporary_file(root_dir=get_buildroot()) as exclude_file: + with temporary_file(root_dir=get_buildroot(), binary_mode=False) as exclude_file: exclude_file.write(dedent("""\ @@ -102,7 +102,7 @@ def test_exclude(self): def test_error(self): cmd = ['compile', 'contrib/findbugs/tests/java/org/pantsbuild/contrib/findbugs:high'] - with temporary_file(root_dir=get_buildroot()) as exclude_file: + with temporary_file(root_dir=get_buildroot(), binary_mode=False) as exclude_file: exclude_file.write(dedent("""\ diff --git a/contrib/go/tests/python/pants_test/contrib/go/subsystems/test_go_distribution.py b/contrib/go/tests/python/pants_test/contrib/go/subsystems/test_go_distribution.py index 6a776c7ea76..33055c0452f 100644 --- a/contrib/go/tests/python/pants_test/contrib/go/subsystems/test_go_distribution.py +++ b/contrib/go/tests/python/pants_test/contrib/go/subsystems/test_go_distribution.py @@ -23,8 +23,8 @@ def distribution(self): def test_bootstrap(self): go_distribution = self.distribution() go_cmd = go_distribution.create_go_cmd(cmd='env', args=['GOROOT']) - output = go_cmd.check_output() - self.assertEqual(go_distribution.goroot, output.strip()) + output = go_cmd.check_output().decode('utf-8').strip() + self.assertEqual(go_distribution.goroot, output) def assert_no_gopath(self): go_distribution = self.distribution() @@ -39,7 +39,7 @@ def assert_no_gopath(self): cmd = [os.path.join(go_distribution.goroot, 'bin', 'go'), 'env', 'GOPATH'] env = os.environ.copy() env.update(go_env) - default_gopath = subprocess.check_output(cmd, env=env).strip() + default_gopath = subprocess.check_output(cmd, env=env).decode('utf-8').strip() go_cmd = go_distribution.create_go_cmd(cmd='env', args=['GOPATH']) @@ -48,7 +48,7 @@ def assert_no_gopath(self): self.assertEqual(['env', 'GOPATH'], go_cmd.cmdline[1:]) self.assertRegexpMatches(str(go_cmd), r'^GOROOT=[^ ]+ GOPATH={} .*/go env GOPATH'.format(default_gopath)) - self.assertEqual(default_gopath, go_cmd.check_output().strip()) + self.assertEqual(default_gopath, go_cmd.check_output().decode('utf-8').strip()) def test_go_command_no_gopath(self): self.assert_no_gopath() diff --git a/contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_binary_integration.py b/contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_binary_integration.py index 1dd524c44b5..9e81aca815a 100644 --- a/contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_binary_integration.py +++ b/contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_binary_integration.py @@ -19,4 +19,4 @@ def test_go_crosscompile(self): 'contrib/go/examples/src/go/hello'] pants_run = self.run_pants(args, extra_env={"GOOS": "windows"}) self.assert_success(pants_run) - self.assertIn("for MS Windows", subprocess.check_output(["file", output_file])) + self.assertIn(b"for MS Windows", subprocess.check_output(["file", output_file])) diff --git a/contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_buildgen.py b/contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_buildgen.py index 2a9f4a3b793..d5b13c305df 100644 --- a/contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_buildgen.py +++ b/contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_buildgen.py @@ -93,7 +93,7 @@ def test_multiple_remote_roots_failure(self): task.execute() def test_existing_targets_wrong_type(self): - self.create_file(relpath='src/go/src/fred/foo.go', contents=dedent(""" + self.create_file(relpath='src/go/src/fred/foo.go', mode='w', contents=dedent(""" package main import "fmt" @@ -109,7 +109,7 @@ def test_existing_targets_wrong_type(self): self.assertEqual(GoTargetGenerator.WrongLocalSourceTargetTypeError, type(exc.exception.cause)) def test_noop_applicable_targets_simple(self): - self.create_file(relpath='src/go/src/fred/foo.go', contents=dedent(""" + self.create_file(relpath='src/go/src/fred/foo.go', mode='w', contents=dedent(""" package main import "fmt" @@ -125,13 +125,13 @@ def test_noop_applicable_targets_simple(self): self.assertEqual(expected, context.targets()) def test_noop_applicable_targets_complete_graph(self): - self.create_file(relpath='src/go/src/jane/bar.go', contents=dedent(""" + self.create_file(relpath='src/go/src/jane/bar.go', mode='w', contents=dedent(""" package jane var PublicConstant = 42 """)) jane = self.make_target('src/go/src/jane', GoLibrary) - self.create_file(relpath='src/go/src/fred/foo.go', contents=dedent(""" + self.create_file(relpath='src/go/src/fred/foo.go', mode='w', contents=dedent(""" package main import ( @@ -157,12 +157,12 @@ def stitch_deps_local(self, materialize): # We need physical directories on disk for `--materialize` since it does scans. self.create_dir('src/go/src') - self.create_file(relpath='src/go/src/jane/bar.go', contents=dedent(""" + self.create_file(relpath='src/go/src/jane/bar.go', mode='w', contents=dedent(""" package jane var PublicConstant = 42 """)) - self.create_file(relpath='src/go/src/fred/foo.go', contents=dedent(""" + self.create_file(relpath='src/go/src/fred/foo.go', mode='w', contents=dedent(""" package main import ( @@ -218,14 +218,14 @@ def stitch_deps_remote(self, remote=True, materialize=False, fail_floating=False self.create_dir('3rdparty/go') self.create_dir('src/go/src') - self.create_file(relpath='src/go/src/jane/bar.go', contents=dedent(""" + self.create_file(relpath='src/go/src/jane/bar.go', mode='w', contents=dedent(""" package jane import "pantsbuild.org/fake/prod" var PublicConstant = prod.DoesNotExistButWeShouldNotCareWhenCheckingDepsAndNotInstalling """)) - self.create_file(relpath='src/go/src/fred/foo.go', contents=dedent(""" + self.create_file(relpath='src/go/src/fred/foo.go', mode='w', contents=dedent(""" package main import ( @@ -318,7 +318,7 @@ def test_issues_2395(self): self.add_to_build_file(relpath='3rdparty/go/pantsbuild.org/fake', target='go_remote_library(rev="v4.5.6")') - self.create_file(relpath='src/go/src/jane/bar.go', contents=dedent(""" + self.create_file(relpath='src/go/src/jane/bar.go', mode='w', contents=dedent(""" package jane import "pantsbuild.org/fake" @@ -339,12 +339,12 @@ def test_issues_2395(self): def test_issues_2616(self): self.set_options(remote=False) - self.create_file(relpath='src/go/src/jane/bar.go', contents=dedent(""" + self.create_file(relpath='src/go/src/jane/bar.go', mode='w', contents=dedent(""" package jane var PublicConstant = 42 """)) - self.create_file(relpath='src/go/src/fred/foo.go', contents=dedent(""" + self.create_file(relpath='src/go/src/fred/foo.go', mode='w', contents=dedent(""" package main /* @@ -379,19 +379,19 @@ def test_issues_2787(self): self.set_options(remote=False, materialize=False) - self.create_file(relpath='src/go/src/helper/helper.go', contents=dedent(""" + self.create_file(relpath='src/go/src/helper/helper.go', mode='w', contents=dedent(""" package helper const PublicConstant = 42 """)) - self.create_file(relpath='src/go/src/lib/lib.go', contents=dedent(""" + self.create_file(relpath='src/go/src/lib/lib.go', mode='w', contents=dedent(""" package lib const privateConstant = 42 """)) - self.create_file(relpath='src/go/src/lib/lib_test.go', contents=dedent(""" + self.create_file(relpath='src/go/src/lib/lib_test.go', mode='w', contents=dedent(""" package lib_test import ( diff --git a/contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_fetch.py b/contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_fetch.py index 6da0f6dfc32..4dcfbe60f87 100644 --- a/contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_fetch.py +++ b/contrib/go/tests/python/pants_test/contrib/go/tasks/test_go_fetch.py @@ -27,7 +27,7 @@ def task_type(cls): def test_get_remote_import_paths(self): go_fetch = self.create_task(self.context()) - self.create_file('src/github.com/u/a/a.go', contents=""" + self.create_file('src/github.com/u/a/a.go', mode='w', contents=""" package a import ( @@ -77,7 +77,7 @@ def _create_package(self, dirpath, name, deps): """Creates a Go package inside dirpath named 'name' importing deps.""" imports = ['import "localzip/{}"'.format(d) for d in deps] f = os.path.join(dirpath, '{name}/{name}.go'.format(name=name)) - self.create_file(f, contents= + self.create_file(f, mode='w', contents= """package {name} {imports} """.format(name=name, imports='\n'.join(imports))) @@ -192,7 +192,7 @@ def test_transitive_download_remote_libs_undeclared_deps(self): def test_issues_2616(self): go_fetch = self.create_task(self.context()) - self.create_file('src/github.com/u/a/a.go', contents=""" + self.create_file('src/github.com/u/a/a.go', mode='w', contents=""" package a import ( @@ -203,7 +203,7 @@ def test_issues_2616(self): "bitbucket.org/u/b" ) """) - self.create_file('src/github.com/u/a/b.go', contents=""" + self.create_file('src/github.com/u/a/b.go', mode='w', contents=""" package a /* diff --git a/contrib/googlejavaformat/tests/python/pants_test/contrib/googlejavaformat/test_googlejavaformat.py b/contrib/googlejavaformat/tests/python/pants_test/contrib/googlejavaformat/test_googlejavaformat.py index 1e8473e7b60..f2eb3432501 100644 --- a/contrib/googlejavaformat/tests/python/pants_test/contrib/googlejavaformat/test_googlejavaformat.py +++ b/contrib/googlejavaformat/tests/python/pants_test/contrib/googlejavaformat/test_googlejavaformat.py @@ -53,6 +53,7 @@ def task_type(cls): def test_googlejavaformat(self): javafile = self.create_file( relpath='src/java/org/pantsbuild/contrib/googlejavaformat/MyClass.java', + mode='w', contents=self._BADFORMAT) target = self.make_target( spec='src/java/org/pantsbuild/contrib/googlejavaformat', @@ -75,6 +76,7 @@ def task_type(cls): def test_lint_badformat(self): self.create_file( relpath='src/java/org/pantsbuild/contrib/googlejavaformat/MyClass.java', + mode='w', contents=self._BADFORMAT) target = self.make_target( spec='src/java/org/pantsbuild/contrib/googlejavaformat', @@ -92,6 +94,7 @@ def test_lint_badformat(self): def test_lint_goodformat(self): self.create_file( relpath='src/java/org/pantsbuild/contrib/googlejavaformat/MyClass.java', + mode='w', contents=self._GOODFORMAT) target = self.make_target( spec='src/java/org/pantsbuild/contrib/googlejavaformat', diff --git a/contrib/node/tests/python/pants_test/contrib/node/subsystems/test_node_distribution.py b/contrib/node/tests/python/pants_test/contrib/node/subsystems/test_node_distribution.py index 0ef72719627..fa22c88431c 100644 --- a/contrib/node/tests/python/pants_test/contrib/node/subsystems/test_node_distribution.py +++ b/contrib/node/tests/python/pants_test/contrib/node/subsystems/test_node_distribution.py @@ -21,28 +21,28 @@ def setUp(self): def test_bootstrap(self): node_cmd = self.distribution.node_command(args=['--version']) - output = node_cmd.check_output() - self.assertEqual(self.distribution.version(), output.strip()) + output = node_cmd.check_output().decode('utf-8').strip() + self.assertEqual(self.distribution.version(), output) def test_node(self): node_command = self.distribution.node_command(args=['--interactive']) # Force a REPL session. repl = node_command.run(stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, err = repl.communicate('console.log("Hello World!")') - self.assertEqual('', err) + out, err = repl.communicate(b'console.log("Hello World!")') + self.assertEqual(b'', err) self.assertEqual(0, repl.returncode) for line in out.splitlines(): - if line.endswith('Hello World!'): + if line.endswith(b'Hello World!'): break else: self.fail('Did not find the expected "Hello World!" in the REPL session ' - 'output:\n{}'.format(out)) + 'output:\n{}'.format(out.decode('utf-8'))) def test_npm(self): npm_version_flag = self.distribution.get_package_manager('npm').run_command( args=['--version']) - raw_version = npm_version_flag.check_output().strip() + raw_version = npm_version_flag.check_output().decode('utf-8').strip() npm_version_cmd = self.distribution.get_package_manager('npm').run_command( args=['version', '--json']) @@ -54,7 +54,7 @@ def test_npm(self): def test_yarnpkg(self): yarnpkg_version_command = self.distribution.get_package_manager('yarn').run_command( args=['--version']) - yarnpkg_version = yarnpkg_version_command.check_output().strip() + yarnpkg_version = yarnpkg_version_command.check_output().decode('utf-8').strip() yarnpkg_versions_command = self.distribution.get_package_manager('yarn').run_command( args=['versions', '--json']) yarnpkg_versions = json.loads(yarnpkg_versions_command.check_output()) @@ -67,7 +67,7 @@ def test_node_command_path_injection(self): # Test the case in which we do not pass in env, # which should fall back to env=os.environ.copy() - injected_paths = node_path_cmd.check_output().strip().split(os.pathsep) + injected_paths = node_path_cmd.check_output().decode('utf-8').strip().split(os.pathsep) self.assertEqual(node_bin_path, injected_paths[0]) def test_node_command_path_injection_with_overrided_path(self): @@ -76,7 +76,7 @@ def test_node_command_path_injection_with_overrided_path(self): node_bin_path = self.distribution._install_node() injected_paths = node_path_cmd.check_output( env={'PATH': '/test/path'} - ).strip().split(os.pathsep) + ).decode('utf-8').strip().split(os.pathsep) self.assertEqual(node_bin_path, injected_paths[0]) self.assertListEqual([node_bin_path, '/test/path'], injected_paths) @@ -86,5 +86,5 @@ def test_node_command_path_injection_with_empty_path(self): node_bin_path = self.distribution._install_node() injected_paths = node_path_cmd.check_output( env={'PATH': ''} - ).strip().split(os.pathsep) + ).decode('utf-8').strip().split(os.pathsep) self.assertListEqual([node_bin_path, ''], injected_paths) diff --git a/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_build.py b/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_build.py index 57b24434e23..0f05ad074f2 100644 --- a/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_build.py +++ b/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_build.py @@ -102,6 +102,7 @@ def test_node_module_no_artifacts(self): def test_run_build_script(self): package_json_file = self.create_file( 'src/node/build_test/package.json', + mode='w', contents=dedent(""" { "scripts": { @@ -131,7 +132,7 @@ def test_run_build_script(self): def test_run_non_existing_script(self): package_json_file = self.create_file( - 'src/node/build_test/package.json', contents='{}') + 'src/node/build_test/package.json', mode='w', contents='{}') build_script = 'my_non_existing_build_scirpt' target = self.make_target( spec='src/node/build_test', @@ -144,6 +145,7 @@ def test_run_non_existing_script(self): def test_run_no_output_dir(self): package_json_file = self.create_file( 'src/node/build_test/package.json', + mode='w', contents=dedent(""" { "scripts": { diff --git a/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_bundle_integration.py b/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_bundle_integration.py index 905b3759c4a..1b019dfa362 100644 --- a/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_bundle_integration.py +++ b/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_bundle_integration.py @@ -136,7 +136,7 @@ def test_no_bundle_for_node_module(self): def _extract_archive(self, archive_path): with temporary_dir() as temp_dir: _, extension = os.path.splitext(archive_path) - print (extension) + print(extension) if extension == '.jar': extraction_archiver = create_archiver('zip') else: diff --git a/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_lint_integration.py b/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_lint_integration.py index 76d63928d02..0311ab2cd29 100644 --- a/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_lint_integration.py +++ b/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_lint_integration.py @@ -20,7 +20,7 @@ def test_lint_success_with_target_level_ignore(self): path = 'contrib/node/examples/src/node/javascriptstyle-empty/index.js' content = 'const console = require(\'console\');\nconsole.log("Double Quotes");\n' - with self.temporary_file_content(path, content): + with self.temporary_file_content(path, content, binary_mode=False): command = ['lint', 'contrib/node/examples/src/node/javascriptstyle-empty'] pants_run = self.run_pants(command=command) @@ -31,7 +31,7 @@ def test_lint_failure_without_target_level_ignore(self): path = 'contrib/node/examples/src/node/javascriptstyle-empty/not_ignored_index.js' content = 'const console = require(\'console\');\nconsole.log("Double Quotes");\n' - with self.temporary_file_content(path, content): + with self.temporary_file_content(path, content, binary_mode=False): command = ['lint', 'contrib/node/examples/src/node/javascriptstyle-empty'] pants_run = self.run_pants(command=command) diff --git a/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_repl_integration.py b/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_repl_integration.py index bef613b1daa..28e2aac7c7d 100644 --- a/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_repl_integration.py +++ b/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_repl_integration.py @@ -57,7 +57,7 @@ def test_run_repl_multiple_targets(self): var calc = new Calculator(0); calc.add(1); console.log('React: ' + reactElem + ', Calc + 1: ' + calc.number); - """) + """).encode('utf-8') pants_run = self.run_pants(command=command, stdin_data=program) self.assert_success(pants_run) diff --git a/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_resolve.py b/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_resolve.py index a0dff10d9f7..edd1a01bba4 100644 --- a/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_resolve.py +++ b/contrib/node/tests/python/pants_test/contrib/node/tasks/test_node_resolve.py @@ -181,7 +181,7 @@ def test_resolve_simple_graph(self): self.assertIn('type of bool is: boolean', lines) def test_resolve_preserves_package_json(self): - self.create_file('src/node/util/package.json', contents=dedent(""" + self.create_file('src/node/util/package.json', mode='w', contents=dedent(""" { "name": "util", "version": "0.0.1" @@ -192,7 +192,7 @@ def test_resolve_preserves_package_json(self): sources=['package.json'], dependencies=[]) - self.create_file('src/node/scripts_project/package.json', contents=dedent(""" + self.create_file('src/node/scripts_project/package.json', mode='w', contents=dedent(""" { "name": "scripts_project", "version": "1.2.3", @@ -239,18 +239,18 @@ def test_resolve_preserves_package_json(self): def _test_resolve_optional_install_helper( self, install_optional, package_manager, expected_params): - self.create_file('src/node/util/package.json', contents=dedent(""" + self.create_file('src/node/util/package.json', mode='w', contents=dedent(""" { "name": "util", "version": "0.0.1" } """)) - self.create_file('src/node/util/util.js', contents=dedent(""" + self.create_file('src/node/util/util.js', mode='w', contents=dedent(""" var typ = require('typ'); console.log("type of boolean is: " + typ.BOOLEAN); """)) # yarn execution path requires yarn.lock - self.create_file('src/node/util/yarn.lock', contents='') + self.create_file('src/node/util/yarn.lock') target = self.make_target(spec='src/node/util', target_type=NodeModule, sources=['util.js', 'package.json', 'yarn.lock'], diff --git a/contrib/scalajs/tests/python/pants_test/contrib/scalajs/tasks/test_scalajs_repl_integration.py b/contrib/scalajs/tests/python/pants_test/contrib/scalajs/tasks/test_scalajs_repl_integration.py index a131a0cdbb4..5d164d57caf 100644 --- a/contrib/scalajs/tests/python/pants_test/contrib/scalajs/tasks/test_scalajs_repl_integration.py +++ b/contrib/scalajs/tests/python/pants_test/contrib/scalajs/tasks/test_scalajs_repl_integration.py @@ -22,7 +22,7 @@ def test_run_repl(self): var _ = require('factfinder'); var tenFactorial = org.pantsbuild.scalajs.example.factfinder.Factfinder().fact(10); console.log(tenFactorial) - """) + """).encode('utf-8') pants_run = self.run_pants(command=command, stdin_data=program) self.assert_success(pants_run) diff --git a/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_scrooge_gen.py b/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_scrooge_gen.py index 83cea1ae630..0bfec72c1cc 100644 --- a/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_scrooge_gen.py +++ b/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_scrooge_gen.py @@ -110,7 +110,7 @@ def _test_help(self, language, library_type, compiler_args, sources): } ''') - self.create_file(relpath='test_smoke/a.thrift', contents=contents) + self.create_file(relpath='test_smoke/a.thrift', mode='w', contents=contents) build_string = self._test_create_build_str(language, compiler_args) self.add_to_build_file('test_smoke', build_string) @@ -171,6 +171,6 @@ def test_exception_deps(self): def _test_dependencies_help(self, contents, declares_service, declares_exception): source = 'test_smoke/a.thrift' - self.create_file(relpath=source, contents=contents) + self.create_file(relpath=source, mode='w', contents=contents) self.assertEquals(ScroogeGen._declares_service(source), declares_service) self.assertEquals(ScroogeGen._declares_exception(source), declares_exception) diff --git a/src/python/pants/fs/archive.py b/src/python/pants/fs/archive.py index ecd22314dcd..3548b2a2911 100644 --- a/src/python/pants/fs/archive.py +++ b/src/python/pants/fs/archive.py @@ -175,7 +175,7 @@ def _extract(self, path, outdir, filter_func=None): with open_zip(path) as archive_file: for name in archive_file.namelist(): # While we're at it, we also perform this safety test. - if name.startswith(b'/') or name.startswith(b'..'): + if name.startswith('/') or name.startswith('..'): raise ValueError('Zip file contains unsafe path: {}'.format(name)) if (not filter_func or filter_func(name)): archive_file.extract(name, outdir) diff --git a/tests/python/pants_test/backend/python/tasks/python_task_test_base.py b/tests/python/pants_test/backend/python/tasks/python_task_test_base.py index c8f79b866f3..47419ff91ed 100644 --- a/tests/python/pants_test/backend/python/tasks/python_task_test_base.py +++ b/tests/python/pants_test/backend/python/tasks/python_task_test_base.py @@ -74,7 +74,7 @@ def create_python_library(self, relpath, name, source_contents_map=None, if source_contents_map: self.create_file(relpath=os.path.join(relpath, '__init__.py')) for source, contents in source_contents_map.items(): - self.create_file(relpath=os.path.join(relpath, source), contents=contents) + self.create_file(relpath=os.path.join(relpath, source), mode='w', contents=contents) return self.target(Address(relpath, name).spec) def create_python_binary(self, relpath, name, entry_point, dependencies=(), provides=None, shebang=None): diff --git a/tests/python/pants_test/pants_run_integration_test.py b/tests/python/pants_test/pants_run_integration_test.py index c8e39908078..39aeb9c9233 100644 --- a/tests/python/pants_test/pants_run_integration_test.py +++ b/tests/python/pants_test/pants_run_integration_test.py @@ -429,13 +429,14 @@ def file_renamed(self, prefix, test_name, real_name): os.rename(real_path, test_path) @contextmanager - def temporary_file_content(self, path, content): + def temporary_file_content(self, path, content, binary_mode=True): """Temporarily write content to a file for the purpose of an integration test.""" path = os.path.realpath(path) assert path.startswith( os.path.realpath(get_buildroot())), 'cannot write paths outside of the buildroot!' assert not os.path.exists(path), 'refusing to overwrite an existing path!' - with open(path, 'wb') as fh: + mode = 'wb' if binary_mode else 'w' + with open(path, mode) as fh: fh.write(content) try: yield diff --git a/tests/python/pants_test/test_base.py b/tests/python/pants_test/test_base.py index 48ccacf3ec5..6d22b9669eb 100644 --- a/tests/python/pants_test/test_base.py +++ b/tests/python/pants_test/test_base.py @@ -219,7 +219,7 @@ def make_target(self, if make_missing_sources and 'sources' in kwargs: for source in kwargs['sources']: if '*' not in source: - self.create_file(os.path.join(address.spec_path, source), mode='a') + self.create_file(os.path.join(address.spec_path, source), mode='a', contents='') kwargs['sources'] = self.sources_for(kwargs['sources'], address.spec_path) target = target_type(name=address.target_name,