diff --git a/asv/commands/publish.py b/asv/commands/publish.py index e5eb0bce5..9e84b0cc2 100644 --- a/asv/commands/publish.py +++ b/asv/commands/publish.py @@ -172,11 +172,18 @@ def copy_ignore(src, names): branches_for_commit = [branch for branch, commits in branches.items() if results.commit_hash in commits] - # Print a warning message if we couldn't find the branch of a commit + # Print a warning message if the commit isn't from a tag if not len(branches_for_commit): - msg = "Couldn't find {} in branches ({})" - log.warning(msg.format(results.commit_hash[:conf.hash_length], - ", ".join(str(branch) for branch in branches.keys()))) + # Assume that these must be tags + repo_tags = repo.get_tags() + branches_for_commit = [branch for branch, commits in branches.items() if + results.commit_hash in repo_tags.values()] + if not len(branches_for_commit): + # Not tags, print a warning + msg = "Couldn't find {} in branches ({})" + log.warning(msg.format(results.commit_hash[:conf.hash_length], + ", ".join(str(branch) for + branch in branches.keys()))) for key in results.get_result_keys(benchmarks): b = benchmarks[key] diff --git a/asv/plugins/git.py b/asv/plugins/git.py index 3d77db871..101e93af2 100644 --- a/asv/plugins/git.py +++ b/asv/plugins/git.py @@ -15,12 +15,19 @@ class Git(Repo): dvcs = "git" - _default_branch = "master" def __init__(self, url, mirror_path): self._git = util.which("git") self._path = os.path.abspath(mirror_path) self._pulled = False + # default branch + try: + self._default_branch = self._run_git(['config', + 'init.defaultBranch', + ], display_error=False, + cwd=None).strip() + except util.ProcessError: + self._default_branch = 'master' if self.is_local_repo(url): # Local repository, no need for mirror @@ -87,13 +94,15 @@ def pull(self): def checkout(self, path, commit_hash): def checkout_existing(display_error): # Deinit fails if no submodules, so ignore its failure - self._run_git(['-c','protocol.file.allow=always', 'submodule', 'deinit', '-f', '.'], + self._run_git(['-c', 'protocol.file.allow=always', + 'submodule', 'deinit', '-f', '.'], cwd=path, display_error=False, valid_return_codes=None) self._run_git(['checkout', '-f', commit_hash], cwd=path, display_error=display_error) self._run_git(['clean', '-fdx'], cwd=path, display_error=display_error) - self._run_git(['-c','protocol.file.allow=always', 'submodule', 'update', '--init', '--recursive'], + self._run_git(['-c', 'protocol.file.allow=always', + 'submodule', 'update', '--init', '--recursive'], cwd=path, display_error=display_error) if os.path.isdir(path): @@ -161,7 +170,7 @@ def get_name_from_hash(self, commit): def get_tags(self): tags = {} - for tag in self._run_git(["tag", "-l"]).splitlines(): + for tag in self._run_git(["tag", "-l", "--sort=taggerdate"]).splitlines(): tags[tag] = self._run_git(["rev-list", "-n", "1", tag]).strip() return tags diff --git a/setup.cfg b/setup.cfg index a5e86269e..9c8c67699 100644 --- a/setup.cfg +++ b/setup.cfg @@ -62,8 +62,10 @@ addopts=-p no:logging [flake8] max-line-length = 99 ignore = - W504, # W504: Line break occurred after a binary operator - E741 # E741: Do not use variables named 'I', 'O', or 'l' +# W504: Line break occurred after a binary operator + W504, +# E741: Do not use variables named 'I', 'O', or 'l' + E741 exclude = asv/extern [isort] diff --git a/test/conftest.py b/test/conftest.py index fa85c97ac..d625bc5f9 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -8,7 +8,7 @@ import pytest import selenium -from asv import config, environment, repo, step_detect +from asv import config, environment, repo, step_detect, util from asv.repo import get_repo from asv.step_detect import L1Dist @@ -29,13 +29,20 @@ except ImportError: HAVE_RANGEMEDIAN = False - DUMMY_VALUES = ( (6, 1), (6, 6), (6, 6), ) +# Variables +try: + defaultBranch = util.check_output([util.which('git'), + 'config', 'init.defaultBranch'], + display_error=False).strip() +except util.ProcessError: + defaultBranch = 'master' + def pytest_addoption(parser): parser.addoption("--webdriver", action="store", default="None", @@ -166,7 +173,7 @@ def two_branch_repo_case(request, tmpdir): dvcs_type = request.param tmpdir = str(tmpdir) if dvcs_type == "git": - master = "master" + master = f"{defaultBranch}" elif dvcs_type == "hg": master = "default" dvcs = tools.generate_repo_from_ops(tmpdir, dvcs_type, [ diff --git a/test/test_benchmarks.py b/test/test_benchmarks.py index 633cc0160..5433a1d8a 100644 --- a/test/test_benchmarks.py +++ b/test/test_benchmarks.py @@ -14,6 +14,15 @@ from . import tools +# Variables +try: + defaultBranch = util.check_output([util.which('git'), + 'config', 'init.defaultBranch' + ], display_error=False).strip() +except util.ProcessError: + defaultBranch = 'master' + + BENCHMARK_DIR = join(dirname(__file__), 'benchmark') INVALID_BENCHMARK_DIR = join( @@ -38,7 +47,7 @@ def test_discover_benchmarks(benchmarks_fixture): assert len(b) == 6 old_branches = conf.branches - conf.branches = ["master", "some-missing-branch"] # missing branches ignored + conf.branches = [f"{defaultBranch}", "some-missing-branch"] # missing branches ignored b = benchmarks.Benchmarks.discover(conf, repo, envs, [commit_hash], regex='example') conf.branches = old_branches diff --git a/test/test_compare.py b/test/test_compare.py index 5269b8491..601f1c78e 100644 --- a/test/test_compare.py +++ b/test/test_compare.py @@ -208,7 +208,17 @@ def test_compare_name_lookup(dvcs_type, capsys, tmpdir, example_results): os.chdir(tmpdir) repo = tools.generate_test_repo(tmpdir, dvcs_type=dvcs_type) - branch_name = 'master' if dvcs_type == 'git' else 'default' + + # Variables + try: + defaultBranch = util.check_output([util.which('git'), + 'config', + 'init.defaultBranch'], + display_error=False).strip() + except util.ProcessError: + defaultBranch = 'master' + + branch_name = defaultBranch if dvcs_type == 'git' else 'default' commit_hash = repo.get_branch_hashes(branch_name)[0] result_dir = os.path.join(tmpdir, 'results') diff --git a/test/test_continuous.py b/test/test_continuous.py index f1f0a1f24..f229ca50b 100644 --- a/test/test_continuous.py +++ b/test/test_continuous.py @@ -4,10 +4,20 @@ import re from asv.results import iter_results_for_machine +from asv import util from . import tools from .tools import get_default_environment_type +# Variables +try: + defaultBranch = util.check_output([util.which('git'), + 'config', 'init.defaultBranch'], + display_error=False + ).strip() +except util.ProcessError: + defaultBranch = 'master' + def test_continuous(capfd, basic_conf_2): tmpdir, local, conf, machine_file = basic_conf_2 @@ -17,7 +27,7 @@ def test_continuous(capfd, basic_conf_2): env_spec = ("-E", env_type + ":" + python) # Check that asv continuous runs - tools.run_asv_with_conf(conf, 'continuous', "master^", '--show-stderr', + tools.run_asv_with_conf(conf, 'continuous', f"{defaultBranch}^", '--show-stderr', '--bench=params_examples.track_find_test', '--bench=params_examples.track_param', '--bench=time_examples.TimeSuite.time_example_benchmark_1', diff --git a/test/test_environment.py b/test/test_environment.py index 80863836c..569d92539 100644 --- a/test/test_environment.py +++ b/test/test_environment.py @@ -648,7 +648,15 @@ def test_build_isolation(tmpdir): 'requires = ["wheel", "setuptools"]') dvcs.add(fn) dvcs.commit("Add pyproject.toml") - commit_hash = dvcs.get_hash("master") + # Variables + try: + defaultBranch = util.check_output([util.which('git'), + 'config', 'init.defaultBranch'], + display_error=False).strip() + except util.ProcessError: + defaultBranch = 'master' + + commit_hash = dvcs.get_hash(f"{defaultBranch}") # Setup config conf = config.Config() diff --git a/test/test_find.py b/test/test_find.py index 59da87813..5abca9705 100644 --- a/test/test_find.py +++ b/test/test_find.py @@ -4,13 +4,21 @@ 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 WIN = (os.name == 'nt') +# Variables +try: + defaultBranch = check_output([which('git'), + 'config', 'init.defaultBranch'], + display_error=False).strip() +except ProcessError: + defaultBranch = 'master' + def test_find(capfd, tmpdir): values = [ @@ -31,14 +39,16 @@ def test_find(capfd, tmpdir): dummy_packages=False) # Test find at least runs - tools.run_asv_with_conf(conf, 'find', "master~5..master", "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 output, err = capfd.readouterr() regression_hash = check_output( - [which('git'), 'rev-parse', 'master^'], cwd=conf.repo) + [which('git'), 'rev-parse', f'{defaultBranch}^'], cwd=conf.repo) assert "Greatest regression found: {0}".format(regression_hash[:8]) in output @@ -56,14 +66,16 @@ def test_find_timeout(capfd, tmpdir): dummy_packages=False) # Test find at least runs - tools.run_asv_with_conf(conf, 'find', "-e", "master", "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 output, err = capfd.readouterr() regression_hash = check_output( - [which('git'), 'rev-parse', 'master'], cwd=conf.repo) + [which('git'), 'rev-parse', f'{defaultBranch}'], cwd=conf.repo) assert "Greatest regression found: {0}".format(regression_hash[:8]) in output assert "asv: benchmark timed out (timeout 1.0s)" in output @@ -82,14 +94,14 @@ def test_find_inverted(capfd, tmpdir): values=values, dummy_packages=False) tools.run_asv_with_conf(*[conf, 'find', - "-i", "master~4..master", + "-i", f"{defaultBranch}~4..{defaultBranch}", "params_examples.track_find_test"], _machine_file=machine_file) output, err = capfd.readouterr() regression_hash = check_output( - [which('git'), 'rev-parse', 'master^'], cwd=conf.repo) + [which('git'), 'rev-parse', f'{defaultBranch}^'], cwd=conf.repo) formatted = "Greatest improvement found: {0}".format(regression_hash[:8]) assert formatted in output diff --git a/test/test_gh_pages.py b/test/test_gh_pages.py index 81c64c4c1..034f8fc97 100644 --- a/test/test_gh_pages.py +++ b/test/test_gh_pages.py @@ -3,10 +3,18 @@ import pytest -import asv.util +from asv import util from . import tools +# Variables +try: + defaultBranch = util.check_output([util.which('git'), + 'config', 'init.defaultBranch'], + display_error=False).strip() +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): @@ -43,7 +51,7 @@ def test_gh_pages(rewrite, tmpdir, generate_result_dir, monkeypatch): dvcs.checkout('gh-pages') assert os.path.isfile(os.path.join(dvcs_dir, 'index.html')) assert len(dvcs.run_git(['rev-list', 'gh-pages']).splitlines()) == 1 - dvcs.checkout('master') + dvcs.checkout(f"{defaultBranch}") assert not os.path.isfile(os.path.join(dvcs_dir, 'index.html')) # Check with existing (and checked out) gh-pages branch, with no changes @@ -55,13 +63,13 @@ def test_gh_pages(rewrite, tmpdir, generate_result_dir, monkeypatch): else: # Timestamp may have changed assert len(dvcs.run_git(['rev-list', 'gh-pages']).splitlines()) <= 2 - dvcs.checkout('master') + dvcs.checkout(f"{defaultBranch}") # Check with existing (not checked out) gh-pages branch, with some changes benchmarks_json = os.path.join(conf.results_dir, 'benchmarks.json') - data = asv.util.load_json(benchmarks_json) + data = util.load_json(benchmarks_json) data['time_func']['pretty_name'] = 'something changed' - asv.util.write_json(benchmarks_json, data) + util.write_json(benchmarks_json, data) prev_len = len(dvcs.run_git(['rev-list', 'gh-pages']).splitlines()) tools.run_asv_with_conf(conf, "gh-pages", "--no-push", *rewrite_args) diff --git a/test/test_publish.py b/test/test_publish.py index d2113fc1b..cfdc7f3fe 100644 --- a/test/test_publish.py +++ b/test/test_publish.py @@ -20,6 +20,14 @@ BENCHMARK_DIR = abspath(join(dirname(__file__), 'benchmark')) +# Variables +try: + defaultBranch = util.check_output([util.which('git'), + 'config', 'init.defaultBranch'], + display_error=False).strip() +except util.ProcessError: + defaultBranch = 'master' + def test_publish(tmpdir, example_results): tmpdir = str(tmpdir) @@ -36,11 +44,11 @@ def test_publish(tmpdir, example_results): master_values = list(range(len(result_files) * 2 // 3)) branch_values = list(range(len(master_values), len(result_files))) dvcs = tools.generate_test_repo(tmpdir, master_values, 'git', - [('master~6', 'some-branch', branch_values)]) + [(f'{defaultBranch}~6', 'some-branch', branch_values)]) # Copy and modify result files, fixing commit hashes and setting result # dates to distinguish the two branches - master_commits = dvcs.get_branch_hashes('master') + master_commits = dvcs.get_branch_hashes(f'{defaultBranch}') only_branch = [x for x in dvcs.get_branch_hashes('some-branch') if x not in master_commits] commits = master_commits + only_branch @@ -82,7 +90,7 @@ def test_publish(tmpdir, example_results): assert not isdir(join(tmpdir, 'html', 'graphs', 'Cython-null', 'arch-x86_64', 'branch-some-branch')) index = util.load_json(join(tmpdir, 'html', 'index.json')) - assert index['params']['branch'] == ['master'] + assert index['params']['branch'] == [f'{defaultBranch}'] repo = get_repo(conf) revision_to_hash = dict((r, h) for h, r in repo.get_revisions(commits).items()) @@ -94,7 +102,7 @@ def check_file(branch, cython): 'time_coordinates.time_latitude.json') data = util.load_json(fn) data_commits = [revision_to_hash[x[0]] for x in data] - if branch == "master": + if branch == f'{defaultBranch}': assert all(c in master_commits for c in data_commits) else: # Must contains commits from some-branch @@ -105,21 +113,21 @@ def check_file(branch, cython): # Check that revisions are strictly increasing assert all(x[0] < y[0] for x, y in zip(data, data[1:])) - check_file("master", "Cython") - check_file("master", "Cython-null") + check_file(f"{defaultBranch}", "Cython") + check_file(f"{defaultBranch}", "Cython-null") # Publish with branches set in the config - conf.branches = ['master', 'some-branch'] + conf.branches = [f'{defaultBranch}', 'some-branch'] tools.run_asv_with_conf(conf, 'publish') # Check output - check_file("master", "Cython") - check_file("master", "Cython-null") + check_file(f"{defaultBranch}", "Cython") + check_file(f"{defaultBranch}", "Cython-null") check_file("some-branch", "Cython") check_file("some-branch", "Cython-null") index = util.load_json(join(tmpdir, 'html', 'index.json')) - assert index['params']['branch'] == ['master', 'some-branch'] + assert index['params']['branch'] == [f'{defaultBranch}', 'some-branch'] assert index['params']['Cython'] == ['', None] assert index['params']['ram'] == ['8.2G', 8804682956.8] @@ -131,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 ["master", "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) @@ -143,7 +153,7 @@ def check_file(branch, cython): def _graph_path(dvcs_type): if dvcs_type == "git": - master = "master" + master = f"{defaultBranch}" elif dvcs_type == "hg": master = "default" return join("graphs", "branch-{0}".format(master), "machine-tarzan", "time_func.json") @@ -252,7 +262,7 @@ def test_regression_parameterized(generate_result_dir): def test_regression_multiple_branches(dvcs_type, tmpdir): tmpdir = str(tmpdir) if dvcs_type == "git": - master = "master" + master = f"{defaultBranch}" elif dvcs_type == "hg": master = "default" dvcs = tools.generate_repo_from_ops( diff --git a/test/test_repo.py b/test/test_repo.py index 9726a69c3..eaf41b6cb 100644 --- a/test/test_repo.py +++ b/test/test_repo.py @@ -16,6 +16,14 @@ from . import tools +# Variables +try: + defaultBranch = util.check_output([util.which('git'), + 'config', 'init.defaultBranch'], + display_error=False).strip() +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") @@ -91,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=[('master~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") @@ -101,13 +111,16 @@ def test_it(is_remote=False): conf.project = mirror_dir conf.repo = dvcs.path - _test_generic_repo(conf, tmpdir, 'master~4..master', 'master', 'tag5', + _test_generic_repo(conf, tmpdir, f'{defaultBranch}~4..{defaultBranch}', + f'{defaultBranch}', 'tag5', is_remote=is_remote) - conf.branches = ['master', 'some-branch'] + conf.branches = [f'{defaultBranch}', 'some-branch'] branch_commits = { - 'master': [dvcs.get_hash('master'), dvcs.get_hash('master~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) @@ -260,23 +273,26 @@ def test_git_submodule(tmpdir): dvcs = tools.generate_test_repo(tmpdir, values=[0], dvcs_type='git') sub_dvcs = tools.generate_test_repo(tmpdir, values=[0], dvcs_type='git') ssub_dvcs = tools.generate_test_repo(tmpdir, values=[0], dvcs_type='git') - commit_hash_0 = dvcs.get_hash("master") + 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("master") + 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']) dvcs.commit('Update sub1') - sub1_hash_2 = sub1_dvcs.get_hash("master") - commit_hash_2 = dvcs.get_hash("master") + sub1_hash_2 = sub1_dvcs.get_hash(f"{defaultBranch}") + commit_hash_2 = dvcs.get_hash(f"{defaultBranch}") # State 3 (one submodule; sub-submodule removed) sub_dvcs.run_git(['rm', '-f', 'ssub1']) @@ -284,18 +300,18 @@ def test_git_submodule(tmpdir): sub1_dvcs.run_git(['pull']) dvcs.run_git(['add', 'sub1']) dvcs.commit('Update sub1 again') - commit_hash_3 = dvcs.get_hash("master") + commit_hash_3 = dvcs.get_hash(f"{defaultBranch}") # State 4 (back to one submodule with sub-submodule) sub1_dvcs.run_git(['checkout', sub1_hash_2]) dvcs.run_git(['add', 'sub1']) dvcs.commit('Update sub1 3rd time') - commit_hash_4 = dvcs.get_hash("master") + commit_hash_4 = dvcs.get_hash(f"{defaultBranch}") # State 5 (remove final submodule) dvcs.run_git(['rm', '-f', 'sub1']) dvcs.commit('Remove sub1') - commit_hash_5 = dvcs.get_hash("master") + commit_hash_5 = dvcs.get_hash(f"{defaultBranch}") # Verify clean operation conf = config.Config() conf.branches = [None] diff --git a/test/test_run.py b/test/test_run.py index 294905d85..b763bddb4 100644 --- a/test/test_run.py +++ b/test/test_run.py @@ -17,6 +17,14 @@ from . import tools from .tools import WIN +# Variables +try: + defaultBranch = util.check_output([util.which('git'), + 'config', 'init.defaultBranch'], + display_error=False).strip() +except util.ProcessError: + defaultBranch = 'master' + def test_set_commit_hash(capsys, existing_env_conf): tmpdir, local, conf, machine_file = existing_env_conf @@ -40,14 +48,14 @@ def test_run_spec(basic_conf_2): tmpdir, local, conf, machine_file = basic_conf_2 conf.build_cache_size = 5 - extra_branches = [('master~1', 'some-branch', [12])] + extra_branches = [(f'{defaultBranch}~1', 'some-branch', [12])] dvcs_path = os.path.join(tmpdir, 'test_repo2') dvcs = tools.generate_test_repo(dvcs_path, [1, 2], extra_branches=extra_branches) conf.repo = dvcs.path - initial_commit = dvcs.get_hash("master~1") - master_commit = dvcs.get_hash("master") + initial_commit = dvcs.get_hash(f"{defaultBranch}~1") + master_commit = dvcs.get_hash(f"{defaultBranch}") branch_commit = dvcs.get_hash("some-branch") template_dir = os.path.join(tmpdir, "results_workflow_template") results_dir = os.path.join(tmpdir, 'results_workflow') @@ -96,7 +104,7 @@ def _test_run(range_spec, branches, expected_commits): (["some-branch"], [initial_commit, branch_commit]), # With two branch in config, should apply to specified branches - (["master", "some-branch"], [initial_commit, master_commit, branch_commit]), + ([f"{defaultBranch}", "some-branch"], [initial_commit, master_commit, branch_commit]), ): for range_spec in (None, "NEW", "ALL"): _test_run(range_spec, branches, expected_commits) @@ -106,9 +114,9 @@ def _test_run(range_spec, branches, expected_commits): with open(os.path.join(tmpdir, 'hashes_to_benchmark'), 'w') as f: for commit in expected_commits: f.write(commit + "\n") - f.write("master~1\n") + f.write(f"{defaultBranch}~1\n") f.write("some-bad-hash-that-will-be-ignored\n") - expected_commits += (dvcs.get_hash("master~1"),) + expected_commits += (dvcs.get_hash(f"{defaultBranch}~1"),) _test_run('HASHFILE:hashes_to_benchmark', [None], expected_commits) diff --git a/test/test_web.py b/test/test_web.py index 91b2afc23..19b1a7ba9 100644 --- a/test/test_web.py +++ b/test/test_web.py @@ -21,6 +21,14 @@ from . import tools from .tools import get_with_retry, WAIT_TIME, WIN +# Variables +try: + defaultBranch = util.check_output([util.which('git'), + 'config', 'init.defaultBranch', + ], display_error=False).strip() +except util.ProcessError: + defaultBranch = 'master' + def _rebuild_basic_html(basedir): local = abspath(dirname(__file__)) @@ -44,7 +52,7 @@ def _rebuild_basic_html(basedir): 3, 3, 3, 3, 3, 2, 2, 2, 2, 2]] dvcs = tools.generate_test_repo(basedir, values) - first_tested_commit_hash = dvcs.get_hash('master~14') + first_tested_commit_hash = dvcs.get_hash(f'{defaultBranch}~14') repo_path = dvcs.path shutil.move(repo_path, join(basedir, 'repo')) @@ -86,7 +94,7 @@ def _rebuild_basic_html(basedir): util.write_json(machine_file, info, api_version=1) - tools.run_asv_with_conf(conf, 'run', 'master~10..', '--steps=3', + tools.run_asv_with_conf(conf, 'run', f'{defaultBranch}~10..', '--steps=3', '--show-stderr', '--quick', '--bench=params_examples[a-z0-9_.]*track_', _machine_file=machine_file) @@ -157,7 +165,7 @@ def check(*args): def test_web_regressions(browser, basic_html): html_dir, dvcs = basic_html - bad_commit_hash = dvcs.get_hash('master~9') + bad_commit_hash = dvcs.get_hash(f'{defaultBranch}~9') ignore_exc = (NoSuchElementException, StaleElementReferenceException) @@ -286,7 +294,7 @@ def test_web_summarylist(browser, basic_html): html_dir, dvcs = basic_html - last_change_hash = dvcs.get_hash('master~4') + last_change_hash = dvcs.get_hash(f'{defaultBranch}~4') browser.set_window_size(1200, 900) diff --git a/test/test_workflow.py b/test/test_workflow.py index c0aa9e13f..6fe75e941 100644 --- a/test/test_workflow.py +++ b/test/test_workflow.py @@ -12,6 +12,14 @@ from . import tools +# Variables +try: + defaultBranch = util.check_output([util.which('git'), + 'config', 'init.defaultBranch'], + display_error=False).strip() +except util.ProcessError: + defaultBranch = 'master' + def test_run_publish(capfd, basic_conf_2): tmpdir, local, conf, machine_file = basic_conf_2 @@ -23,7 +31,7 @@ def test_run_publish(capfd, basic_conf_2): } # Tests a typical complete run/publish workflow - ret = tools.run_asv_with_conf(conf, 'run', "master", '--steps=2', + ret = tools.run_asv_with_conf(conf, 'run', f"{defaultBranch}", '--steps=2', '--quick', '--show-stderr', '--profile', '-a', 'warmup_time=0', '--durations=5', @@ -65,12 +73,12 @@ def test_run_publish(capfd, basic_conf_2): # Check that the skip options work capfd.readouterr() - tools.run_asv_with_conf(conf, 'run', "master", '--steps=2', + tools.run_asv_with_conf(conf, 'run', f"{defaultBranch}", '--steps=2', '--quick', '--skip-existing-successful', '--bench=time_secondary.track_value', '--skip-existing-failed', _machine_file=join(tmpdir, 'asv-machine.json')) - tools.run_asv_with_conf(conf, 'run', "master", '--steps=2', + tools.run_asv_with_conf(conf, 'run', f"{defaultBranch}", '--steps=2', '--bench=time_secondary.track_value', '--quick', '--skip-existing-commits', _machine_file=join(tmpdir, 'asv-machine.json')) diff --git a/test/tools.py b/test/tools.py index 6d8a36049..33079d480 100644 --- a/test/tools.py +++ b/test/tools.py @@ -210,7 +210,11 @@ def get_hash(self, name): def get_branch_hashes(self, branch=None): if branch is None: - branch = "master" + try: + branch = self.run_git(["config", "init.defaultBranch"], + display_error=False).strip() + except util.ProcessError: + branch = 'master' return [x.strip() for x in self.run_git(['rev-list', branch]).splitlines() if x.strip()]