Skip to content

Commit

Permalink
Fix failing test on Windows Platform (huggingface#11589)
Browse files Browse the repository at this point in the history
* add separator for windows

* fixes test_is_copy_consistent on Windows

* fixing writing encoding issue on extended test (for Windows)

* resolving comments
  • Loading branch information
Lynx1820 authored May 20, 2021
1 parent f4a0d6f commit 2239438
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/pytorch/translation/run_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def compute_metrics(eval_preds):
)
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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tokenization_wav2vec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def test_save_pretrained(self):
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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils_check_copies.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def check_copy_consistency(self, comment, class_name, class_code, overwrite_resu
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)
Expand Down

0 comments on commit 2239438

Please sign in to comment.