From 02d1c1cdb3446ec5dd8a0267535338625dc59938 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Mon, 2 Jan 2023 23:57:38 +0530 Subject: [PATCH] MAINT: Appease linter --- asv/plugins/git.py | 2 +- test/conftest.py | 3 ++- test/test_benchmarks.py | 6 +++--- test/test_compare.py | 2 +- test/test_continuous.py | 2 +- test/test_environment.py | 2 +- test/test_find.py | 19 ++++++++++++------- test/test_gh_pages.py | 3 ++- test/test_publish.py | 7 +++++-- test/test_repo.py | 24 ++++++++++++++++-------- test/test_run.py | 3 ++- test/test_web.py | 3 ++- test/test_workflow.py | 5 ++--- test/tools.py | 2 +- 14 files changed, 51 insertions(+), 32 deletions(-) diff --git a/asv/plugins/git.py b/asv/plugins/git.py index 9393db20b..fae3af32f 100644 --- a/asv/plugins/git.py +++ b/asv/plugins/git.py @@ -26,7 +26,7 @@ def __init__(self, url, mirror_path): 'init.defaultBranch', ], display_error=False, cwd=None).strip() - except: + except util.ProcessError: self._default_branch = 'master' if self.is_local_repo(url): diff --git a/test/conftest.py b/test/conftest.py index 8620d3301..d625bc5f9 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -40,9 +40,10 @@ defaultBranch = util.check_output([util.which('git'), 'config', 'init.defaultBranch'], display_error=False).strip() -except: +except util.ProcessError: defaultBranch = 'master' + def pytest_addoption(parser): parser.addoption("--webdriver", action="store", default="None", help=("Selenium WebDriver interface to use for running the test. " diff --git a/test/test_benchmarks.py b/test/test_benchmarks.py index 99e0738ca..5433a1d8a 100644 --- a/test/test_benchmarks.py +++ b/test/test_benchmarks.py @@ -11,7 +11,6 @@ from asv import benchmarks, config, environment, util from asv.repo import get_repo -from asv import util from . import tools @@ -19,10 +18,11 @@ try: defaultBranch = util.check_output([util.which('git'), 'config', 'init.defaultBranch' - ],display_error=False).strip() -except: + ], display_error=False).strip() +except util.ProcessError: defaultBranch = 'master' + BENCHMARK_DIR = join(dirname(__file__), 'benchmark') INVALID_BENCHMARK_DIR = join( diff --git a/test/test_compare.py b/test/test_compare.py index d3f395aad..601f1c78e 100644 --- a/test/test_compare.py +++ b/test/test_compare.py @@ -215,7 +215,7 @@ def test_compare_name_lookup(dvcs_type, capsys, tmpdir, example_results): 'config', 'init.defaultBranch'], display_error=False).strip() - except: + except util.ProcessError: defaultBranch = 'master' branch_name = defaultBranch if dvcs_type == 'git' else 'default' diff --git a/test/test_continuous.py b/test/test_continuous.py index a7f9f9562..7351a6f05 100644 --- a/test/test_continuous.py +++ b/test/test_continuous.py @@ -15,7 +15,7 @@ 'config', 'init.defaultBranch'], display_error=False ).strip() -except: +except util.ProcessError: defaultBranch = 'master' diff --git a/test/test_environment.py b/test/test_environment.py index 625364b5d..569d92539 100644 --- a/test/test_environment.py +++ b/test/test_environment.py @@ -653,7 +653,7 @@ def test_build_isolation(tmpdir): defaultBranch = util.check_output([util.which('git'), 'config', 'init.defaultBranch'], display_error=False).strip() - except: + except util.ProcessError: defaultBranch = 'master' commit_hash = dvcs.get_hash(f"{defaultBranch}") diff --git a/test/test_find.py b/test/test_find.py index 91e2ae9e5..5abca9705 100644 --- a/test/test_find.py +++ b/test/test_find.py @@ -4,7 +4,7 @@ import pytest -from asv.util import check_output, which +from asv.util import check_output, which, ProcessError from . import tools from .conftest import generate_basic_conf @@ -13,12 +13,13 @@ # Variables try: - defaultBranch = util.check_output([util.which('git'), - 'config', 'init.defaultBranch'], - display_error=False).strip() -except: + defaultBranch = check_output([which('git'), + 'config', 'init.defaultBranch'], + display_error=False).strip() +except ProcessError: defaultBranch = 'master' + def test_find(capfd, tmpdir): values = [ (None, None), @@ -38,7 +39,9 @@ def test_find(capfd, tmpdir): dummy_packages=False) # Test find at least runs - tools.run_asv_with_conf(conf, 'find', f"{defaultBranch}~5..{defaultBranch}", "params_examples.track_find_test", + tools.run_asv_with_conf(conf, 'find', + f"{defaultBranch}~5..{defaultBranch}", + "params_examples.track_find_test", _machine_file=machine_file) # Check it found the first commit after the initially tested one @@ -63,7 +66,9 @@ def test_find_timeout(capfd, tmpdir): dummy_packages=False) # Test find at least runs - tools.run_asv_with_conf(conf, 'find', "-e", f"{defaultBranch}", "params_examples.time_find_test_timeout", + tools.run_asv_with_conf(conf, 'find', "-e", + f"{defaultBranch}", + "params_examples.time_find_test_timeout", _machine_file=machine_file) # Check it found the first commit after the initially tested one diff --git a/test/test_gh_pages.py b/test/test_gh_pages.py index d5dd7aa33..034f8fc97 100644 --- a/test/test_gh_pages.py +++ b/test/test_gh_pages.py @@ -12,9 +12,10 @@ defaultBranch = util.check_output([util.which('git'), 'config', 'init.defaultBranch'], display_error=False).strip() -except: +except util.ProcessError: defaultBranch = 'master' + @pytest.mark.parametrize("rewrite", [False, True], ids=["no-rewrite", "rewrite"]) def test_gh_pages(rewrite, tmpdir, generate_result_dir, monkeypatch): tmpdir = os.path.abspath(str(tmpdir)) diff --git a/test/test_publish.py b/test/test_publish.py index b2f995431..cfdc7f3fe 100644 --- a/test/test_publish.py +++ b/test/test_publish.py @@ -25,9 +25,10 @@ defaultBranch = util.check_output([util.which('git'), 'config', 'init.defaultBranch'], display_error=False).strip() -except: +except util.ProcessError: defaultBranch = 'master' + def test_publish(tmpdir, example_results): tmpdir = str(tmpdir) os.chdir(tmpdir) @@ -138,7 +139,9 @@ def check_file(branch, cython): 'os': 'Linux (Fedora 20)', 'python': '2.7', 'ram': '8.2G'} - for cython in ["", None] for branch in [f"{defaultBranch}", "some-branch"]] + for cython in ["", + None] for branch in [f"{defaultBranch}", + "some-branch"]] d = dict(expected_graph_list[0]) d['ram'] = 8804682956.8 expected_graph_list.append(d) diff --git a/test/test_repo.py b/test/test_repo.py index 4acb7ec01..eaf41b6cb 100644 --- a/test/test_repo.py +++ b/test/test_repo.py @@ -21,9 +21,10 @@ defaultBranch = util.check_output([util.which('git'), 'config', 'init.defaultBranch'], display_error=False).strip() -except: +except util.ProcessError: defaultBranch = 'master' + def _test_generic_repo(conf, tmpdir, hash_range, master, branch, is_remote=False): workcopy_dir = tempfile.mkdtemp(dir=tmpdir, prefix="workcopy") os.rmdir(workcopy_dir) @@ -98,8 +99,10 @@ def _test_branches(conf, branch_commits, require_describe=False): def test_repo_git(tmpdir): tmpdir = str(tmpdir) - dvcs = tools.generate_test_repo(tmpdir, list(range(10)), dvcs_type='git', - extra_branches=[(f'{defaultBranch}~4', 'some-branch', [11, 12, 13])]) + dvcs = tools.generate_test_repo(tmpdir, list(range(10)), + dvcs_type='git', + extra_branches=[(f'{defaultBranch}~4', + 'some-branch', [11, 12, 13])]) mirror_dir = join(tmpdir, "repo") @@ -114,8 +117,10 @@ def test_it(is_remote=False): conf.branches = [f'{defaultBranch}', 'some-branch'] branch_commits = { - f'{defaultBranch}': [dvcs.get_hash(f'{defaultBranch}'), dvcs.get_hash(f'{defaultBranch}~6')], - 'some-branch': [dvcs.get_hash('some-branch'), dvcs.get_hash('some-branch~6')] + f'{defaultBranch}': [dvcs.get_hash(f'{defaultBranch}'), + dvcs.get_hash(f'{defaultBranch}~6')], + 'some-branch': [dvcs.get_hash('some-branch'), + dvcs.get_hash('some-branch~6')] } _test_branches(conf, branch_commits, require_describe=True) @@ -271,14 +276,17 @@ def test_git_submodule(tmpdir): commit_hash_0 = dvcs.get_hash(f"{defaultBranch}") # State 1 (one submodule) - dvcs.run_git(['-c','protocol.file.allow=always', 'submodule', 'add', sub_dvcs.path, 'sub1']) + dvcs.run_git(['-c', 'protocol.file.allow=always', + 'submodule', 'add', sub_dvcs.path, 'sub1']) dvcs.commit('Add sub1') commit_hash_1 = dvcs.get_hash(f"{defaultBranch}") # State 2 (one submodule with sub-submodule) - dvcs.run_git(['-c','protocol.file.allow=always', 'submodule', 'update', '--init']) + dvcs.run_git(['-c', 'protocol.file.allow=always', + 'submodule', 'update', '--init']) sub1_dvcs = tools.Git(join(dvcs.path, 'sub1')) - sub_dvcs.run_git(['-c','protocol.file.allow=always', 'submodule', 'add', ssub_dvcs.path, 'ssub1']) + sub_dvcs.run_git(['-c', 'protocol.file.allow=always', + 'submodule', 'add', ssub_dvcs.path, 'ssub1']) sub_dvcs.commit('Add sub1') sub1_dvcs.run_git(['pull']) dvcs.run_git(['add', 'sub1']) diff --git a/test/test_run.py b/test/test_run.py index 4a8c669e3..b763bddb4 100644 --- a/test/test_run.py +++ b/test/test_run.py @@ -22,9 +22,10 @@ defaultBranch = util.check_output([util.which('git'), 'config', 'init.defaultBranch'], display_error=False).strip() -except: +except util.ProcessError: defaultBranch = 'master' + def test_set_commit_hash(capsys, existing_env_conf): tmpdir, local, conf, machine_file = existing_env_conf diff --git a/test/test_web.py b/test/test_web.py index 9127b2c8a..19b1a7ba9 100644 --- a/test/test_web.py +++ b/test/test_web.py @@ -26,9 +26,10 @@ defaultBranch = util.check_output([util.which('git'), 'config', 'init.defaultBranch', ], display_error=False).strip() -except: +except util.ProcessError: defaultBranch = 'master' + def _rebuild_basic_html(basedir): local = abspath(dirname(__file__)) cwd = os.getcwd() diff --git a/test/test_workflow.py b/test/test_workflow.py index 0e45e94b6..6fe75e941 100644 --- a/test/test_workflow.py +++ b/test/test_workflow.py @@ -12,16 +12,15 @@ from . import tools -from pathlib import Path - # Variables try: defaultBranch = util.check_output([util.which('git'), 'config', 'init.defaultBranch'], display_error=False).strip() -except: +except util.ProcessError: defaultBranch = 'master' + def test_run_publish(capfd, basic_conf_2): tmpdir, local, conf, machine_file = basic_conf_2 tmpdir = util.long_path(tmpdir) diff --git a/test/tools.py b/test/tools.py index 325f0fc6c..33079d480 100644 --- a/test/tools.py +++ b/test/tools.py @@ -213,7 +213,7 @@ def get_branch_hashes(self, branch=None): try: branch = self.run_git(["config", "init.defaultBranch"], display_error=False).strip() - except: + except util.ProcessError: branch = 'master' return [x.strip() for x in self.run_git(['rev-list', branch]).splitlines() if x.strip()]