Skip to content

Commit

Permalink
Fix pytests (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
dostuffthatmatters committed Jan 19, 2024
1 parent 99ea1c2 commit 82f8939
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ jobs:
# run test suite
- name: Run pytests
run: |
pytest -m "quick" --verbose --cov=src tests/
pytest -m "ci" --verbose --cov=src tests/
11 changes: 7 additions & 4 deletions src/utils/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def date_range(
def sdc_covers_the_full_day(
sdc: em27_metadata.types.SensorDataContext,
) -> bool:
return (
sdc.from_datetime.time() == datetime.time.min and
sdc.to_datetime.time() == datetime.time.max.replace(microsecond=0)
)
return ((
sdc.from_datetime.time().replace(microsecond=0)
== datetime.time.min.replace(microsecond=0)
) and (
sdc.to_datetime.time().replace(microsecond=0)
== datetime.time.max.replace(microsecond=0)
))
42 changes: 25 additions & 17 deletions tests/retrieval/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import em27_metadata
import tum_esm_utils
import multiprocessing
from src import types
from src import types, utils
from tests.fixtures import (
wrap_test_with_mainlock, download_sample_data, provide_config_template,
remove_temporary_retrieval_data
Expand Down Expand Up @@ -87,6 +87,13 @@ def provide_container_factory(
)


@pytest.mark.order(3)
@pytest.mark.quick
def test_sdc_covers_the_full_day() -> None:
for sdc in SENSOR_DATA_CONTEXTS:
assert utils.functions.sdc_covers_the_full_day(sdc)


# this test will only mock the retrieval algorithm
@pytest.mark.order(4)
@pytest.mark.ci
Expand Down Expand Up @@ -123,6 +130,22 @@ def test_container_lifecycle_complete(
)


def run_session(
session: types.RetrievalSession, config: types.Config,
only_run_mock_retrieval: bool
) -> None:
retrieval.session.process_session.run(
config,
session,
test_mode=only_run_mock_retrieval,
)
_assert_output_correctness(
session.retrieval_algorithm,
session.atmospheric_profile_model,
session.ctx,
)


def _run(
config: types.Config,
container_factory: retrieval.dispatching.container_factory.ContainerFactory,
Expand All @@ -135,21 +158,6 @@ def _run(
NUMBER_OF_JOBS = len(SENSOR_DATA_CONTEXTS) * 2 * 3
print(f"Running {NUMBER_OF_JOBS} retrieval jobs in parallel")

def run_session(
session: types.RetrievalSession,
config: types.Config,
) -> None:
retrieval.session.process_session.run(
config,
session,
test_mode=only_run_mock_retrieval,
)
_assert_output_correctness(
session.retrieval_algorithm,
session.atmospheric_profile_model,
session.ctx,
)

atm: types.AtmosphericProfileModel
alg: types.RetrievalAlgorithm
processes: list[multiprocessing.Process] = []
Expand Down Expand Up @@ -183,7 +191,7 @@ def run_session(
)
p = multiprocessing.Process(
target=run_session,
args=(session, config),
args=(session, config, only_run_mock_retrieval),
name=name,
daemon=True,
)
Expand Down

0 comments on commit 82f8939

Please sign in to comment.