-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove DI framework (GSI-536) (#78) - removes the DI framework. - removes dependency_injector from dependencies - example app shown DI without dedicated framework - added tests for the CLI of the example app This is a breaking change. Bumps version to 2.0.0. * Tools for Structured Logging (GSI 510) (#77) * Add basic logging tools * Use configurable class rather than instance * Add service name and instance id to config * Explicitly get service/instance from log record * Use capitalized LogLevel literal for log_level arg * Add __all__ and rename Adapter to StructuredLogger * Add RecordCompiler handler * Add log_format config option * Bump version from 1.2.0 -> 2.0.0 * Add tests * remove DI framework (GSI-536) (#78) - removes the DI framework. - removes dependency_injector from dependencies - example app shown DI without dedicated framework - added tests for the CLI of the example app This is a breaking change. Bumps version to 2.0.0. * Rename function and remove second config in fixture * Integrate Kersten's suggestions for simpler config --------- Co-authored-by: TheByronHimes <TheByronHimes@gmail.com> Co-authored-by: Kersten Breuer <kersten-breuer@outlook.com> * Upgrade pytest-asyncio (GSI-534) (#80) * Remove cap on pytest-asyncio and update lock files * Use module-scoped kafka fixture in correlation tests Place the publishing tests at the end of the module, rather than in the middle. * Specify minimum ver so lower version doesn't get installed --------- Co-authored-by: TheByronHimes <TheByronHimes@gmail.com> * Log all config (GSI-546) (#81) * Log complete config when configuring logging * Make no-secrets log test more robust * Add suggested changes --------- Co-authored-by: TheByronHimes <TheByronHimes@gmail.com> --------- Co-authored-by: Kersten Breuer <kersten-breuer@outlook.com> Co-authored-by: TheByronHimes <TheByronHimes@gmail.com>
- Loading branch information
1 parent
412568e
commit 5c619ef
Showing
23 changed files
with
970 additions
and
1,434 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Copyright 2021 - 2023 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln | ||
# for the German Human Genome-Phenome Archive (GHGA) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
"""Test the stream_calc app via the CLI.""" | ||
|
||
import os | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
|
||
from func_timeout import func_timeout | ||
|
||
from hexkit.providers.akafka.testutils import KafkaFixture, kafka_fixture # noqa:F401 | ||
from sc_tests.integration.test_event_api import ( | ||
CASES, | ||
check_problem_outcomes, | ||
submit_test_problems, | ||
) | ||
|
||
APP_DIR = Path(__file__).parent.parent.parent.absolute() | ||
|
||
|
||
def test_cli(kafka_fixture: KafkaFixture, monkeypatch): # noqa:F811 | ||
"""Test the stream_calc app via the CLI.""" | ||
os.chdir(APP_DIR) | ||
monkeypatch.setenv( | ||
name="STREAM_CALC_KAFKA_SERVERS", value=f'["{kafka_fixture.kafka_servers[0]}"]' | ||
) | ||
monkeypatch.setenv( | ||
name="PYTHONPATH", value=(os.environ.get("PYTHONPATH", "") + f":{APP_DIR}") | ||
) | ||
|
||
submit_test_problems(CASES, kafka_server=kafka_fixture.kafka_servers[0]) | ||
|
||
with subprocess.Popen( | ||
args=["-m", "stream_calc"], | ||
executable=sys.executable, | ||
) as process: | ||
func_timeout( | ||
10, | ||
check_problem_outcomes, | ||
kwargs={"cases": CASES, "kafka_server": kafka_fixture.kafka_servers[0]}, | ||
) | ||
process.terminate() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Copyright 2021 - 2023 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln | ||
# for the German Human Genome-Phenome Archive (GHGA) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Module hosting the dependency injection container.""" | ||
|
||
from collections.abc import AsyncGenerator | ||
from contextlib import asynccontextmanager | ||
|
||
from hexkit.providers.akafka import KafkaEventPublisher, KafkaEventSubscriber | ||
from stream_calc.config import Config | ||
from stream_calc.core.calc import StreamCalculator | ||
from stream_calc.ports.problem_receiver import ArithProblemHandlerPort | ||
from stream_calc.translators.eventpub import EventResultEmitter | ||
from stream_calc.translators.eventsub import EventProblemReceiver | ||
|
||
|
||
@asynccontextmanager | ||
async def prepare_core( | ||
*, | ||
config: Config, | ||
) -> AsyncGenerator[ArithProblemHandlerPort, None]: | ||
"""Constructs and initializes all core components and their outbound dependencies.""" | ||
|
||
async with KafkaEventPublisher.construct(config=config) as event_pub_provider: | ||
result_emitter = EventResultEmitter( | ||
config=config, event_publisher=event_pub_provider | ||
) | ||
|
||
yield StreamCalculator(result_emitter=result_emitter) | ||
|
||
|
||
@asynccontextmanager | ||
async def prepare_event_subscriber( | ||
*, | ||
config: Config, | ||
) -> AsyncGenerator[KafkaEventSubscriber, None]: | ||
"""Construct and initialize an event subscriber with all its dependencies.""" | ||
async with prepare_core(config=config) as stream_calculator: | ||
event_problem_receiver = EventProblemReceiver( | ||
config=config, problem_handler=stream_calculator | ||
) | ||
|
||
async with KafkaEventSubscriber.construct( | ||
config=config, translator=event_problem_receiver | ||
) as event_subscriber: | ||
yield event_subscriber |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.