Added a test that replicates the error

This commit is contained in:
mbsantiago 2024-11-10 20:06:58 +00:00
parent 697b5dbddb
commit d93d8284d0
8 changed files with 60 additions and 0 deletions

1
.gitignore vendored
View File

@ -110,5 +110,6 @@ experiments/*
!batdetect2_notebook.ipynb
!batdetect2/models/*.pth.tar
!tests/data/*.wav
!tests/data/**/*.wav
notebooks/lightning_logs
example_data/preprocessed

17
tests/conftest.py Normal file
View File

@ -0,0 +1,17 @@
from pathlib import Path
import pytest
@pytest.fixture
def data_dir() -> Path:
dir = Path(__file__).parent / "data"
assert dir.exists()
return dir
@pytest.fixture
def contrib_dir(data_dir) -> Path:
dir = data_dir / "contrib"
assert dir.exists()
return dir

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

42
tests/test_contrib.py Normal file
View File

@ -0,0 +1,42 @@
"""Test suite to ensure user provided files are correctly processed."""
from pathlib import Path
from click.testing import CliRunner
from batdetect2.cli import cli
runner = CliRunner()
def test_files_negative_dimensions_are_not_allowed(
contrib_dir: Path,
tmp_path: Path,
):
"""This test stems from issue #31.
A user provided a set of files which which batdetect2 cli failed and
generated the following error message:
[2272] "Error processing file!: negative dimensions are not allowed"
This test ensures that the error message is not generated when running
batdetect2 cli with the same set of files.
"""
path = contrib_dir / "jeff37"
assert path.exists()
results_dir = tmp_path / "results"
result = runner.invoke(
cli,
[
"detect",
str(path),
str(results_dir),
"0.3",
],
)
assert result.exit_code == 0
assert results_dir.exists()
assert len(list(results_dir.glob("*.csv"))) == 3
assert len(list(results_dir.glob("*.json"))) == 3