From a597f1c7839928be820514921c786f442f1910e2 Mon Sep 17 00:00:00 2001 From: Usama Sadiq Date: Tue, 11 May 2021 15:19:48 +0500 Subject: [PATCH] refactor: ran pyupgrade second iteration (#27463) --- pavelib/paver_tests/test_assets.py | 12 ++++++------ pavelib/paver_tests/test_extract_and_generate.py | 2 +- scripts/show_events.py | 2 +- scripts/xblock/xblock_counts.py | 2 +- scripts/xdist/find_order_dependent_test_failures.py | 6 +++--- scripts/xdist/get_worker_test_list.py | 2 +- scripts/xdist/pytest_worker_manager.py | 2 +- scripts/xsslint/xsslint/linters.py | 2 +- scripts/xsslint/xsslint/reporting.py | 2 +- scripts/xsslint/xsslint/utils.py | 2 +- 10 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pavelib/paver_tests/test_assets.py b/pavelib/paver_tests/test_assets.py index 608c5cdece..5722b20624 100644 --- a/pavelib/paver_tests/test_assets.py +++ b/pavelib/paver_tests/test_assets.py @@ -131,7 +131,7 @@ class TestPaverThemeAssetTasks(PaverTestCase): expected_messages.append('mkdir_p ' + repr(TEST_THEME_DIR / 'lms/static/css')) if force: expected_messages.append( - 'rm -rf {test_theme_dir}/lms/static/css/*.css'.format(test_theme_dir=str(TEST_THEME_DIR)) + f'rm -rf {str(TEST_THEME_DIR)}/lms/static/css/*.css' ) expected_messages.append("libsass lms/static/sass") expected_messages.append( @@ -148,10 +148,10 @@ class TestPaverThemeAssetTasks(PaverTestCase): ) if force: expected_messages.append( - 'rm -rf {test_theme_dir}/lms/static/css/*.css'.format(test_theme_dir=str(TEST_THEME_DIR)) + f'rm -rf {str(TEST_THEME_DIR)}/lms/static/css/*.css' ) expected_messages.append( - 'libsass {test_theme_dir}/lms/static/sass'.format(test_theme_dir=str(TEST_THEME_DIR)) + f'libsass {str(TEST_THEME_DIR)}/lms/static/sass' ) if force: expected_messages.append('rm -rf lms/static/css/*.css') @@ -171,7 +171,7 @@ class TestPaverThemeAssetTasks(PaverTestCase): expected_messages.append('mkdir_p ' + repr(TEST_THEME_DIR / 'cms/static/css')) if force: expected_messages.append( - 'rm -rf {test_theme_dir}/cms/static/css/*.css'.format(test_theme_dir=str(TEST_THEME_DIR)) + f'rm -rf {str(TEST_THEME_DIR)}/cms/static/css/*.css' ) expected_messages.append('libsass cms/static/sass') expected_messages.append( @@ -182,10 +182,10 @@ class TestPaverThemeAssetTasks(PaverTestCase): ) if force: expected_messages.append( - 'rm -rf {test_theme_dir}/cms/static/css/*.css'.format(test_theme_dir=str(TEST_THEME_DIR)) + f'rm -rf {str(TEST_THEME_DIR)}/cms/static/css/*.css' ) expected_messages.append( - 'libsass {test_theme_dir}/cms/static/sass'.format(test_theme_dir=str(TEST_THEME_DIR)) + f'libsass {str(TEST_THEME_DIR)}/cms/static/sass' ) if force: expected_messages.append('rm -rf cms/static/css/*.css') diff --git a/pavelib/paver_tests/test_extract_and_generate.py b/pavelib/paver_tests/test_extract_and_generate.py index da52c496ba..c64f24c17c 100644 --- a/pavelib/paver_tests/test_extract_and_generate.py +++ b/pavelib/paver_tests/test_extract_and_generate.py @@ -109,7 +109,7 @@ class TestGenerate(TestCase): pof = pofile(path) pattern = re.compile('^#-#-#-#-#', re.M) match = pattern.findall(pof.header) - assert len(match) == 3, ('Found {} (should be 3) merge comments in the header for {}'.format(len(match), path)) + assert len(match) == 3, (f'Found {len(match)} (should be 3) merge comments in the header for {path}') def random_name(size=6): diff --git a/scripts/show_events.py b/scripts/show_events.py index 06be6f57e2..d1bf34d593 100644 --- a/scripts/show_events.py +++ b/scripts/show_events.py @@ -24,7 +24,7 @@ def display(message): # lint-amnesty, pylint: disable=missing-function-docstrin if message.get('event'): event = json.loads(message['event']) for k in sorted(event): - print('\t{}: {}'.format(k, event[k])) + print(f'\t{k}: {event[k]}') print() while 1: diff --git a/scripts/xblock/xblock_counts.py b/scripts/xblock/xblock_counts.py index 1514a99f4f..64a4acc207 100644 --- a/scripts/xblock/xblock_counts.py +++ b/scripts/xblock/xblock_counts.py @@ -383,4 +383,4 @@ if __name__ == "__main__": if len(course_data) > 0: write_block_summary_report(course_data) write_course_block_detail_report(course_data) - print('Start time: {} Total run time: {}'.format(str(start_time), str(datetime.now() - start_time))) + print(f'Start time: {str(start_time)} Total run time: {str(datetime.now() - start_time)}') diff --git a/scripts/xdist/find_order_dependent_test_failures.py b/scripts/xdist/find_order_dependent_test_failures.py index 644ec0d4d5..5646f6d52b 100644 --- a/scripts/xdist/find_order_dependent_test_failures.py +++ b/scripts/xdist/find_order_dependent_test_failures.py @@ -77,7 +77,7 @@ def main(log_file, test_suite, fast, verbose): test_list_with_failures, pytest_command = _find_fewest_tests_with_failures(failing_test_list, 'ALL') if test_list_with_failures: - print('Found failures running {} tests.'.format(len(test_list_with_failures))) + print(f'Found failures running {len(test_list_with_failures)} tests.') print(f'Use: {pytest_command}') return @@ -102,7 +102,7 @@ def _strip_console_for_tests_with_failure(log_file, test_suite): worker_test_dict = {} test_base_included = {} failing_worker_num = None - with open(log_file, 'r') as console_file: + with open(log_file) as console_file: for line in console_file: regex_search = re.search(fr'\[gw(\d+)] (PASSED|FAILED|SKIPPED|ERROR) (\S+)', line) if regex_search: @@ -159,7 +159,7 @@ def _create_and_check_test_files_for_failures(test_list, test_type): Returns the pytest command to run if failures are found. """ - print("Testing {}, includes {} test(s)...".format(test_type, len(test_list))) + print(f"Testing {test_type}, includes {len(test_list)} test(s)...") global test_suite_option output_file_name = "{}_failing_test_list_{}_{}.txt".format( OUTPUT_FOLDER_NAME, test_suite_option, test_type, len(test_list) diff --git a/scripts/xdist/get_worker_test_list.py b/scripts/xdist/get_worker_test_list.py index b365782a33..73910489c6 100644 --- a/scripts/xdist/get_worker_test_list.py +++ b/scripts/xdist/get_worker_test_list.py @@ -30,7 +30,7 @@ import click ) def main(log_file, test_suite): worker_test_dict = {} - with open(log_file, 'r') as console_file: + with open(log_file) as console_file: for line in console_file: regex_search = re.search(fr'\[gw(\d+)] (PASSED|FAILED|SKIPPED|ERROR) (\S+)', line) if regex_search: diff --git a/scripts/xdist/pytest_worker_manager.py b/scripts/xdist/pytest_worker_manager.py index 9a6872ecb7..c63b684cfc 100644 --- a/scripts/xdist/pytest_worker_manager.py +++ b/scripts/xdist/pytest_worker_manager.py @@ -100,7 +100,7 @@ class PytestWorkerManager(): not_running.append(instance_info['InstanceId']) if len(not_running) > 0: - logger.info("Still waiting on {} workers to spin up".format(len(not_running))) + logger.info(f"Still waiting on {len(not_running)} workers to spin up") time.sleep(5) else: logger.info("Finished spinning up workers") diff --git a/scripts/xsslint/xsslint/linters.py b/scripts/xsslint/xsslint/linters.py index 6274f9cec5..a73e805dac 100644 --- a/scripts/xsslint/xsslint/linters.py +++ b/scripts/xsslint/xsslint/linters.py @@ -53,7 +53,7 @@ class BaseLinter: A string containing the files contents. """ - with open(file_full_path, 'r') as input_file: + with open(file_full_path) as input_file: file_contents = input_file.read() return file_contents diff --git a/scripts/xsslint/xsslint/reporting.py b/scripts/xsslint/xsslint/reporting.py index 05a08647f7..8d85de76c5 100644 --- a/scripts/xsslint/xsslint/reporting.py +++ b/scripts/xsslint/xsslint/reporting.py @@ -289,7 +289,7 @@ class SummaryResults: print("", file=out) for rule_id in sorted(self.totals_by_rule.keys()): padding = " " * (max_rule_id_len - len(rule_id)) - print("{}: {}{} violations".format(rule_id, padding, self.totals_by_rule[rule_id]), file=out) + print(f"{rule_id}: {padding}{self.totals_by_rule[rule_id]} violations", file=out) print("", file=out) # matches output of eslint for simplicity diff --git a/scripts/xsslint/xsslint/utils.py b/scripts/xsslint/xsslint/utils.py index 3e311fd2e2..d7e6e73af0 100644 --- a/scripts/xsslint/xsslint/utils.py +++ b/scripts/xsslint/xsslint/utils.py @@ -20,7 +20,7 @@ def is_skip_dir(skip_dirs, directory): """ for skip_dir in skip_dirs: skip_dir_regex = re.compile( - "(.*/)*{}(/.*)*".format(re.escape(skip_dir))) + f"(.*/)*{re.escape(skip_dir)}(/.*)*") if skip_dir_regex.match(directory) is not None: return True return False