Skip to content

Commit

Permalink
Merge pull request #52 from hechth/50_eq_computation
Browse files Browse the repository at this point in the history
Implemented __eq__ function for Kovats and CubicSpline via ComputationMethod class
  • Loading branch information
martenson authored Jul 15, 2021
2 parents 140de7c + 4402132 commit 699abf8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
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")

0 comments on commit 699abf8

Please sign in to comment.