From 270b3f212d6a306de5b5a006840616cb71bc171b Mon Sep 17 00:00:00 2001 From: mbsantiago Date: Mon, 11 Nov 2024 12:13:00 +0000 Subject: [PATCH] Created test to verify no errors occurred when running on padpadpadpad recordings --- tests/test_cli.py | 14 ++++++++------ tests/test_contrib.py | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 4038533..b53635f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,7 +1,9 @@ """Test the command line interface.""" + from pathlib import Path -from click.testing import CliRunner + import pandas as pd +from click.testing import CliRunner from batdetect2.cli import cli @@ -11,7 +13,9 @@ def test_cli_base_command(): runner = CliRunner() result = runner.invoke(cli, ["--help"]) 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(): @@ -68,8 +72,7 @@ def test_cli_detect_command_with_non_trivial_time_expansion(tmp_path): ) 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): @@ -94,13 +97,12 @@ def test_cli_detect_command_with_the_spec_feature_flag(tmp_path: Path): assert result.exit_code == 0 assert results_dir.exists() - csv_files = [path.name for path in results_dir.glob("*.csv")] expected_files = [ "20170701_213954-MYOMYS-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: diff --git a/tests/test_contrib.py b/tests/test_contrib.py index b335349..b97e9c0 100644 --- a/tests/test_contrib.py +++ b/tests/test_contrib.py @@ -9,7 +9,7 @@ from batdetect2.cli import cli runner = CliRunner() -def test_files_negative_dimensions_are_not_allowed( +def test_can_process_jeff37_files( contrib_dir: Path, tmp_path: Path, ): @@ -40,3 +40,34 @@ def test_files_negative_dimensions_are_not_allowed( assert results_dir.exists() assert len(list(results_dir.glob("*.csv"))) == 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