def test_repr(self): """ A user should be able to run str(Subprocess) in their shell prompt. """ cmd_str = str(run('printf', 'foo"bar')) output = subprocess.check_output(cmd_str, shell=True).decode() assert output == 'foo"bar'
def test_empty_env(self): proc = run('env', env={'foo': 'bar'}) spm_run = set(proc.stdout.read().decode().split('\n')) sh_run = set( subprocess.check_output(str(proc), shell=True).decode().split('\n') ) assert sh_run == spm_run
def test_empty_env(self): proc = run('env', env={'foo': 'bar'}) spm_run = set(proc.stdout.read().decode().split('\n')) sh_run = set( subprocess.check_output(str(proc), shell=True).decode().split('\n')) assert sh_run == spm_run
def test_stdin_from_file(self): content = '__file_content__' fname = self.get_temp_filename() with open(fname, 'w') as file_: file_.write(content) cat = run('cat') cat.stdin = open(fname) assert cat.stdout.read().decode() == content
def test_stdout_to_file(self): string = '__output__' fname = self.get_temp_filename() echo = run('printf', string) echo.stdout = open(fname, 'w') out, err = echo.wait() assert out is None with open(fname) as file_: assert six.u(file_.read()) == string
def test_pass_subprocess_to_pipe(self): proc = pipe(['printf', 'hello'], ['gzip'], run('zcat')) assert proc.stdout.read().decode() == 'hello'
def test_subprocess_failure(self): with self.assertRaises(subprocess.CalledProcessError): run('false').wait()
def test_repr_env(self): cmd_str = str(run('env', env={'FOO': 'BAR'})) env = subprocess.check_output(cmd_str, shell=True).decode().split('\n') assert 'FOO=BAR' in env
def test_empty_environment_by_default(self): env = run('env').stdout.read().decode() assert env == ''
def test_environment(self): env = run('env', env={'FOO': 'BAR'}).stdout.read().decode().split('\n') assert 'FOO=BAR' in env
def test_copy_environment_opt_in(self): env = run('env', env=propagate_env({})).stdout.read().decode() assert env != ''
def test_repr_env(self): cmd_str = str(run('env', env=propagate_env(foo='bar'))) env = subprocess.check_output(cmd_str, shell=True).decode().split('\n') assert 'foo=bar' in env
def test_empty_environment(self): env = run('env', env=empty_environ()).stdout.read().decode() assert env == ''