def test_input(self): msg = 'This is a test' p = pwcli.RunProcess(['cat'], input=msg) self.assertEqual(p.returncode, 0) self.assertEqual(p.stdoutdata, msg) self.assertEqual(p.stderrdata, '')
def test_repr(self): msg = 'This is a test' p = pwcli.RunProcess(['cat'], input=msg) self.assertEqual(repr(p), 'RunProcess([\'cat\'], None, \'This is a test\')')
def test_stdout(self): msg = 'This is a test\nLine 2' p = pwcli.RunProcess(['/bin/echo', '-n', msg]) self.assertEqual(p.returncode, 0) self.assertEqual(p.stdoutdata, msg) self.assertEqual(p.stderrdata, '')
def test_nonzero_returncode(self): value = 177 python_cmd = 'import sys; sys.exit(%d)' % (value) p = pwcli.RunProcess(['python3', '-c', python_cmd]) self.assertEqual(p.returncode, value) self.assertEqual(p.stdoutdata, '') self.assertEqual(p.stderrdata, '')
def test_stderr(self): # Note: newlines in msg will fail for some reason msg = 'This is a test' python_cmd = 'import sys; sys.stderr.write("%s")' % (msg) p = pwcli.RunProcess(['python3', '-c', python_cmd]) self.assertEqual(p.returncode, 0) self.assertEqual(p.stdoutdata, '') self.assertEqual(p.stderrdata, msg)
def test_stdout_cb(self): msg = 'Line 1\nLine 2\nLine 3' cb_output = [] cb = lambda line: cb_output.append(line) p = pwcli.RunProcess(['/bin/echo', '-n', msg], stdout_cb=cb) self.assertEqual(p.returncode, 0) self.assertEqual(p.stdoutdata, msg) self.assertEqual(p.stderrdata, '') # strip newlines for easy comparison cb_output = [s.strip() for s in cb_output] self.assertEqual(msg.split('\n'), cb_output)
def test_str(self): p = pwcli.RunProcess(['/bin/echo', 'foo', 'bar']) self.assertEqual(str(p), 'RunProcess(\'/bin/echo foo bar\', None, None)')