aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/test/skylark/skylark_test.py12
-rw-r--r--src/test/skylark/skylint/skylint_test.py9
2 files changed, 14 insertions, 7 deletions
diff --git a/src/test/skylark/skylark_test.py b/src/test/skylark/skylark_test.py
index ae617b0208..55bf92b7ec 100644
--- a/src/test/skylark/skylark_test.py
+++ b/src/test/skylark/skylark_test.py
@@ -38,8 +38,9 @@ class SkylarkTest(unittest.TestCase):
def chunks(self, path):
code = []
expected_errors = []
- with open(path) as f:
+ with open(path, mode="rb") as f:
for line in f:
+ line = line.decode("utf-8")
if line.strip() == self.CHUNK_SEP:
yield code, expected_errors
expected_errors = []
@@ -91,9 +92,12 @@ def assert_(cond, msg="assertion failed"):
print("===", t, "===")
f = os.path.join(testenv.SKYLARK_TESTDATA_PATH, t)
for chunk, expected in self.chunks(f):
- with tempfile.NamedTemporaryFile(suffix=".sky", delete=False) as tmp:
- tmp.writelines([self.PRELUDE] + chunk)
- output = self.evaluate(tmp.name)
+ with tempfile.NamedTemporaryFile(
+ mode="wb", suffix=".sky", delete=False) as tmp:
+ lines = [line.encode("utf-8") for line in
+ [self.PRELUDE] + chunk]
+ tmp.writelines(lines)
+ output = self.evaluate(tmp.name).decode("utf-8")
os.unlink(tmp.name)
self.check_output(output, expected)
diff --git a/src/test/skylark/skylint/skylint_test.py b/src/test/skylark/skylint/skylint_test.py
index eec9a4fd3d..26dba1dc88 100644
--- a/src/test/skylark/skylint/skylint_test.py
+++ b/src/test/skylark/skylint/skylint_test.py
@@ -28,6 +28,7 @@ class SkylintTest(unittest.TestCase):
testenv.SKYLINT_BINARY_PATH,
os.path.join(testenv.SKYLINT_TESTDATA_PATH, "good.bzl.test")
])
+ output = output.decode("utf-8")
self.assertEqual(output, "")
def testBadFile(self):
@@ -38,7 +39,7 @@ class SkylintTest(unittest.TestCase):
os.path.join(testenv.SKYLINT_TESTDATA_PATH, "bad.bzl.test")
])
except subprocess.CalledProcessError as e:
- issues = e.output
+ issues = e.output.decode("utf-8")
self.assertIn("no module docstring", issues)
def testNonexistingFile(self):
@@ -48,7 +49,7 @@ class SkylintTest(unittest.TestCase):
[testenv.SKYLINT_BINARY_PATH, "does_not_exist.bzl"],
stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
- output = e.output
+ output = e.output.decode("utf-8")
self.assertEqual("File not found: does_not_exist.bzl\n", output)
def testDisablingCheck(self):
@@ -56,6 +57,7 @@ class SkylintTest(unittest.TestCase):
testenv.SKYLINT_BINARY_PATH, "--disable-checks=docstring",
os.path.join(testenv.SKYLINT_TESTDATA_PATH, "bad.bzl.test")
])
+ output = output.decode("utf-8")
self.assertEqual(output, "")
def testDisablingCategory(self):
@@ -64,6 +66,7 @@ class SkylintTest(unittest.TestCase):
"--disable-categories=missing-module-docstring",
os.path.join(testenv.SKYLINT_TESTDATA_PATH, "bad.bzl.test")
])
+ output = output.decode("utf-8")
self.assertEqual(output, "")
IMPORT_BZL_CONTENTS = """
@@ -90,7 +93,7 @@ def foo():
os.path.join(temp_dir, "dependencies.bzl")
] + options)
except subprocess.CalledProcessError as e:
- output = e.output
+ output = e.output.decode("utf-8")
return output
finally:
shutil.rmtree(temp_dir)