Created test to verify no errors occurred when running on padpadpadpad recordings

This commit is contained in:
mbsantiago 2024-11-11 12:13:00 +00:00
parent f61d1d8c72
commit 270b3f212d
2 changed files with 40 additions and 7 deletions

View File

@ -1,7 +1,9 @@
"""Test the command line interface.""" """Test the command line interface."""
from pathlib import Path from pathlib import Path
from click.testing import CliRunner
import pandas as pd import pandas as pd
from click.testing import CliRunner
from batdetect2.cli import cli from batdetect2.cli import cli
@ -11,7 +13,9 @@ def test_cli_base_command():
runner = CliRunner() runner = CliRunner()
result = runner.invoke(cli, ["--help"]) result = runner.invoke(cli, ["--help"])
assert result.exit_code == 0 assert result.exit_code == 0
assert "BatDetect2 - Bat Call Detection and Classification" in result.output assert (
"BatDetect2 - Bat Call Detection and Classification" in result.output
)
def test_cli_detect_command_help(): def test_cli_detect_command_help():
@ -68,8 +72,7 @@ def test_cli_detect_command_with_non_trivial_time_expansion(tmp_path):
) )
assert result.exit_code == 0 assert result.exit_code == 0
assert 'Time Expansion Factor: 10' in result.stdout assert "Time Expansion Factor: 10" in result.stdout
def test_cli_detect_command_with_the_spec_feature_flag(tmp_path: Path): def test_cli_detect_command_with_the_spec_feature_flag(tmp_path: Path):
@ -94,13 +97,12 @@ def test_cli_detect_command_with_the_spec_feature_flag(tmp_path: Path):
assert result.exit_code == 0 assert result.exit_code == 0
assert results_dir.exists() assert results_dir.exists()
csv_files = [path.name for path in results_dir.glob("*.csv")] csv_files = [path.name for path in results_dir.glob("*.csv")]
expected_files = [ expected_files = [
"20170701_213954-MYOMYS-LR_0_0.5.wav_spec_features.csv", "20170701_213954-MYOMYS-LR_0_0.5.wav_spec_features.csv",
"20180530_213516-EPTSER-LR_0_0.5.wav_spec_features.csv", "20180530_213516-EPTSER-LR_0_0.5.wav_spec_features.csv",
"20180627_215323-RHIFER-LR_0_0.5.wav_spec_features.csv" "20180627_215323-RHIFER-LR_0_0.5.wav_spec_features.csv",
] ]
for expected_file in expected_files: for expected_file in expected_files:

View File

@ -9,7 +9,7 @@ from batdetect2.cli import cli
runner = CliRunner() runner = CliRunner()
def test_files_negative_dimensions_are_not_allowed( def test_can_process_jeff37_files(
contrib_dir: Path, contrib_dir: Path,
tmp_path: Path, tmp_path: Path,
): ):
@ -40,3 +40,34 @@ def test_files_negative_dimensions_are_not_allowed(
assert results_dir.exists() assert results_dir.exists()
assert len(list(results_dir.glob("*.csv"))) == 5 assert len(list(results_dir.glob("*.csv"))) == 5
assert len(list(results_dir.glob("*.json"))) == 5 assert len(list(results_dir.glob("*.json"))) == 5
def test_can_process_padpadpadpad_files(
contrib_dir: Path,
tmp_path: Path,
):
"""This test stems from issue #29.
Batdetect2 cli failed on the files provided by the user @padpadpadpad
with the following error message:
AttributeError: module 'numpy' has no attribute 'AxisError'
This test ensures that the files are processed without any error.
"""
path = contrib_dir / "padpadpadpad"
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"))) == 2
assert len(list(results_dir.glob("*.json"))) == 2