Skip to content

Commit eccf075

Browse files
authored
Add stdin to hash and use hash for comparing (#52)
1 parent b3a7526 commit eccf075

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

exec_helpers/exec_result.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,7 @@ def __str__(self): # type: () -> str
425425

426426
def __eq__(self, other): # type: (typing.Any) -> bool
427427
"""Comparision."""
428-
return all(
429-
(
430-
getattr(self, val) == getattr(other, val)
431-
for val in ['cmd', 'stdout', 'stderr', 'exit_code']
432-
)
433-
)
428+
return hash(self) == hash(other)
434429

435430
def __ne__(self, other): # type: (typing.Any) -> bool
436431
"""Comparision."""
@@ -440,6 +435,6 @@ def __hash__(self):
440435
"""Hash for usage as dict key and in sets."""
441436
return hash(
442437
(
443-
self.__class__, self.cmd, self.stdout, self.stderr,
438+
self.__class__, self.cmd, self.stdin, self.stdout, self.stderr,
444439
self.exit_code
445440
))

test/test_exec_result.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def test_create_minimal(self, logger):
105105
(
106106
exec_helpers.ExecResult,
107107
cmd,
108+
None,
108109
(),
109110
(),
110111
exec_helpers.ExitCodes.EX_INVALID

test/test_subprocess_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ def test_006_check_stdin_bytearray(
564564
): # type: (...) -> None
565565
stdin = bytearray(b'this is a line')
566566

567-
popen_obj, exp_result = self.prepare_close(popen, cmd=print_stdin, stdout_override=[stdin])
567+
popen_obj, exp_result = self.prepare_close(popen, cmd=print_stdin, stdout_override=[bytes(l) for l in stdin])
568568

569569
stdin_mock = mock.Mock()
570570
popen_obj.attach_mock(stdin_mock, 'stdin')

0 commit comments

Comments
 (0)