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

Normalized test initialization in dl_formula #5

Merged
merged 2 commits into from
Dec 14, 2023
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
4 changes: 3 additions & 1 deletion lib/dl_api_lib_testing/dl_api_lib_testing/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
from dl_api_lib.loader import ApiLibraryConfig
from dl_configs.connector_availability import ConnectorAvailabilityConfigSettings
from dl_core_testing.configuration import CoreTestEnvironmentConfigurationBase
from dl_formula_testing.configuration import FormulaTestEnvironmentConfiguration


@attr.s(kw_only=True)
class ApiTestEnvironmentConfiguration:
core_test_config: CoreTestEnvironmentConfigurationBase = attr.ib()
core_test_config: CoreTestEnvironmentConfigurationBase = attr.ib(factory=CoreTestEnvironmentConfigurationBase)
formula_test_config: FormulaTestEnvironmentConfiguration = attr.ib(factory=FormulaTestEnvironmentConfiguration)

ext_query_executer_secret_key: str = attr.ib()

Expand Down
2 changes: 2 additions & 0 deletions lib/dl_api_lib_testing/dl_api_lib_testing/initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
from dl_api_lib.loader import load_api_lib
from dl_api_lib_testing.configuration import ApiTestEnvironmentConfiguration
from dl_core_testing.initialization import initialize_core_test
from dl_formula_testing.initialization import initialize_formula_test


def initialize_api_lib_test(pytest_config: Config, api_test_config: ApiTestEnvironmentConfiguration) -> None:
load_api_lib(api_lib_config=api_test_config.get_api_library_config())
initialize_core_test(pytest_config=pytest_config, core_test_config=api_test_config.core_test_config)
initialize_formula_test(pytest_config=pytest_config, formula_test_config=api_test_config.formula_test_config)
17 changes: 11 additions & 6 deletions lib/dl_formula/dl_formula_tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import pytest

from dl_formula.loader import load_formula_lib
from dl_formula.parser.base import FormulaParser
from dl_formula.parser.factory import (
ParserType,
get_parser,
)
from dl_formula_testing.configuration import FormulaTestEnvironmentConfiguration
from dl_formula_testing.forced_literal import forced_literal_use # noqa
from dl_formula_testing.initialization import initialize_formula_test


PARSERS = (ParserType.antlr_py,)


def pytest_configure(config): # noqa
initialize_formula_test(
pytest_config=config,
formula_test_config=FormulaTestEnvironmentConfiguration(
formula_connector_ep_names=("clickhouse",),
),
)


@pytest.fixture(
scope="session",
params=PARSERS,
Expand All @@ -20,8 +30,3 @@
def parser(request) -> FormulaParser:
parser_type = request.param
return get_parser(parser_type=parser_type)


@pytest.fixture(scope="session", autouse=True)
def loaded_bi_libraries() -> None:
load_formula_lib()
2 changes: 1 addition & 1 deletion lib/dl_formula/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dynamic-enum = {path = "../dynamic_enum"}
pytest = ">=7.2.2"
pyodbc = ">=4.0.35"
python-dateutil = ">=2.8.2"

datalens-connector-clickhouse = {path = "../dl_connector_clickhouse"}

[[tool.mypy.overrides]]
module = "ciso8601"
Expand Down
20 changes: 20 additions & 0 deletions lib/dl_formula_testing/dl_formula_testing/configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from __future__ import annotations

from typing import (
Collection,
Optional,
)

import attr

from dl_formula.loader import FormulaLibraryConfig


@attr.s(kw_only=True)
class FormulaTestEnvironmentConfiguration:
formula_connector_ep_names: Optional[Collection[str]] = attr.ib(default=None)

def get_formula_library_config(self) -> FormulaLibraryConfig:
return FormulaLibraryConfig(
formula_connector_ep_names=self.formula_connector_ep_names,
)
10 changes: 10 additions & 0 deletions lib/dl_formula_testing/dl_formula_testing/initialization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pytest import Config

from dl_db_testing.loader import load_db_testing_lib
from dl_formula.loader import load_formula_lib
from dl_formula_testing.configuration import FormulaTestEnvironmentConfiguration


def initialize_formula_test(pytest_config: Config, formula_test_config: FormulaTestEnvironmentConfiguration) -> None:
load_db_testing_lib()
load_formula_lib(formula_lib_config=formula_test_config.get_formula_library_config())
Loading