Пример #1
0
    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'
Пример #2
0
    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'
Пример #3
0
    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
Пример #4
0
    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
Пример #5
0
    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
Пример #6
0
    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
Пример #7
0
    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
Пример #8
0
    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
Пример #9
0
 def test_pass_subprocess_to_pipe(self):
     proc = pipe(['printf', 'hello'], ['gzip'], run('zcat'))
     assert proc.stdout.read().decode() == 'hello'
Пример #10
0
 def test_subprocess_failure(self):
     with self.assertRaises(subprocess.CalledProcessError):
         run('false').wait()
Пример #11
0
    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
Пример #12
0
    def test_empty_environment_by_default(self):
        env = run('env').stdout.read().decode()

        assert env == ''
Пример #13
0
    def test_empty_environment_by_default(self):
        env = run('env').stdout.read().decode()

        assert env == ''
Пример #14
0
    def test_environment(self):
        env = run('env', env={'FOO': 'BAR'}).stdout.read().decode().split('\n')

        assert 'FOO=BAR' in env
Пример #15
0
 def test_pass_subprocess_to_pipe(self):
     proc = pipe(['printf', 'hello'], ['gzip'], run('zcat'))
     assert proc.stdout.read().decode() == 'hello'
Пример #16
0
 def test_subprocess_failure(self):
     with self.assertRaises(subprocess.CalledProcessError):
         run('false').wait()
Пример #17
0
    def test_environment(self):
        env = run('env', env={'FOO': 'BAR'}).stdout.read().decode().split('\n')

        assert 'FOO=BAR' in env
Пример #18
0
    def test_copy_environment_opt_in(self):
        env = run('env', env=propagate_env({})).stdout.read().decode()

        assert env != ''
Пример #19
0
    def test_copy_environment_opt_in(self):
        env = run('env', env=propagate_env({})).stdout.read().decode()

        assert env != ''
Пример #20
0
    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
Пример #21
0
    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
Пример #22
0
    def test_empty_environment(self):
        env = run('env', env=empty_environ()).stdout.read().decode()

        assert env == ''