Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Egor Baturin committed Sep 4, 2024
1 parent 4194b0e commit 20c39a1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
-

### Changed
- Add support of property attributes in `__repr__` of `BaseMixin` ([#469](https://github.com/etna-team/etna/pull/469))
- Add support of property attributes in `__repr__` and `to_dict` of `BaseMixin` ([#469](https://github.com/etna-team/etna/pull/469))
-
-
-
Expand Down
11 changes: 11 additions & 0 deletions tests/test_core/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from etna.core.mixins import BaseMixin


class Dummy(BaseMixin):
def __init__(self, a: int = 1, b: int = 2):
self.a = a
self._b = b

@property
def b(self):
return self._b
6 changes: 6 additions & 0 deletions tests/test_core/test_repr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from tests.test_core.conftest import Dummy


def test_repr_public_property_private_attribute():
dummy = Dummy()
assert repr(dummy) == "Dummy(a = 1, b = 2, )"
9 changes: 9 additions & 0 deletions tests/test_core/test_set_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from etna.models import CatBoostMultiSegmentModel
from etna.pipeline import Pipeline
from etna.transforms import AddConstTransform
from tests.test_core.conftest import Dummy


def test_base_mixin_set_params_changes_params_estimator():
Expand Down Expand Up @@ -130,3 +131,11 @@ def test_update_nested_structure(nested_structure, keys, value, expected_result)
def test_update_nested_structure_fail(nested_structure, keys, value):
with pytest.raises(ValueError, match=f"Structure to update is .* with type .*"):
_ = BaseMixin._update_nested_structure(nested_structure, keys, value)


def test_to_dict_public_property_private_attribute():
dummy = Dummy()
dummy = dummy.set_params(**{"a": 10, "b": 20})
expected_dict = {"a": 10, "b": 20, "_target_": "tests.test_core.conftest.Dummy"}
obtained_dict = dummy.to_dict()
assert obtained_dict == expected_dict
6 changes: 6 additions & 0 deletions tests/test_core/test_to_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from etna.transforms import LogTransform
from etna.transforms.decomposition.change_points_based import RupturesChangePointsModel
from etna.transforms.decomposition.change_points_based import SklearnRegressionPerIntervalModel
from tests.test_core.conftest import Dummy


def ensemble_samples():
Expand Down Expand Up @@ -205,3 +206,8 @@ def __init__(self, a: _Dummy):
def test_warnings():
with pytest.warns(Warning, match="Some of external objects in input parameters could be not written in dict"):
_ = _InvalidParsing(_Dummy()).to_dict()


def test_to_dict_public_property_private_attribute():
dummy = Dummy()
assert dummy.to_dict() == {"a": 1, "b": 2, "_target_": "tests.test_core.conftest.Dummy"}

0 comments on commit 20c39a1

Please sign in to comment.