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

Implemented __eq__ function for Kovats and CubicSpline via ComputationMethod class #52

Merged
merged 6 commits into from
Jul 15, 2021
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: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Added `__eq__` to `PandasData` and `MatchMSData` [#51](https://github.com/RECETOX/RIAssigner/pull/51)
- Added `__eq__` to `ComputationMethod` class and subclasses [#52](https://github.com/RECETOX/RIAssigner/pull/52)
- data/PandasData.py: Added reading `tsv` files. [#49](https://github.com/RECETOX/RIAssigner/pull/49)
### Changed
- data/MatchMSData.py: `_assign_ri_value` now converts all values to float and stores them as string in metadata field
Expand All @@ -19,4 +20,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Computing Kovats retention index [#25](https://github.com/RECETOX/RIAssigner/pull/25)
- Computing RI based on cubic splines [#33](https://github.com/RECETOX/RIAssigner/pull/33)
- Added CI actions to GitHub [#43](https://github.com/RECETOX/RIAssigner/pull/43)
- Added writing data back to memory for `MSP`, `CSV` and `tsv` files [#7](https://github.com/RECETOX/RIAssigner/pull/7)[#14](https://github.com/RECETOX/RIAssigner/pull/14)[#19](https://github.com/RECETOX/RIAssigner/pull/19)
- Added writing data back to memory for `MSP`, `CSV` and `tsv` files [#7](https://github.com/RECETOX/RIAssigner/pull/7)[#14](https://github.com/RECETOX/RIAssigner/pull/14)[#19](https://github.com/RECETOX/RIAssigner/pull/19)
3 changes: 3 additions & 0 deletions RIAssigner/compute/ComputationMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ def _check_data_args(self, query, reference):
"""
assert query is not None, "Query data is 'None'."
assert reference is not None, "Reference data is 'None'."

def __eq__(self, o: object) -> bool:
return type(o) == type(self)
2 changes: 2 additions & 0 deletions RIAssigner/compute/__init__.py
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",
]
24 changes: 24 additions & 0 deletions tests/test_compute_ComputationMethod.py
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")