Ejemplo n.º 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'
Ejemplo n.º 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'
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 9
0
 def test_pass_subprocess_to_pipe(self):
     proc = pipe(['printf', 'hello'], ['gzip'], run('zcat'))
     assert proc.stdout.read().decode() == 'hello'
Ejemplo n.º 10
0
 def test_subprocess_failure(self):
     with self.assertRaises(subprocess.CalledProcessError):
         run('false').wait()
Ejemplo n.º 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
Ejemplo n.º 12
0
    def test_empty_environment_by_default(self):
        env = run('env').stdout.read().decode()

        assert env == ''
Ejemplo n.º 13
0
    def test_empty_environment_by_default(self):
        env = run('env').stdout.read().decode()

        assert env == ''
Ejemplo n.º 14
0
    def test_environment(self):
        env = run('env', env={'FOO': 'BAR'}).stdout.read().decode().split('\n')

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

        assert 'FOO=BAR' in env
Ejemplo n.º 18
0
    def test_copy_environment_opt_in(self):
        env = run('env', env=propagate_env({})).stdout.read().decode()

        assert env != ''
Ejemplo n.º 19
0
    def test_copy_environment_opt_in(self):
        env = run('env', env=propagate_env({})).stdout.read().decode()

        assert env != ''
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 22
0
    def test_empty_environment(self):
        env = run('env', env=empty_environ()).stdout.read().decode()

        assert env == ''