def fixture(): skip_if_no_svn() repo_name = 'svnrepo' tmpdir = os.path.realpath(tempfile.mkdtemp(prefix='reproman-tests-')) root_dir = os.path.join(tmpdir, repo_name) subdir = os.path.join(tmpdir, 'subdir') os.mkdir(subdir) runner = Runner() runner.run(['svnadmin', 'create', root_dir]) runner.run(['svn', 'checkout', 'file://' + root_dir], cwd=subdir) checked_out_dir = os.path.join(subdir, repo_name) if kind != 'empty': runner.run(['touch', 'foo'], cwd=checked_out_dir) runner.run(['svn', 'add', 'foo'], cwd=checked_out_dir) runner.run(['svn', 'commit', '-m', 'bar'], cwd=checked_out_dir) yield (root_dir, checked_out_dir) shutil.rmtree(tmpdir)
def check_run_and_get_output(cmd): runner = Runner() try: # suppress log output happen it was set to high values with patch.dict('os.environ', {'REPROMAN_LOGLEVEL': 'WARN'}): output = runner.run(["reproman", "--help"]) except CommandError as e: raise AssertionError("'reproman --help' failed to start normally. " "Exited with %d and output %s" % (e.code, (e.stdout, e.stderr))) return output
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 venv_test_dir(): dirs = AppDirs('reproman') test_dir = os.path.join(dirs.user_cache_dir, 'venv_test') if os.path.exists(test_dir): return test_dir runner = Runner() runner.run(["mkdir", "-p", test_dir]) pymod_dir = os.path.join(test_dir, "minimal_pymodule") create_pymodule(pymod_dir) with chpwd(test_dir): runner.run(["virtualenv", "--python", PY_VERSION, "venv0"]) runner.run(["virtualenv", "--python", PY_VERSION, "venv1"]) runner.run(["./venv0/bin/pip", "install", "pyyaml"]) runner.run(["./venv0/bin/pip", "install", "-e", pymod_dir]) runner.run(["./venv1/bin/pip", "install", "attrs"]) # Make sure we're compatible with older pips. runner.run(["./venv1/bin/pip", "install", "pip==9.0.3"]) return test_dir
class ShellSession(POSIXSession): """Local shell session""" def __init__(self): super(ShellSession, self).__init__() self._runner = None @borrowdoc(Session) def open(self): self._runner = Runner() @borrowdoc(Session) def close(self): self._runner = None @borrowdoc(Session) def _execute_command(self, command, env=None, cwd=None, with_shell=False): # XXX should it be a generic behavior to auto-start? if self._runner is None: self.open() run_kw = {} if env: # if anything custom, then we need to get original full environment # and update it with custom settings which we either "accumulated" # via set_envvar, or it was passed into this call. run_kw['env'] = get_updated_env(os.environ, env) return self._runner.run( command, # For now we do not ERROR out whenever command fails or provides # stderr -- analysis will be done outside expect_fail=True, expect_stderr=True, cwd=cwd, **run_kw) # , shell=True) @borrowdoc(Session) def isdir(self, path): return os.path.isdir(path) @borrowdoc(Session) def mkdir(self, path, parents=False): if not os.path.exists(path): if parents: os.makedirs(path) else: try: os.mkdir(path) except OSError: raise CommandError( msg="Failed to make directory {}".format(path)) @borrowdoc(Session) def get(self, src_path, dest_path=None, uid=-1, gid=-1): dest_path = self._prepare_dest_path(src_path, dest_path) if os.path.isdir(src_path): shutil.copytree(src_path, dest_path) else: shutil.copy(src_path, dest_path) if uid > -1 or gid > -1: self.chown(dest_path, uid, gid, recursive=True) @borrowdoc(Session) def put(self, src_path, dest_path, uid=-1, gid=-1): # put is the same as get for the shell resource self.get(src_path, dest_path, uid, gid)
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", pymod_dir]) return test_dir