def test_find(capfd, tmpdir): values = [ (None, None), (1, 1), (3, 1), (None, 1), (6, None), (5, 1), (6, 1), (6, 1), (6, 6), (6, 6), ] tmpdir, local, conf, machine_file = generate_basic_conf( tmpdir, values=values, dummy_packages=False) # Test find at least runs tools.run_asv_with_conf(conf, 'find', "master~5..master", "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) assert "Greatest regression found: {0}".format( regression_hash[:8]) in output
def test_matrix_environments(tmpdir): try: util.which('python2.7') except RuntimeError: raise RuntimeError( "python 2.7 must be installed for this test to pass") try: util.which('python3.3') except RuntimeError: raise RuntimeError( "python 3.3 must be installed for this test to pass") conf = config.Config() conf.env_dir = six.text_type(tmpdir.join("env")) conf.pythons = ["2.7", "3.3"] conf.matrix = { "six": ["1.4", None], "psutil": ["1.2", "1.1"] } environments = list(environment.get_environments(conf)) assert len(environments) == 2 * 2 * 2 # Only test the first two environments, since this is so time # consuming for env in environments[:2]: env.setup() env.install_requirements() output = env.run( ['-c', 'import six, sys; sys.stdout.write(six.__version__)']) if env._requirements['six'] is not None: assert output.startswith(six.text_type(env._requirements['six'])) output = env.run( ['-c', 'import psutil, sys; sys.stdout.write(psutil.__version__)']) assert output.startswith(six.text_type(env._requirements['psutil']))
def test_which_path(tmpdir): dirname = os.path.abspath(os.path.join(str(tmpdir), 'name with spaces')) fn = 'asv_test_exe_1234.exe' os.makedirs(dirname) shutil.copyfile(sys.executable, os.path.join(dirname, fn)) old_path = os.environ.get('PATH', '') try: if WIN: os.environ['PATH'] = old_path + os.pathsep + '"' + dirname + '"' util.which('asv_test_exe_1234') util.which('asv_test_exe_1234.exe') os.environ['PATH'] = old_path + os.pathsep + dirname util.which('asv_test_exe_1234.exe') if WIN: util.which('asv_test_exe_1234') finally: os.environ['PATH'] = old_path
def test_conda_channel_addition(tmpdir, channel_list, expected_channel): # test that we can add conda channels to environments # and that we respect the specified priority order # of channels conf = config.Config() conf.env_dir = six.text_type(tmpdir.join("env")) conf.environment_type = "conda" conf.pythons = [PYTHON_VER1] conf.matrix = {} # these have to be valid channels # available for online access conf.conda_channels = channel_list environments = list(environment.get_environments(conf, None)) # should have one environment per Python version assert len(environments) == 1 # create the environments for env in environments: env.create() # generate JSON output from conda list # and parse to verify added channels # for current env # (conda info would be more direct, but # seems to reflect contents of condarc file, # which we are intentionally trying not to modify) conda = util.which('conda') print("\n**conda being used:", conda) out_str = six.text_type(util.check_output([conda, 'list', '-p', os.path.normpath(env._path), '--json'])) json_package_list = json.loads(out_str) print(json_package_list) for installed_package in json_package_list: # check only explicitly installed packages if installed_package['name'] not in ('python',): continue print(installed_package) assert installed_package['channel'] == expected_channel
def test_find(capfd, basic_conf): tmpdir, local, conf, machine_file = basic_conf if WIN and os.path.basename(sys.argv[0]).lower().startswith('py.test'): # Multiprocessing in spawn mode can result to problems with py.test # Find.run calls Setup.run in parallel mode by default pytest.skip("Multiprocessing spawn mode on Windows not safe to run " "from py.test runner.") # Test find at least runs tools.run_asv_with_conf(conf, 'find', "master~5..master", "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) assert "Greatest regression found: {0}".format(regression_hash[:8]) in output
def test_find_timeout(capfd, tmpdir): values = [(1, 0), (1, 0), (1, -1)] tmpdir, local, conf, machine_file = generate_basic_conf( tmpdir, values=values, dummy_packages=False) # Test find at least runs tools.run_asv_with_conf(conf, 'find', "-e", "master", "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) assert "Greatest regression found: {0}".format( regression_hash[:8]) in output assert "asv: benchmark timed out (timeout 1.0s)" in output
def test_find_inverted(capfd, tmpdir): values = [ (5, 6), (6, 6), (6, 6), (6, 1), (6, 1), ] tmpdir, local, conf, machine_file = generate_basic_conf( tmpdir, values=values, dummy_packages=False) tools.run_asv_with_conf(*[ conf, 'find', "-i", "master~4..master", "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) formatted = "Greatest improvement found: {0}".format(regression_hash[:8]) assert formatted in output
import os import sys import six import pytest from asv import config from asv import environment from asv import util WIN = (os.name == "nt") try: util.which('python2.7') HAS_PYTHON_27 = True except (RuntimeError, IOError): HAS_PYTHON_27 = (sys.version_info[:2] == (2, 7)) try: util.which('python3.4') HAS_PYTHON_34 = True except (RuntimeError, IOError): HAS_PYTHON_34 = (sys.version_info[:2] == (3, 4)) try: # Conda can install Python 2.7 and 3.4 on demand util.which('conda')
def test_which_path(tmpdir): dirname = os.path.abspath(os.path.join(str(tmpdir), 'name with spaces')) fn = 'asv_test_exe_1234.exe' fn2 = 'asv_test_exe_4321.bat' os.makedirs(dirname) shutil.copyfile(sys.executable, os.path.join(dirname, fn)) shutil.copyfile(sys.executable, os.path.join(dirname, fn2)) old_path = os.environ.get('PATH', '') try: if WIN: os.environ['PATH'] = old_path + os.pathsep + '"' + dirname + '"' util.which('asv_test_exe_1234') util.which('asv_test_exe_1234.exe') util.which('asv_test_exe_4321') util.which('asv_test_exe_4321.bat') os.environ['PATH'] = old_path + os.pathsep + dirname util.which('asv_test_exe_1234.exe') util.which('asv_test_exe_4321.bat') if WIN: util.which('asv_test_exe_1234') util.which('asv_test_exe_4321') # Check the paths= argument util.which('asv_test_exe_1234.exe', paths=[dirname]) util.which('asv_test_exe_4321.bat', paths=[dirname]) # Check non-existent files with pytest.raises(IOError): util.which('nonexistent.exe', paths=[dirname]) finally: os.environ['PATH'] = old_path
def __init__(self, path): self.path = abspath(path) self._git = util.which('git') self._fake_date = datetime.datetime.now()
# Two Python versions for testing PYTHON_VER1 = "{0[0]}.{0[1]}".format(sys.version_info) if sys.version_info < (3, ): PYTHON_VER2 = "3.6" else: PYTHON_VER2 = "2.7" # Installable library versions to use in tests DUMMY1_VERSION = "0.14" DUMMY2_VERSIONS = ["0.3.7", "0.3.9"] WIN = (os.name == "nt") try: util.which('pypy') HAS_PYPY = True except (RuntimeError, IOError): HAS_PYPY = hasattr(sys, 'pypy_version_info') and (sys.version_info[:2] == (2, 7)) def _check_conda(): from asv.plugins.conda import _conda_lock conda = _find_conda() with _conda_lock(): try: subprocess.check_call([conda, 'build', '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) except subprocess.CalledProcessError:
import json import six import pytest from os.path import abspath, dirname, join, isfile, relpath from asv import config, environment, util from asv.results import iter_results_for_machine from asv.util import check_output, which from . import tools from .tools import dummy_packages try: which('conda') HAS_CONDA = True except (RuntimeError, IOError): HAS_CONDA = False WIN = (os.name == 'nt') dummy_values = [ (None, None), (1, 1), (3, 1), (None, 1), (6, None), (5, 1), (6, 1), (6, 1),
# Two Python versions for testing PYTHON_VER1 = "{0[0]}.{0[1]}".format(sys.version_info) if sys.version_info < (3,): PYTHON_VER2 = "3.6" else: PYTHON_VER2 = "2.7" # Installable library versions to use in tests DUMMY1_VERSION = "0.14" DUMMY2_VERSIONS = ["0.3.7", "0.3.9"] WIN = (os.name == "nt") try: util.which('pypy') HAS_PYPY = True except (RuntimeError, IOError): HAS_PYPY = hasattr(sys, 'pypy_version_info') and (sys.version_info[:2] == (2, 7)) try: # Conda can install required Python versions on demand _find_conda() HAS_CONDA = True except (RuntimeError, IOError): HAS_CONDA = False try: import virtualenv
from os.path import abspath, dirname, join, isfile, relpath import shutil import sys import six import json import pytest from asv import config, environment from asv.util import check_output, which from . import tools try: which('conda') HAS_CONDA = True except (RuntimeError, IOError): HAS_CONDA = False WIN = (os.name == 'nt') dummy_values = [ (None, None), (1, 1), (3, 1), (None, 1), (6, None), (5, 1),