From 5f396cf08f3644918d25cd5cc5c6d7e974f04d67 Mon Sep 17 00:00:00 2001 From: dorothykiz1 Date: Wed, 9 Mar 2022 19:27:57 +0300 Subject: [PATCH 1/4] move fixtures to conftest.py file --- test/conftest.py | 48 +++++++++++++++++++++++++++++++++++++++++ test/test_benchmarks.py | 22 ------------------- test/test_workflow.py | 5 ----- 3 files changed, 48 insertions(+), 27 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index a9b72d82b..ef7fde437 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -12,6 +12,9 @@ WAIT_TIME, DUMMY1_VERSION, DUMMY2_VERSIONS, WIN, HAS_CONDA, PYTHON_VER1, PYTHON_VER2) from .test_web import _rebuild_basic_html +from asv.repo import get_repo +from .test_benchmarks import ASV_CONF_JSON, BENCHMARK_DIR +from asv import environment try: @@ -266,3 +269,48 @@ def basic_html(request): tmpdir = join(str(cache_dir), 'cached') html_dir, dvcs = _rebuild_basic_html(tmpdir) return html_dir, dvcs + + +@pytest.fixture +def benchmarks_fixture(tmpdir): + tmpdir = str(tmpdir) + os.chdir(tmpdir) + + shutil.copytree(BENCHMARK_DIR, 'benchmark') + + d = {} + d.update(ASV_CONF_JSON) + d['env_dir'] = "env" + d['benchmark_dir'] = 'benchmark' + d['repo'] = tools.generate_test_repo(tmpdir, [0]).path + d['branches'] = ["master"] + conf = config.Config.from_json(d) + + repo = get_repo(conf) + envs = list(environment.get_environments(conf, None)) + commit_hash = repo.get_hash_from_name(repo.get_branch_name()) + + return conf, repo, envs, commit_hash + + +@pytest.fixture(params=[ + "git", + pytest.param("hg", marks=pytest.mark.skipif(hglib is None, reason="needs hglib")), +]) +def generate_result_dir(request, tmpdir): + tmpdir = str(tmpdir) + dvcs_type = request.param + + def _generate_result_dir(values, commits_without_result=None): + dvcs = tools.generate_repo_from_ops( + tmpdir, dvcs_type, [("commit", i) for i in range(len(values))]) + commits = list(reversed(dvcs.get_branch_hashes())) + commit_values = {} + commits_without_result = [commits[i] for i in commits_without_result or []] + for commit, value in zip(commits, values): + if commit not in commits_without_result: + commit_values[commit] = value + conf = tools.generate_result_dir(tmpdir, dvcs, commit_values) + repo = get_repo(conf) + return conf, repo, commits + return _generate_result_dir diff --git a/test/test_benchmarks.py b/test/test_benchmarks.py index 43ed4d7a5..6ca7e76da 100644 --- a/test/test_benchmarks.py +++ b/test/test_benchmarks.py @@ -32,28 +32,6 @@ ON_PYPY = False -@pytest.fixture -def benchmarks_fixture(tmpdir): - tmpdir = str(tmpdir) - os.chdir(tmpdir) - - shutil.copytree(BENCHMARK_DIR, 'benchmark') - - d = {} - d.update(ASV_CONF_JSON) - d['env_dir'] = "env" - d['benchmark_dir'] = 'benchmark' - d['repo'] = tools.generate_test_repo(tmpdir, [0]).path - d['branches'] = ["master"] - conf = config.Config.from_json(d) - - repo = get_repo(conf) - envs = list(environment.get_environments(conf, None)) - commit_hash = repo.get_hash_from_name(repo.get_branch_name()) - - return conf, repo, envs, commit_hash - - def test_discover_benchmarks(benchmarks_fixture): conf, repo, envs, commit_hash = benchmarks_fixture diff --git a/test/test_workflow.py b/test/test_workflow.py index 48db7d9e6..d387c0461 100644 --- a/test/test_workflow.py +++ b/test/test_workflow.py @@ -73,11 +73,6 @@ def generate_basic_conf(tmpdir, repo_subdir='', values=dummy_values, dummy_packa return tmpdir, local, conf, machine_file -@pytest.fixture -def basic_conf(tmpdir, dummy_packages): - return generate_basic_conf(tmpdir) - - def test_run_publish(capfd, basic_conf): tmpdir, local, conf, machine_file = basic_conf tmpdir = util.long_path(tmpdir) From 8513c2a5a0d9fdb35ec34b1e515602012107537a Mon Sep 17 00:00:00 2001 From: dorothykiz1 Date: Wed, 9 Mar 2022 19:34:45 +0300 Subject: [PATCH 2/4] fix import errors --- test/test_runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_runner.py b/test/test_runner.py index ffc2f63d6..2b012e35a 100644 --- a/test/test_runner.py +++ b/test/test_runner.py @@ -19,7 +19,7 @@ from asv import util from asv.results import Results -from .test_benchmarks import benchmarks_fixture, ASV_CONF_JSON, BENCHMARK_DIR +from .test_benchmarks import ASV_CONF_JSON, BENCHMARK_DIR ON_PYPY = hasattr(sys, 'pypy_version_info') From f76ea6a192a586e5674724b3c41191249dc695e6 Mon Sep 17 00:00:00 2001 From: dorothykiz1 Date: Wed, 9 Mar 2022 19:49:15 +0300 Subject: [PATCH 3/4] fix import errors --- test/conftest.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index ef7fde437..7c4861249 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,29 +1,28 @@ +import contextlib import os import shutil -import contextlib +import textwrap +from os.path import abspath, dirname, join + import pytest import selenium -import textwrap -from os.path import join, abspath, dirname -from asv import config -from asv import repo -from .test_workflow import generate_basic_conf -from .tools import (locked_cache_dir, run_asv_with_conf, _build_dummy_wheels, - WAIT_TIME, DUMMY1_VERSION, DUMMY2_VERSIONS, WIN, HAS_CONDA, - PYTHON_VER1, PYTHON_VER2) -from .test_web import _rebuild_basic_html + +from asv import config, environment, repo from asv.repo import get_repo -from .test_benchmarks import ASV_CONF_JSON, BENCHMARK_DIR -from asv import environment +from . import tools +from .test_benchmarks import ASV_CONF_JSON, BENCHMARK_DIR +from .test_web import _rebuild_basic_html +from .test_workflow import generate_basic_conf +from .tools import (DUMMY1_VERSION, DUMMY2_VERSIONS, HAS_CONDA, PYTHON_VER1, + PYTHON_VER2, WAIT_TIME, WIN, _build_dummy_wheels, + locked_cache_dir, run_asv_with_conf) try: import hglib except ImportError: hglib = None -from . import tools - def pytest_addoption(parser): parser.addoption("--webdriver", action="store", default="None", From fde06780a3525406dd4eef4fc3922a53f93dcbcf Mon Sep 17 00:00:00 2001 From: dorothykiz1 Date: Wed, 9 Mar 2022 20:05:11 +0300 Subject: [PATCH 4/4] sort imports --- test/conftest.py | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index 29366bda2..e7025d4b9 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -290,26 +290,3 @@ def benchmarks_fixture(tmpdir): commit_hash = repo.get_hash_from_name(repo.get_branch_name()) return conf, repo, envs, commit_hash - - -@pytest.fixture(params=[ - "git", - pytest.param("hg", marks=pytest.mark.skipif(hglib is None, reason="needs hglib")), -]) -def generate_result_dir(request, tmpdir): - tmpdir = str(tmpdir) - dvcs_type = request.param - - def _generate_result_dir(values, commits_without_result=None): - dvcs = tools.generate_repo_from_ops( - tmpdir, dvcs_type, [("commit", i) for i in range(len(values))]) - commits = list(reversed(dvcs.get_branch_hashes())) - commit_values = {} - commits_without_result = [commits[i] for i in commits_without_result or []] - for commit, value in zip(commits, values): - if commit not in commits_without_result: - commit_values[commit] = value - conf = tools.generate_result_dir(tmpdir, dvcs, commit_values) - repo = get_repo(conf) - return conf, repo, commits - return _generate_result_dir