def test_run_cmd_with_errors(self): """Invoke a command with errors.""" try: code, out, err = run_cmd(["ls", "-AF", "/this/does/not/exist"]) except Exception, e: self.assertEqual( "ls terminated with exit code: 2\nls: cannot access " "/this/does/not/exist: No such file or directory\n", e.args[0])
def test_run_cmd_with_errors_and_ignore_exit_code(self): """Invoke a command with errors but ignore the exit code.""" code, out, err = run_cmd( ["ls", "-AF", "/this/does/not/exist"], ignore_exit_code=True) self.assertEqual(2, code) self.assertEqual("", out) self.assertEqual("ls: cannot access /this/does/not/exist: No such " "file or directory\n", err)
def test_run_cmd_with_errors_and_ignore_exit_code(self): """Invoke a command with errors but ignore the exit code.""" code, out, err = run_cmd(["ls", "-AF", "/this/does/not/exist"], ignore_exit_code=True) self.assertEqual(2, code) self.assertEqual("", out) self.assertEqual( "ls: cannot access /this/does/not/exist: No such " "file or directory\n", err)
def test_run_cmd_with_errors(self): """Invoke a command with errors.""" # The expected error message varies between Linux and OSX. if sys.platform == 'darwin': expected_error = ('ls terminated with exit code: 1\nls: ' '/this/does/not/exist: No such file or directory\n') else: expected_error = ('ls terminated with exit code: 2\nls: cannot ' 'access /this/does/not/exist: No such file or directory\n') try: code, out, err = run_cmd(["ls", "-AF", "/this/does/not/exist"]) except Exception, e: self.assertEqual(expected_error, e.args[0])
def test_run_cmd_with_errors(self): """Invoke a command with errors.""" # The expected error message varies between Linux and OSX. if sys.platform == 'darwin': expected_error = ( 'ls terminated with exit code: 1\nls: ' '/this/does/not/exist: No such file or directory\n') else: expected_error = ( 'ls terminated with exit code: 2\nls: cannot ' 'access /this/does/not/exist: No such file or directory\n') try: code, out, err = run_cmd(["ls", "-AF", "/this/does/not/exist"]) except Exception, e: self.assertEqual(expected_error, e.args[0])
def test_run_cmd_with_errors_and_ignore_exit_code(self): """Invoke a command with errors but ignore the exit code.""" # Both the expected exit code and error message vary between Linux and # OSX. if sys.platform == 'darwin': expected_code = 1 expected_error = ("ls: /this/does/not/exist: No such file or " "directory\n") else: expected_code = 2 expected_error = ("ls: cannot access /this/does/not/exist: No such" " file or directory\n") code, out, err = run_cmd( ["ls", "-AF", "/this/does/not/exist"], ignore_exit_code=True) self.assertEqual(expected_code, code) self.assertEqual("", out) self.assertEqual(expected_error, err)
def test_run_cmd_with_errors_and_ignore_exit_code(self): """Invoke a command with errors but ignore the exit code.""" # Both the expected exit code and error message vary between Linux and # OSX. if sys.platform == 'darwin': expected_code = 1 expected_error = ("ls: /this/does/not/exist: No such file or " "directory\n") else: expected_code = 2 expected_error = ("ls: cannot access /this/does/not/exist: No such" " file or directory\n") code, out, err = run_cmd(["ls", "-AF", "/this/does/not/exist"], ignore_exit_code=True) self.assertEqual(expected_code, code) self.assertEqual("", out) self.assertEqual(expected_error, err)
def test_run_cmd_with_success(self): """Invoke a command without errors.""" code, out, err = run_cmd(["echo", "-n", "Hello world!"]) self.assertEqual(0, code) self.assertEqual("Hello world!", out) self.assertEqual("", err)