-
Notifications
You must be signed in to change notification settings - Fork 192
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
ExitCode
: make the exit message parameterizable through templates
#3824
Merged
sphuber
merged 4 commits into
aiidateam:develop
from
sphuber:feature/2644/exit-code-message-template
Mar 25, 2020
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
402f828
`ExitCode`: make the exit message parameterizable through templates
sphuber 9051177
Change formatting `ExitCode` from `__call__` to `format`
sphuber 4ec0662
Restore `ExitCode` to being a namedtuple
sphuber 27d67ac
Merge branch 'develop' into feature/2644/exit-code-message-template
sphuber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Tests for `aiida.engine.processes.exit_code.ExitCode`.""" | ||
import pytest | ||
|
||
from aiida.engine import ExitCode | ||
|
||
|
||
def test_exit_code_defaults(): | ||
"""Test that the defaults are properly set.""" | ||
exit_code = ExitCode() | ||
assert exit_code.status == 0 | ||
assert exit_code.message is None | ||
assert exit_code.invalidates_cache is False | ||
|
||
|
||
def test_exit_code_construct(): | ||
"""Test that the constructor allows to override defaults.""" | ||
status = 418 | ||
message = 'I am a teapot' | ||
invalidates_cache = True | ||
|
||
exit_code = ExitCode(status, message, invalidates_cache) | ||
assert exit_code.status == status | ||
assert exit_code.message == message | ||
assert exit_code.invalidates_cache == invalidates_cache | ||
|
||
|
||
def test_exit_code_equality(): | ||
"""Test that the equality operator works properly.""" | ||
exit_code_origin = ExitCode(1, 'message', True) | ||
exit_code_clone = ExitCode(1, 'message', True) | ||
exit_code_different = ExitCode(2, 'message', True) | ||
|
||
assert exit_code_origin == exit_code_clone | ||
assert exit_code_clone != exit_code_different | ||
|
||
|
||
def test_exit_code_template_message(): | ||
"""Test that an exit code with a templated message can be called to replace the parameters.""" | ||
message_template = 'Wrong parameter {parameter}' | ||
parameter_name = 'some_parameter' | ||
|
||
exit_code_base = ExitCode(418, message_template) | ||
exit_code_called = exit_code_base.format(parameter=parameter_name) | ||
|
||
# Incorrect placeholder | ||
with pytest.raises(ValueError): | ||
exit_code_base.format(non_existing_parameter=parameter_name) | ||
|
||
# Missing placeholders | ||
with pytest.raises(ValueError): | ||
exit_code_base.format() | ||
|
||
assert exit_code_base != exit_code_called # Calling the exit code should return a new instance | ||
assert exit_code_called.message == message_template.format(parameter=parameter_name) | ||
|
||
|
||
def test_exit_code_expand_tuple(): | ||
"""Test that an exit code instance can be expanded in its attributes like a tuple.""" | ||
status = 418 | ||
message = 'I am a teapot' | ||
invalidates_cache = True | ||
|
||
status_exp, message_exp, invalidates_cache_exp = ExitCode(418, message, True) | ||
|
||
assert status == status_exp | ||
assert message == message_exp | ||
assert invalidates_cache == invalidates_cache_exp |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is technically a change in interface, because
namedtuple
exposes all the methods of the underlyingtuple
. For example, one could doI'm not sure if any of these "accidental features" is used anywhere, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Do you know of a way to make a simple class replicate the exact interface/behavior of a named tuple? If not, we might have to put this in
2.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. Also this functionality is probably not super critical, depending on when a
2.0
release is scheduled.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behold, a thing of beauty:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.