Skip to content

Commit

Permalink
Move fixture from test/test_step_detect.py file (#1131)
Browse files Browse the repository at this point in the history
  • Loading branch information
dorothykiz1 authored Mar 12, 2022
1 parent ac7189e commit fd9f3ac
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
31 changes: 30 additions & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import pytest
import selenium

from asv import config, environment, repo
from asv import config, environment, repo, step_detect
from asv.repo import get_repo
from asv.step_detect import L1Dist

from . import tools
from .test_benchmarks import ASV_CONF_JSON, BENCHMARK_DIR
Expand All @@ -22,6 +23,12 @@
except ImportError:
hglib = None

try:
from asv import _rangemedian
HAVE_RANGEMEDIAN = True
except ImportError:
HAVE_RANGEMEDIAN = False


def pytest_addoption(parser):
parser.addoption("--webdriver", action="store", default="None",
Expand Down Expand Up @@ -304,3 +311,25 @@ def show_fixture(tmpdir, example_results):
'environment_type': "shouldn't matter what"})

return conf


@pytest.fixture(params=[
"python",
pytest.param("rangemedian",
marks=pytest.mark.skipif(not HAVE_RANGEMEDIAN,
reason="compiled asv._rangemedian required"))
])
def use_rangemedian(request):
if request.param == "rangemedian":
assert isinstance(step_detect.get_mu_dist([0], [1]), _rangemedian.RangeMedian)
return True
else:
step_detect._rangemedian = None

def restore():
if HAVE_RANGEMEDIAN:
step_detect._rangemedian = _rangemedian
request.addfinalizer(restore)

assert isinstance(step_detect.get_mu_dist([0], [1]), L1Dist)
return False
35 changes: 3 additions & 32 deletions test/test_step_detect.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst

import random

import pytest

from asv.step_detect import (solve_potts, solve_potts_autogamma, solve_potts_approx,
detect_regressions, golden_search, median, rolling_median_dev, L1Dist,
detect_steps)
from asv import step_detect
from asv.step_detect import (detect_regressions, detect_steps, golden_search, median,
rolling_median_dev, solve_potts, solve_potts_approx,
solve_potts_autogamma)

try:
import numpy as np
Expand All @@ -16,34 +15,6 @@
except (ImportError, NameError):
HAVE_NUMPY = False

try:
from asv import _rangemedian
HAVE_RANGEMEDIAN = True
except ImportError:
HAVE_RANGEMEDIAN = False


@pytest.fixture(params=[
"python",
pytest.param("rangemedian",
marks=pytest.mark.skipif(not HAVE_RANGEMEDIAN,
reason="compiled asv._rangemedian required"))
])
def use_rangemedian(request):
if request.param == "rangemedian":
assert isinstance(step_detect.get_mu_dist([0], [1]), _rangemedian.RangeMedian)
return True
else:
step_detect._rangemedian = None

def restore():
if HAVE_RANGEMEDIAN:
step_detect._rangemedian = _rangemedian
request.addfinalizer(restore)

assert isinstance(step_detect.get_mu_dist([0], [1]), L1Dist)
return False


@pytest.mark.skipif(not HAVE_NUMPY, reason="test needs numpy")
def test_solve_potts(use_rangemedian):
Expand Down

0 comments on commit fd9f3ac

Please sign in to comment.