From a351372fa6199d6e698839614c232eebb801c686 Mon Sep 17 00:00:00 2001 From: Ravleen-Solulab Date: Tue, 15 Oct 2024 11:30:00 +0530 Subject: [PATCH] check runs --- .../tests/states/test_base.py | 28 ++++++++++--------- .../tests/states/test_decision_request.py | 1 - .../tests/states/test_handle_failed_tx.py | 2 +- .../tests/states/test_order_subscription.py | 4 ++- .../tests/states/test_randomness.py | 1 + .../tests/states/test_sampling.py | 1 + 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/packages/valory/skills/decision_maker_abci/tests/states/test_base.py b/packages/valory/skills/decision_maker_abci/tests/states/test_base.py index 4281a3679..89eda8386 100644 --- a/packages/valory/skills/decision_maker_abci/tests/states/test_base.py +++ b/packages/valory/skills/decision_maker_abci/tests/states/test_base.py @@ -25,15 +25,15 @@ import pytest -from packages.valory.skills.decision_maker_abci.policy import EGreedyPolicy +from packages.valory.skills.decision_maker_abci.policy import ( + AccuracyInfo, + EGreedyPolicy, +) from packages.valory.skills.decision_maker_abci.states.base import ( Event, SynchronizedData, TxPreparationRound, ) -from packages.valory.skills.market_manager_abci.rounds import ( - SynchronizedData as MarketManagerSyncedData, -) from packages.valory.skills.mech_interact_abci.states.base import MechMetadata @@ -193,15 +193,17 @@ def test_mech_requests(sync_data, mocked_db): def test_weighted_accuracy(sync_data, mocked_db): """Test the weighted_accuracy property.""" - mocked_db.get_strict.return_value = json.dumps( - {"epsilon": 0.1, "weighted_accuracy": {"tool1": 0.8}} + selected_mech_tool = "tool1" + policy_db_name = "policy" + policy_mock = EGreedyPolicy( + eps=0.1, accuracy_store={selected_mech_tool: AccuracyInfo(requests=1)} + ).serialize() + mocked_db.get_strict = lambda name: ( + policy_mock if name == policy_db_name else selected_mech_tool ) - mocked_db.get.return_value = "tool1" - sync_data._policy = None # Reset cached value - policy = EGreedyPolicy.deserialize(mocked_db.get_strict.return_value) - - # Access the weighted accuracy correctly - assert sync_data.weighted_accuracy == policy.weighted_accuracy["tool1"] + policy = EGreedyPolicy.deserialize(policy_mock) + assert selected_mech_tool in policy.weighted_accuracy + assert sync_data.weighted_accuracy == policy.weighted_accuracy[selected_mech_tool] def test_end_block(mocked_db): @@ -223,4 +225,4 @@ def test_end_block(mocked_db): TxPreparationRound, "end_block", return_value=(mocked_sync_data, Event.NONE) ): result = round_instance.end_block() - assert result == (mocked_sync_data, Event.NONE) + assert result == (mocked_sync_data, Event.NONE) \ No newline at end of file diff --git a/packages/valory/skills/decision_maker_abci/tests/states/test_decision_request.py b/packages/valory/skills/decision_maker_abci/tests/states/test_decision_request.py index ef1bd1a1c..e1a9003a3 100644 --- a/packages/valory/skills/decision_maker_abci/tests/states/test_decision_request.py +++ b/packages/valory/skills/decision_maker_abci/tests/states/test_decision_request.py @@ -25,7 +25,6 @@ from typing import Any, Callable, Dict, FrozenSet, Hashable, List, Mapping, Optional from unittest import mock - import pytest from packages.valory.skills.abstract_round_abci.base import BaseTxPayload diff --git a/packages/valory/skills/decision_maker_abci/tests/states/test_handle_failed_tx.py b/packages/valory/skills/decision_maker_abci/tests/states/test_handle_failed_tx.py index 8f2f76215..b88bad2cc 100644 --- a/packages/valory/skills/decision_maker_abci/tests/states/test_handle_failed_tx.py +++ b/packages/valory/skills/decision_maker_abci/tests/states/test_handle_failed_tx.py @@ -21,7 +21,7 @@ """This package contains the tests for Decision Maker""" import json -from typing import Any, Callable, Dict, FrozenSet, List, Mapping, Type +from typing import Any, Callable, Dict, FrozenSet, Type from unittest.mock import MagicMock import pytest diff --git a/packages/valory/skills/decision_maker_abci/tests/states/test_order_subscription.py b/packages/valory/skills/decision_maker_abci/tests/states/test_order_subscription.py index d030384b7..ac0502af8 100644 --- a/packages/valory/skills/decision_maker_abci/tests/states/test_order_subscription.py +++ b/packages/valory/skills/decision_maker_abci/tests/states/test_order_subscription.py @@ -33,8 +33,10 @@ # Dummy values for testing class MockSynchronizedData(BaseSynchronizedData): - """The class for testing """ + """The class for testing""" + def __init__(self, db): + """Mock""" super().__init__(db=db) self.agreement_id = "dummy_agreement_id" diff --git a/packages/valory/skills/decision_maker_abci/tests/states/test_randomness.py b/packages/valory/skills/decision_maker_abci/tests/states/test_randomness.py index a3e45c2fd..fe5683cc2 100644 --- a/packages/valory/skills/decision_maker_abci/tests/states/test_randomness.py +++ b/packages/valory/skills/decision_maker_abci/tests/states/test_randomness.py @@ -43,6 +43,7 @@ def __init__(self): class TestRandomnessRound: """The class for testing Randomness Round""" + @pytest.fixture def setup_randomness_round(self): """Fixture to set up a RandomnessRound instance.""" diff --git a/packages/valory/skills/decision_maker_abci/tests/states/test_sampling.py b/packages/valory/skills/decision_maker_abci/tests/states/test_sampling.py index 0bf13c8b0..8f0f462e7 100644 --- a/packages/valory/skills/decision_maker_abci/tests/states/test_sampling.py +++ b/packages/valory/skills/decision_maker_abci/tests/states/test_sampling.py @@ -50,6 +50,7 @@ def __init__(self): class TestSamplingRound: """The class for testing Sampling Round""" + @pytest.fixture def setup_sampling_round(self): """Fixture to set up a SamplingRound instance."""