def __init__(self, environ=None): self.root_path = mkdtemp(prefix='pkgtest') # We will set up a virtual environment at root_path. self.scratch_path = self.root_path / self.scratch self.venv_path = self.root_path / self.venv if not environ: environ = dict(((k, v) for k, v in os.environ.items() if not k.lower().startswith('pip_'))) environ['PIP_DOWNLOAD_CACHE'] = str(download_cache) environ['PIP_NO_INPUT'] = '1' environ['PIP_LOG_FILE'] = str(self.root_path/'pip-log.txt') super(Environment,self).__init__( self.root_path, ignore_hidden=False, environ=environ, split_cmd=False, start_clear=False, cwd=self.scratch_path, capture_temp=True, assert_no_temp=True ) mktree(self.venv_path) mktree(self.scratch_path) use_distribute = os.environ.get('PKGTEST_USE_DISTRIBUTE', False) # Create a virtualenv and remember where it is putting things. virtualenv_paths = create_virtualenv(self.venv_path, distribute=use_distribute) assert self.venv_path == virtualenv_paths[0] # sanity check for id,path in zip(('venv', 'lib', 'include', 'bin'), virtualenv_paths): setattr(self, id+'_path', Path(path)) setattr(self, id, relpath(self.root_path,path)) assert self.venv == Environment.venv # sanity check self.site_packages = self.lib/'site-packages' self.site_packages_path = self.lib_path/'site-packages' # put the virtualenv's bin dir first on the PATH; that's # essentially all that happens when you activate a virtualenv self.environ['PATH'] = Path.pathsep.join( (self.bin_path, self.environ['PATH']) ) # test that test-scratch virtualenv creation produced sensible venv python pythonbin = self.run('python', '-c', 'import sys; print sys.executable').stdout.strip() if Path(pythonbin).noext != self.bin_path/'python': raise RuntimeError( "Oops! 'python' in our test environment runs %r" " rather than expected %r" % (pythonbin, self.bin_path/'python')) # make sure we have current setuptools to avoid svn incompatibilities if not use_distribute: install_setuptools(self)
def __init__(self, environ=None): super(Environment,self).__init__(environ=environ) tmppath = Path(testutil.mkdtemp()) # On Windows, we can't use pip to upgrade the pip package because # it fails upgrading the pip.exe that is currently running. # So, we copy all of pip from the bin_path to some temporary # directory and invoke it from there. for pip in glob.glob(self.bin_path/'pip*'): shutil.copy2(pip, tmppath) pip_exe = tmppath/'pip'+testutil.exe_ext self.run(pip_exe, 'install', '--upgrade', 'pip') # Now, we install ryppl by running it's setup.py from # the ryppl/ directory (one directory up) self.run('python', 'setup.py', 'install', cwd=here.folder)
@property def stdout(self): return self._impl.stdout.replace('\r\n', '\n') @property def stderr(self): return self._impl.stderr.replace('\r\n', '\n') def __str__(self): return str(self._impl).replace('\r\n','\n') else: # Python doesn't automatically forward __str__ through __getattr__ def __str__(self): return str(self._impl) download_cache = mkdtemp(prefix='pip-cache') class Environment(TestFileEnvironment): """ A specialized TestFileEnvironment for tests of packaging/installation functionality """ # # Attribute naming convention # --------------------------- # # Instances of this class have several attributes representing paths # in the filesystem. To keep things straight, absolute paths have # a name of the form xxxx_path and relative paths have a name that # does not end in '_path'.