mirror of
https://github.com/macaodha/batdetect2.git
synced 2025-06-29 14:41:58 +02:00
Run the same test with example data instead of random audio
This commit is contained in:
parent
394c66a2ee
commit
3477d7b5b4
@ -1,8 +1,31 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import List
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def example_data_dir() -> Path:
|
||||||
|
pkg_dir = Path(__file__).parent.parent
|
||||||
|
example_data_dir = pkg_dir / "example_data"
|
||||||
|
assert example_data_dir.exists()
|
||||||
|
return example_data_dir
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def example_audio_dir(example_data_dir: Path) -> Path:
|
||||||
|
example_audio_dir = example_data_dir / "audio"
|
||||||
|
assert example_audio_dir.exists()
|
||||||
|
return example_audio_dir
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def example_audio_files(example_audio_dir: Path) -> List[Path]:
|
||||||
|
audio_files = list(example_audio_dir.glob("*.[wW][aA][vV]"))
|
||||||
|
assert len(audio_files) == 3
|
||||||
|
return audio_files
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def data_dir() -> Path:
|
def data_dir() -> Path:
|
||||||
dir = Path(__file__).parent / "data"
|
dir = Path(__file__).parent / "data"
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
"""Test suite for model functions."""
|
"""Test suite for model functions."""
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import List
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from hypothesis import given, settings
|
from hypothesis import given, settings
|
||||||
@ -45,3 +47,32 @@ def test_can_import_model_without_pickle(duration: float):
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert predictions_without_pickle == predictions_with_pickle
|
assert predictions_without_pickle == predictions_with_pickle
|
||||||
|
|
||||||
|
|
||||||
|
def test_can_import_model_without_pickle_on_test_data(
|
||||||
|
example_audio_files: List[Path],
|
||||||
|
):
|
||||||
|
# NOTE: remove this test once no other issues are found This is a temporary
|
||||||
|
# test to check that change in model loading did not impact model behaviour
|
||||||
|
# in any way.
|
||||||
|
|
||||||
|
model_without_pickle, model_params_without_pickle = api.load_model(
|
||||||
|
weights_only=True
|
||||||
|
)
|
||||||
|
model_with_pickle, model_params_with_pickle = api.load_model(
|
||||||
|
weights_only=False
|
||||||
|
)
|
||||||
|
|
||||||
|
assert model_params_without_pickle == model_params_with_pickle
|
||||||
|
|
||||||
|
for audio_file in example_audio_files:
|
||||||
|
audio = api.load_audio(str(audio_file))
|
||||||
|
predictions_without_pickle, _, _ = api.process_audio(
|
||||||
|
audio,
|
||||||
|
model=model_without_pickle,
|
||||||
|
)
|
||||||
|
predictions_with_pickle, _, _ = api.process_audio(
|
||||||
|
audio,
|
||||||
|
model=model_with_pickle,
|
||||||
|
)
|
||||||
|
assert predictions_without_pickle == predictions_with_pickle
|
||||||
|
Loading…
Reference in New Issue
Block a user