Skip to content

Commit

Permalink
Normalized test initialization in dl_formula
Browse files Browse the repository at this point in the history
  • Loading branch information
altvod committed Oct 9, 2023
1 parent 19078d7 commit 4e94744
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
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=(),
),
)


@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()
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())

0 comments on commit 4e94744

Please sign in to comment.