diff --git a/.gitignore b/.gitignore index c598b98..80a1db0 100644 --- a/.gitignore +++ b/.gitignore @@ -110,5 +110,6 @@ experiments/* !batdetect2_notebook.ipynb !batdetect2/models/*.pth.tar !tests/data/*.wav +!tests/data/**/*.wav notebooks/lightning_logs example_data/preprocessed diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..06f9ddc --- /dev/null +++ b/tests/conftest.py @@ -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 diff --git a/tests/data/contrib/jeff37/0166_20240531_223911.wav b/tests/data/contrib/jeff37/0166_20240531_223911.wav new file mode 100755 index 0000000..e5daa02 Binary files /dev/null and b/tests/data/contrib/jeff37/0166_20240531_223911.wav differ diff --git a/tests/data/contrib/jeff37/0166_20240602_225340.wav b/tests/data/contrib/jeff37/0166_20240602_225340.wav new file mode 100755 index 0000000..eb38e14 Binary files /dev/null and b/tests/data/contrib/jeff37/0166_20240602_225340.wav differ diff --git a/tests/data/contrib/jeff37/0166_20240603_033731.wav b/tests/data/contrib/jeff37/0166_20240603_033731.wav new file mode 100755 index 0000000..1f95b5a Binary files /dev/null and b/tests/data/contrib/jeff37/0166_20240603_033731.wav differ diff --git a/tests/data/contrib/jeff37/0166_20240603_033937.wav b/tests/data/contrib/jeff37/0166_20240603_033937.wav new file mode 100755 index 0000000..24bdec0 Binary files /dev/null and b/tests/data/contrib/jeff37/0166_20240603_033937.wav differ diff --git a/tests/data/contrib/jeff37/0166_20240604_233500.wav b/tests/data/contrib/jeff37/0166_20240604_233500.wav new file mode 100755 index 0000000..9e4b67d Binary files /dev/null and b/tests/data/contrib/jeff37/0166_20240604_233500.wav differ diff --git a/tests/test_contrib.py b/tests/test_contrib.py new file mode 100644 index 0000000..efb0531 --- /dev/null +++ b/tests/test_contrib.py @@ -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