def run_cmd(self, cmd): kwargs = {} inside_tox = 'BOOTSTRAPPER_TOX' in os.environ out, err = bootstrapper.get_temp_streams() if cmd.startswith('bootstrap'): func = bootstrapper.main args = tuple(shlex.split(cmd)[1:]) args += ('-e', self.venv, '-r', self.requirements) if self.config: args += ('-c', self.config) if inside_tox: args += ('--ignore-activated', ) elif cmd.startswith('pip '): func = bootstrapper.pip_cmd args = ( self.venv, cmd[4:].split(), inside_tox, ) kwargs['echo'] = True else: assert False, 'Command {0!r} is not supported!'.format(cmd) with self.redirect_streams(out, err): func(*args, **kwargs) try: return (out.read(), err.read()) finally: out.close() err.close()
def run_cmd(self, cmd): kwargs = {} inside_tox = 'BOOTSTRAPPER_TOX' in os.environ out, err = bootstrapper.get_temp_streams() if cmd.startswith('bootstrap'): func = bootstrapper.main args = tuple(shlex.split(cmd)[1:]) args += ('-e', self.venv, '-r', self.requirements) if self.config: args += ('-c', self.config) if inside_tox: args += ('--ignore-activated', ) elif cmd.startswith('pip '): func = bootstrapper.pip_cmd args = (self.venv, cmd[4:].split(), inside_tox, ) kwargs['echo'] = True else: assert False, 'Command {0!r} is not supported!'.format(cmd) with self.redirect_streams(out, err): func(*args, **kwargs) try: return (out.read(), err.read()) finally: out.close() err.close()
def test_get_streams(self): out, err = bootstrapper.get_temp_streams() out.write('Output'), err.write('Error') out.seek(0), err.seek(0) self.assertEqual(out.read(), 'Output') self.assertEqual(err.read(), 'Error') out.close() err.close()