def venv_test_dir(): skipif.no_network() dirs = AppDirs('reproman') ssp = os.getenv("REPROMAN_TESTS_ASSUME_SSP") # Encode the SSP value in the directory name so that the caller doesn't # have to worry about deleting the cached venvs before setting the flag.. test_dir = os.path.join(dirs.user_cache_dir, 'venv_test{}'.format("_ssp" if ssp else "")) if os.path.exists(test_dir): return test_dir os.makedirs(test_dir) pymod_dir = os.path.join(test_dir, "minimal_pymodule") create_pymodule(pymod_dir) runner = Runner(cwd=test_dir) pip0 = op.join("venv0", "bin", "pip") pip1 = op.join("venv1", "bin", "pip") runner.run(["virtualenv", "--python", PY_VERSION, "venv0"]) runner.run(["virtualenv", "--python", PY_VERSION, "venv1"]) runner.run([pip0, "install", "pyyaml"]) runner.run([pip0, "install", "-e", pymod_dir]) runner.run([pip1, "install", "attrs"]) # Make sure we're compatible with older pips. runner.run([pip1, "install", "pip==9.0.3"]) if ssp: # The testing environment supports --system_site_packages. pip2 = op.join("venv-nonlocal", "bin", "pip") runner.run(["virtualenv", "--python", PY_VERSION, "--system-site-packages", "venv-nonlocal"]) runner.run([pip2, "install", "attrs"]) return test_dir
def fixture(): skipif.no_network() skipif.no_singularity() from reproman.resource.singularity import Singularity resource = Singularity(name=name or str(uuid.uuid4().hex)[:11], image=image) resource.connect() list(resource.create()) yield resource resource.delete()
def container_dataset(tmpdir_factory): skipif.no_datalad() skipif.no_network() if "datalad_container" not in external_versions: pytest.skip("datalad-container not installed") import datalad.api as dl path = str(tmpdir_factory.mktemp("container_dataset")) ds = dl.Dataset(path).create(force=True) ds.containers_add("dc", url="shub://datalad/datalad-container:testhelper") return ds
def fixture(tmpdir_factory): skipif.no_network() skipif.no_singularity() # Change to a temporary directory so that we don't pollute the current # directory with image files. with chpwd(str(tmpdir_factory.mktemp("singularity-resource"))): from reproman.resource.singularity import Singularity resource = Singularity(name=name or str(uuid.uuid4().hex)[:11], image=image) resource.connect() list(resource.create()) yield resource resource.delete()
def venv_test_dir(): skipif.no_network() dirs = AppDirs('reproman') test_dir = os.path.join(dirs.user_cache_dir, 'venv_test') if os.path.exists(test_dir): return test_dir os.makedirs(test_dir) pymod_dir = os.path.join(test_dir, "minimal_pymodule") create_pymodule(pymod_dir) runner = Runner(cwd=test_dir) pip0 = op.join("venv0", "bin", "pip") pip1 = op.join("venv1", "bin", "pip") runner.run(["virtualenv", "--python", PY_VERSION, "venv0"]) runner.run(["virtualenv", "--python", PY_VERSION, "venv1"]) runner.run([pip0, "install", "pyyaml"]) runner.run([pip0, "install", "-e", pymod_dir]) runner.run([pip1, "install", "attrs"]) # Make sure we're compatible with older pips. runner.run([pip1, "install", "pip==9.0.3"]) return test_dir
def docker_fixture(): """The actual fixture code generated by get_docker_fixture on setup, this fixture ensures that a docker container is running and starts one if necessary. Fixture yields parameters of the container with a `custom` field passed into the `get_docker_container`. on teardown, this fixture stops the docker container it started """ skipif.no_docker_engine() skipif.no_network() args = [ 'docker', 'run', '-d', '--rm', ] if seccomp_unconfined: args.extend(['--security-opt', 'seccomp=unconfined']) params = {} if name: args += ['--name', name] params['name'] = name if portmaps: for from_to in portmaps.items(): args += ['-p', '%d:%d' % from_to] params['port'] = from_to[0] args += [image] stdout, _ = Runner().run(args, expect_stderr=True) params['container_id'] = container_id = stdout.strip() params['custom'] = custom_params yield params Runner().run(['docker', 'stop', container_id])
def test_skipif_inline(): with patch.dict("os.environ", {"REPROMAN_TESTS_NONETWORK": "1"}): with pytest.raises(pytest.skip.Exception): skipif.no_network()