From 223943872e8c9c3fc11db3c6e93da07f5177423f Mon Sep 17 00:00:00 2001 From: Keren Fuentes Date: Thu, 20 May 2021 16:54:23 -0700 Subject: [PATCH] Fix failing test on Windows Platform (#11589) * add separator for windows * fixes test_is_copy_consistent on Windows * fixing writing encoding issue on extended test (for Windows) * resolving comments --- examples/pytorch/translation/run_translation.py | 2 +- tests/test_tokenization_wav2vec2.py | 2 +- tests/test_utils_check_copies.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/pytorch/translation/run_translation.py b/examples/pytorch/translation/run_translation.py index 84181ab113..ed880b2e39 100755 --- a/examples/pytorch/translation/run_translation.py +++ b/examples/pytorch/translation/run_translation.py @@ -571,7 +571,7 @@ def main(): ) predictions = [pred.strip() for pred in predictions] output_prediction_file = os.path.join(training_args.output_dir, "generated_predictions.txt") - with open(output_prediction_file, "w") as writer: + with open(output_prediction_file, "w", encoding="utf-8") as writer: writer.write("\n".join(predictions)) if training_args.push_to_hub: diff --git a/tests/test_tokenization_wav2vec2.py b/tests/test_tokenization_wav2vec2.py index e5336f1f6a..db9d302200 100644 --- a/tests/test_tokenization_wav2vec2.py +++ b/tests/test_tokenization_wav2vec2.py @@ -231,7 +231,7 @@ class Wav2Vec2TokenizerTest(unittest.TestCase): tokenizer_files = tokenizer.save_pretrained(tmpdirname2) self.assertSequenceEqual( sorted(tuple(VOCAB_FILES_NAMES.values()) + ("special_tokens_map.json", "added_tokens.json")), - sorted(tuple(x.split("/")[-1] for x in tokenizer_files)), + sorted(tuple(x.split(os.path.sep)[-1] for x in tokenizer_files)), ) # Checks everything loads correctly in the same way diff --git a/tests/test_utils_check_copies.py b/tests/test_utils_check_copies.py index aaa407480d..067bd45efa 100644 --- a/tests/test_utils_check_copies.py +++ b/tests/test_utils_check_copies.py @@ -70,7 +70,7 @@ class CopyCheckTester(unittest.TestCase): expected = comment + f"\nclass {class_name}(nn.Module):\n" + overwrite_result code = black.format_str(code, mode=black.FileMode([black.TargetVersion.PY35], line_length=119)) fname = os.path.join(self.transformer_dir, "new_code.py") - with open(fname, "w") as f: + with open(fname, "w", newline="\n") as f: f.write(code) if overwrite_result is None: self.assertTrue(len(check_copies.is_copy_consistent(fname)) == 0)