-
Notifications
You must be signed in to change notification settings - Fork 6
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
Implemented __eq__ function for Kovats and CubicSpline via ComputationMethod class #52
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dc4dd56
Added ComputationMethod class to package
hechth 9533841
Implemented tests for __eq__ function for CubicSpline & Kovats class
hechth d3af97f
Implemented __eq__ in ComputationMethod base class
hechth b6a909a
Added updates to changelog
hechth 87c116b
Changed type check to be more strict
hechth 4402132
Merge branch 'main' into 50_eq_computation
hechth 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import logging | ||
|
||
from .ComputationMethod import ComputationMethod | ||
from .CubicSpline import CubicSpline | ||
from .Kovats import Kovats | ||
|
||
logging.getLogger(__name__).addHandler(logging.NullHandler()) | ||
|
||
__all__ = [ | ||
"ComputationMethod", | ||
"CubicSpline", | ||
"Kovats", | ||
] |
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,24 @@ | ||
import pytest | ||
|
||
from RIAssigner.compute import ComputationMethod, CubicSpline, Kovats | ||
|
||
|
||
@pytest.mark.parametrize('this, other, expected', [ | ||
[CubicSpline(), CubicSpline(), True], | ||
[Kovats(), Kovats(), True], | ||
[CubicSpline(), Kovats(), False], | ||
[Kovats(), object(), False], | ||
[CubicSpline(), object(), False], | ||
]) | ||
def test_equal(this, other, expected): | ||
actual = (this == other) | ||
assert actual == expected | ||
|
||
|
||
def test_abc(): | ||
with pytest.raises(TypeError) as exception: | ||
method = ComputationMethod() | ||
|
||
message = exception.value.args[0] | ||
assert exception.typename == "TypeError" | ||
assert str(message).startswith("Can't instantiate abstract class ComputationMethod with abstract methods") |
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.
Just a note to consider - if in the future you will possibly use nested inheritance
(e.g. create a new Computation Method
XY
fromKovats
, where you, for example, change only one of its methods).Then, this kind of equality check
Kovats() == XY()
returnsTrue
, becauseisinstance
considers also inheritance. Is that desired behavior? (See this SO post for more detials)A way to change this is to explicitelly compare their types, i.e.
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.
Thanks for the comment! My linter complains about the type comparison with
type(o) == type(self)
and I am aware of the subclassing issue.I don't think there will be computation methods derived from any of the derived classes, but this is good to know. I might violate the linter and change the type check to this one which seems to be stricter.
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.
What is the linter's output?
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.
Using type() instead of isinstance() for a typecheck.