Skip to content

Commit

Permalink
Mocking methods of the view related to aggregations to make them comp…
Browse files Browse the repository at this point in the history
…liant to tests.
  • Loading branch information
PatrykWyzgowski committed Jul 19, 2024
1 parent 0b7e50a commit 5511729
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tests/unit/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from dbally.iql import IQLQuery
from dbally.iql.syntax import FunctionCall
from dbally.views.exposed_functions import ExposedFunction, MethodParamWithTyping
from tests.unit.mocks import MockIQLGenerator, MockLLM, MockSimilarityIndex, MockViewBase, MockViewSelector
from tests.unit.mocks import MockIQLGenerator, MockLLM, MockSimilarityIndex, MockViewBase, MockViewSelector, \
MockAggregationFormatter


class MockView1(MockViewBase):
Expand Down Expand Up @@ -62,6 +63,12 @@ def list_filters(self) -> List[ExposedFunction]:
def get_iql_generator(self, *_, **__) -> MockIQLGenerator:
return MockIQLGenerator(IQLQuery(FunctionCall("test_filter", []), "test_filter()"))

def list_aggregations(self) -> List[ExposedFunction]:
return [ExposedFunction("test_aggregation", "", [])]

def get_agg_formatter(self, *_, **__) -> MockAggregationFormatter:
return MockAggregationFormatter(IQLQuery(FunctionCall("test_aggregation", []), "test_aggregation()"))


@pytest.fixture(name="similarity_classes")
def mock_similarity_classes() -> (
Expand Down Expand Up @@ -291,7 +298,7 @@ async def test_ask_view_selection_single_view() -> None:
result = await collection.ask("Mock question")
assert result.view_name == "MockViewWithResults"
assert result.results == [{"foo": "bar"}]
assert result.context == {"baz": "qux", "iql": "test_filter()"}
assert result.context == {"baz": "qux", "iql": {'aggregation': 'test_aggregation()', 'filters': 'test_filter()'}}


async def test_ask_view_selection_multiple_views() -> None:
Expand All @@ -312,7 +319,7 @@ async def test_ask_view_selection_multiple_views() -> None:
result = await collection.ask("Mock question")
assert result.view_name == "MockViewWithResults"
assert result.results == [{"foo": "bar"}]
assert result.context == {"baz": "qux", "iql": "test_filter()"}
assert result.context == {"baz": "qux", "iql": {'aggregation': 'test_aggregation()', 'filters': 'test_filter()'}}


async def test_ask_view_selection_no_views() -> None:
Expand Down

0 comments on commit 5511729

Please sign in to comment.