Skip to content

Commit

Permalink
fix python compatibility for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pgombar committed Aug 8, 2019
1 parent dfb53d6 commit 9ebc2e7
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions tests/utils/test_shell_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,23 @@ def test_run_command_it_should_raise_an_exception_file_not_found(self):

ex = context_manager.exception
self.assertEquals(subprocess.CalledProcessError, type(ex))
self.assertEquals((expected_returncode, ["ls", "nonexistent_file"]), ex.args)
self.assertEquals(expected_returncode, ex.returncode)
self.assertEquals(command, ex.cmd)

self.assertEquals(mock_logger.error.call_count, 2)

logged_error_first = "Command: [{0}], return code: [{1}], " \
"stdout: [] stderr: [{2}]".format(command, expected_returncode,
"ls: cannot access 'nonexistent_file': "
"No such file or directory\n")
logged_error_first = u"Command: [{0}], return code: [{1}], " \
u"stdout: [] stderr: [{2}]".format(command, expected_returncode,
"ls: cannot access 'nonexistent_file': "
"No such file or directory\n")
self.assertEquals(mock_logger.error.call_args_list[0][0][0], logged_error_first)

logged_error_second = "Command [{0}] raised unexpected exception: " \
"[Command '{0}' returned non-zero exit status {1}.]".format(command,
logged_error_second = u"Command [{0}] raised unexpected exception: " \
u"[Command '{0}' returned non-zero exit status {1}]".format(command,
expected_returncode)
self.assertEquals(mock_logger.error.call_args_list[1][0][0], logged_error_second)
# The exception message has a "." at the end of the string, depending on the Python version,
# not using equals.
self.assertIn(logged_error_second, mock_logger.error.call_args_list[1][0][0])


if __name__ == '__main__':
Expand Down

0 comments on commit 9ebc2e7

Please sign in to comment.