Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the equality operator of ExitCode #3940

Merged
merged 1 commit into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions aiida/engine/processes/exit_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ def format(self, **kwargs):

return ExitCode(self.status, message, self.invalidates_cache)

def __eq__(self, other):
return all(getattr(self, attr) == getattr(other, attr) for attr in ['status', 'message', 'invalidates_cache'])


# Set the defaults for the `ExitCode` attributes
ExitCode.__new__.__defaults__ = (0, None, False)
Expand Down
30 changes: 30 additions & 0 deletions tests/engine/processes/text_exit_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ def test_exit_code_construct():
assert exit_code.invalidates_cache == invalidates_cache


def test_exit_code_serializability():
"""Test that an `ExitCode` instance can be serialized and deserialized with `yaml`."""
import yaml

exit_code = ExitCode()
serialized = yaml.dump(exit_code)
deserialized = yaml.full_load(serialized)

assert deserialized == exit_code
assert isinstance(deserialized, ExitCode)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should check that the result is still an ExitCode instance here?


def test_exit_code_equality():
"""Test that the equality operator works properly."""
exit_code_origin = ExitCode(1, 'message', True)
Expand All @@ -42,6 +54,24 @@ def test_exit_code_equality():
assert exit_code_origin == exit_code_clone
assert exit_code_clone != exit_code_different

# Check default `ExitCode` also matches normal tuples
exit_code = ExitCode()
assert exit_code == (0, None, False)

assert exit_code != {}
assert exit_code != []
assert exit_code != ()
assert exit_code != (0)
assert exit_code != (None,)
assert exit_code != (0, None)
assert exit_code != [0, None, False]
assert exit_code != [0, None, False, 'test']

# `ExitCode` instances should match bare tuples as long as the content is the same
exit_code = ExitCode(1, 'message', True)
assert exit_code == (1, 'message', True)
assert exit_code != ()


def test_exit_code_template_message():
"""Test that an exit code with a templated message can be called to replace the parameters."""
Expand Down