Use Python 3.9 syntax in tests (#37343)
Signed-off-by: cyy <cyyever@outlook.com>
This commit is contained in:
@@ -239,7 +239,7 @@ class RobertaBertDummyModel:
|
||||
|
||||
|
||||
def replace_in_file(filename, old, new):
|
||||
with open(filename, "r", encoding="utf-8") as f:
|
||||
with open(filename, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
content = content.replace(old, new)
|
||||
@@ -328,7 +328,7 @@ class CopyCheckTester(unittest.TestCase):
|
||||
|
||||
_ = is_copy_consistent(file_to_check, overwrite=True)
|
||||
|
||||
with open(file_to_check, "r", encoding="utf-8") as f:
|
||||
with open(file_to_check, encoding="utf-8") as f:
|
||||
self.assertEqual(f.read(), MOCK_BERT_COPY_CODE)
|
||||
|
||||
def test_is_copy_consistent_with_ignored_match(self):
|
||||
@@ -364,7 +364,7 @@ class CopyCheckTester(unittest.TestCase):
|
||||
|
||||
_ = is_copy_consistent(file_to_check, overwrite=True)
|
||||
|
||||
with open(file_to_check, "r", encoding="utf-8") as f:
|
||||
with open(file_to_check, encoding="utf-8") as f:
|
||||
self.assertEqual(f.read(), EXPECTED_REPLACED_CODE)
|
||||
|
||||
def test_convert_to_localized_md(self):
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# coding=utf-8
|
||||
# Copyright 2023 The HuggingFace Inc. team.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
||||
@@ -646,9 +646,9 @@ src/transformers/configuration_utils.py
|
||||
|
||||
with patch_transformer_repo_path(tmp_folder):
|
||||
infer_tests_to_run(tmp_folder / "test-output.txt", diff_with_last_commit=True)
|
||||
with open(tmp_folder / "test-output.txt", "r") as f:
|
||||
with open(tmp_folder / "test-output.txt") as f:
|
||||
tests_to_run = f.read()
|
||||
with open(tmp_folder / "examples_test_list.txt", "r") as f:
|
||||
with open(tmp_folder / "examples_test_list.txt") as f:
|
||||
example_tests_to_run = f.read()
|
||||
|
||||
assert tests_to_run == "tests/models/bert/test_modeling_bert.py"
|
||||
@@ -687,9 +687,9 @@ src/transformers/configuration_utils.py
|
||||
|
||||
with patch_transformer_repo_path(tmp_folder):
|
||||
infer_tests_to_run(tmp_folder / "test-output.txt")
|
||||
with open(tmp_folder / "test-output.txt", "r") as f:
|
||||
with open(tmp_folder / "test-output.txt") as f:
|
||||
tests_to_run = f.read()
|
||||
with open(tmp_folder / "examples_test_list.txt", "r") as f:
|
||||
with open(tmp_folder / "examples_test_list.txt") as f:
|
||||
example_tests_to_run = f.read()
|
||||
|
||||
expected_tests = {
|
||||
@@ -703,9 +703,9 @@ src/transformers/configuration_utils.py
|
||||
|
||||
with patch_transformer_repo_path(tmp_folder):
|
||||
infer_tests_to_run(tmp_folder / "test-output.txt", filter_models=False)
|
||||
with open(tmp_folder / "test-output.txt", "r") as f:
|
||||
with open(tmp_folder / "test-output.txt") as f:
|
||||
tests_to_run = f.read()
|
||||
with open(tmp_folder / "examples_test_list.txt", "r") as f:
|
||||
with open(tmp_folder / "examples_test_list.txt") as f:
|
||||
example_tests_to_run = f.read()
|
||||
|
||||
expected_tests = [f"tests/models/{name}/test_modeling_{name}.py" for name in models + ["t5"]]
|
||||
@@ -728,7 +728,7 @@ src/transformers/configuration_utils.py
|
||||
|
||||
with patch_transformer_repo_path(tmp_folder):
|
||||
infer_tests_to_run(tmp_folder / "test-output.txt", diff_with_last_commit=True)
|
||||
with open(tmp_folder / "test-output.txt", "r") as f:
|
||||
with open(tmp_folder / "test-output.txt") as f:
|
||||
tests_to_run = f.read()
|
||||
|
||||
assert tests_to_run == "tests/models/bert/test_modeling_bert.py"
|
||||
@@ -749,7 +749,7 @@ src/transformers/configuration_utils.py
|
||||
|
||||
with patch_transformer_repo_path(tmp_folder):
|
||||
infer_tests_to_run(tmp_folder / "test-output.txt", diff_with_last_commit=True)
|
||||
with open(tmp_folder / "examples_test_list.txt", "r") as f:
|
||||
with open(tmp_folder / "examples_test_list.txt") as f:
|
||||
example_tests_to_run = f.read()
|
||||
|
||||
assert example_tests_to_run == "examples/pytorch/test_pytorch_examples.py"
|
||||
@@ -764,7 +764,7 @@ src/transformers/configuration_utils.py
|
||||
|
||||
with patch_transformer_repo_path(tmp_folder):
|
||||
infer_tests_to_run(tmp_folder / "test-output.txt", diff_with_last_commit=True)
|
||||
with open(tmp_folder / "examples_test_list.txt", "r") as f:
|
||||
with open(tmp_folder / "examples_test_list.txt") as f:
|
||||
example_tests_to_run = f.read()
|
||||
|
||||
assert example_tests_to_run == "examples/pytorch/test_pytorch_examples.py"
|
||||
|
||||
Reference in New Issue
Block a user