def bytes__get(self): if self._bytes is None: f = open(self.full, 'rb') self._bytes = string(f.read()) f.close() return self._bytes
def run(self, script, *args, **kw): """ Run the command, with the given arguments. The ``script`` argument can have space-separated arguments, or you can use the positional arguments. Keywords allowed are: ``expect_error``: (default False) Don't raise an exception in case of errors ``expect_stderr``: (default ``expect_error``) Don't raise an exception if anything is printed to stderr ``stdin``: (default ``""``) Input to the script ``cwd``: (default ``self.cwd``) The working directory to run in (default ``base_path``) ``quiet``: (default False) When there's an error (return code != 0), do not print stdout/stderr Returns a `ProcResult <class-paste.fixture.ProcResult.html>`_ object. """ __tracebackhide__ = True expect_error = _popget(kw, 'expect_error', False) expect_stderr = _popget(kw, 'expect_stderr', expect_error) cwd = _popget(kw, 'cwd', self.cwd) stdin = _popget(kw, 'stdin', None) quiet = _popget(kw, 'quiet', False) debug = _popget(kw, 'debug', False) if not self.temp_path: if 'expect_temp' in kw: raise TypeError( 'You cannot use expect_temp unless you use capture_temp=True') expect_temp = _popget(kw, 'expect_temp', not self._assert_no_temp) args = list(map(str, args)) assert not kw, ( "Arguments not expected: %s" % ', '.join(kw.keys())) if self.split_cmd and ' ' in script: if args: # Then treat this as a script that has a space in it pass else: script, args = script.split(None, 1) args = shlex.split(args) environ=clean_environ(self.environ) all = [script] + args files_before = self._find_files() if debug: proc = subprocess.Popen(all, cwd=cwd, shell=(sys.platform=='win32'), # see http://bugs.python.org/issue8557 env=clean_environ(self.environ)) else: proc = subprocess.Popen(all, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, cwd=cwd, shell=(sys.platform=='win32'), # see http://bugs.python.org/issue8557 env=clean_environ(self.environ)) if debug: stdout,stderr = proc.communicate() else: stdout, stderr = proc.communicate(stdin) stdout = string(stdout) stderr = string(stderr) stdout = string(stdout).replace('\r\n', '\n') stderr = string(stderr).replace('\r\n', '\n') files_after = self._find_files() result = ProcResult( self, all, stdin, stdout, stderr, returncode=proc.returncode, files_before=files_before, files_after=files_after) if not expect_error: result.assert_no_error(quiet) if not expect_stderr: result.assert_no_stderr(quiet) if not expect_temp: result.assert_no_temp(quiet) return result