From 8e7848c63efe36f09e4651bece8c0efc34a1c3e1 Mon Sep 17 00:00:00 2001 From: Zsolt Dollenstein Date: Thu, 12 Apr 2018 19:19:21 +0100 Subject: [PATCH] Open temporary files with utf-8 encoding (#126) This is not the default on Windows. --- black.py | 2 +- tests/test_black.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/black.py b/black.py index 537ba59..587d9b3 100644 --- a/black.py +++ b/black.py @@ -2325,7 +2325,7 @@ def dump_to_file(*output: str) -> str: import tempfile with tempfile.NamedTemporaryFile( - mode="w", prefix="blk_", suffix=".log", delete=False + mode="w", prefix="blk_", suffix=".log", delete=False, encoding="utf8" ) as f: for lines in output: f.write(lines) diff --git a/tests/test_black.py b/tests/test_black.py index f71f9b3..6e6aad8 100644 --- a/tests/test_black.py +++ b/tests/test_black.py @@ -150,7 +150,7 @@ class BlackTestCase(unittest.TestCase): tmp_file = Path(black.dump_to_file(source)) try: self.assertTrue(ff(tmp_file, write_back=black.WriteBack.YES)) - with open(tmp_file) as f: + with open(tmp_file, encoding="utf8") as f: actual = f.read() finally: os.unlink(tmp_file) -- 2.39.5