Skip to content
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
16 changes: 9 additions & 7 deletions aimbat/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from pydantic_settings import BaseSettings, SettingsConfigDict
from pathlib import Path
from datetime import timedelta
from pysmo.tools.iccs._defaults import ICCS_DEFAULTS
import numpy as np


class Settings(BaseSettings):
Expand All @@ -28,26 +30,28 @@ class Settings(BaseSettings):
"""Enable debug logging."""

window_pre: timedelta = Field(
default=timedelta(seconds=-15),
default=ICCS_DEFAULTS.WINDOW_PRE,
lt=0,
description="Initial relative begin time of window.",
)
"""Initial relative begin time of window."""

window_post: timedelta = Field(
default=timedelta(seconds=15),
default=ICCS_DEFAULTS.WINDOW_POST,
ge=0,
description="Initial relative end time of window.",
)
"""Initial relative end time of window."""

window_padding: timedelta = Field(
default=timedelta(seconds=20), gt=0, description="Padding around time window."
default=ICCS_DEFAULTS.PLOT_PADDING,
gt=0,
description="Padding around time window.",
)
"""Padding around time window."""

min_ccnorm: float = Field(
default=0.5,
min_ccnorm: float | np.floating = Field(
default=ICCS_DEFAULTS.MIN_CCNORM,
ge=0,
le=1,
description="Initial minimum cross correlation coefficient.",
Expand Down Expand Up @@ -76,8 +80,6 @@ class Settings(BaseSettings):
)
"""Minimum length of truncated UUID string."""

_blah: int = 4


settings = Settings()

Expand Down
18 changes: 2 additions & 16 deletions tests/test_data.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from aimbat.app import app
from pysmo.classes import SAC
from sqlalchemy.exc import NoResultFound
from sqlmodel import select, Session
from pathlib import Path
from importlib import reload
from aimbat.lib.io import DataType
from aimbat.lib.models import AimbatDataSource
import aimbat.lib.data as data
Expand All @@ -12,9 +12,7 @@


class TestDataBase:
@pytest.fixture(autouse=True)
def reload_modules(self, fixture_session_with_project: Session) -> None:
reload(data)
"""Base class for testing the data module."""


class TestDataAdd(TestDataBase):
Expand All @@ -40,8 +38,6 @@ def test_cli_data_add(
sac_file_good: Path,
fixture_session_with_project: Session,
) -> None:
from aimbat.app import app

sac_file_good_as_string = str(sac_file_good)

app(["data", "add", "--no-progress", sac_file_good_as_string])
Expand All @@ -57,7 +53,6 @@ def test_lib_print_data_table_without_active_event(
fixture_session_with_data: tuple[Path, Session],
capsys: pytest.CaptureFixture,
) -> None:
reload(data)
# no event active
with pytest.raises(NoResultFound):
data.print_data_table(False)
Expand All @@ -83,8 +78,6 @@ def test_lib_print_data_table_with_active_event(
all_events: bool,
expected: str,
) -> None:
reload(data)

data.print_data_table(short, all_events)
captured = capsys.readouterr()
assert expected in captured.out
Expand All @@ -105,9 +98,6 @@ def test_cli_data_list(
cli_args: list[str],
expected: str,
) -> None:
reload(data)
from aimbat.app import app

cmd = ["data", "list"]
cmd.extend(cli_args)
app(cmd)
Expand All @@ -121,7 +111,6 @@ def test_lib_dump_data(
fixture_session_with_data: Session,
capsys: pytest.CaptureFixture,
) -> None:
reload(data)
data.dump_data_table()
captured = capsys.readouterr()
loaded_json = json.loads(captured.out)
Expand All @@ -135,9 +124,6 @@ def test_cli_dump_data(
fixture_session_with_data: Session,
capsys: pytest.CaptureFixture,
) -> None:
reload(data)
from aimbat.app import app

app(["data", "dump"])
captured = capsys.readouterr()
loaded_json = json.loads(captured.out)
Expand Down
19 changes: 7 additions & 12 deletions tests/test_event.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from aimbat.config import settings
from aimbat.lib.models import AimbatEvent, AimbatStation, AimbatSeismogram
from aimbat.lib.typing import EventParameter
from pydantic_core import ValidationError
from sqlmodel import Session, select
from sqlalchemy.exc import NoResultFound
from importlib import reload
from typing import Any
from collections.abc import Generator, Sequence
import aimbat.lib.event as event
Expand All @@ -13,10 +13,6 @@


class TestEventBase:
@pytest.fixture(autouse=True)
def reload_modules(self, fixture_session_with_data: Session) -> None:
reload(event)

@pytest.fixture
def session(
self, fixture_session_with_data: Session
Expand All @@ -32,11 +28,9 @@ def get_random_event(self, session: Session) -> AimbatEvent:
return random.choice(events)

def activate_random_event(self, session: Session) -> AimbatEvent:
from aimbat.lib.event import set_active_event

event = self.get_random_event(session)
set_active_event(session, event)
return event
random_event = self.get_random_event(session)
event.set_active_event(session, random_event)
return random_event


class TestDeleteEvent(TestEventBase):
Expand All @@ -62,7 +56,7 @@ def test_cli_delete_event_by_id(self, session: Session) -> None:
is None
)

def test_cli_delete_event_by_id_with_wrong_id(self) -> None:
def test_cli_delete_event_by_id_with_wrong_id(self, session: Session) -> None:
from aimbat.app import app
from uuid import uuid4

Expand Down Expand Up @@ -250,7 +244,7 @@ def test_cli_get_event_parameter(
assert "False" in capsys.readouterr().out

app(["event", "get", "window_post"])
assert "15.0s" in capsys.readouterr().out
assert f"{settings.window_post.total_seconds()}s" in capsys.readouterr().out


class TestCliEvent(TestEventBase):
Expand All @@ -274,6 +268,7 @@ def test_cli_set_event_parameter(

def test_cli_event_list(
self,
session: Session,
capsys: pytest.CaptureFixture,
) -> None:
from aimbat.app import app
Expand Down
5 changes: 0 additions & 5 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@
from typing import Any
from collections.abc import Generator
from pathlib import Path
from importlib import reload
import aimbat.lib.data as data
import numpy as np
import pytest


class TestSacBase:
@pytest.fixture(autouse=True)
def reload_modules(self, fixture_session_with_project: Session) -> None:
reload(data)

@pytest.fixture
def aimbat_seismogram_from_sac(
self,
Expand Down
14 changes: 1 addition & 13 deletions tests/test_project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from aimbat.app import app
from pathlib import Path
from sqlmodel import Session
from importlib import reload
import aimbat.lib.project as project
import pytest

Expand Down Expand Up @@ -35,8 +35,6 @@ def test_lib_create_project_when_one_exists(
project.create_project()

def test_cli_create_project(self, fixture_session_empty: Session) -> None:
from aimbat.app import app

assert project._project_exists() is False
app(["project", "create"])
assert project._project_exists() is True
Expand All @@ -46,23 +44,18 @@ class TestProjectDelete(TestProjectBase):
def test_lib_delete_project_file(
self, fixture_session_with_project_file: tuple[Session, Path]
) -> None:
reload(project)
assert project._project_exists() is True

project.delete_project()
assert project._project_exists() is False

def test_lib_delete_project(self, fixture_session_with_project: Session) -> None:
assert project._project_exists() is True
reload(project)

project.delete_project()
assert project._project_exists() is False

def test_cli_delete_project(self, fixture_session_with_project: Session) -> None:
reload(project)
from aimbat.app import app

assert project._project_exists() is True

app(["project", "delete"])
Expand All @@ -81,7 +74,6 @@ def test_lib_print_project_info_with_empty_project(
fixture_session_with_project: Session,
capsys: pytest.CaptureFixture,
) -> None:
reload(project)
project.print_project_info()
captured = capsys.readouterr()
assert "Project Info" in captured.out
Expand All @@ -90,7 +82,6 @@ def test_lib_print_project_info_with_empty_project(
def test_lib_print_project_info_with_active_event(
self, fixture_session_with_active_event: Session, capsys: pytest.CaptureFixture
) -> None:
reload(project)
project.print_project_info()
captured = capsys.readouterr()
assert "Project Info" in captured.out
Expand All @@ -99,9 +90,6 @@ def test_lib_print_project_info_with_active_event(
def test_cli_print_project_info_with_active_event(
self, fixture_session_with_active_event: Session, capsys: pytest.CaptureFixture
) -> None:
reload(project)
from aimbat.app import app

assert project._project_exists() is True

app(["project", "info"])
Expand Down
Loading
Loading