-
Notifications
You must be signed in to change notification settings - Fork 17
Additional test coverage #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...odels/inference_pipeline/configs_py/FilteringConfig/test_validate_bandpass_frequencies.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import pytest | ||
|
|
||
| from birdnet.acoustic.inference.configs import FilteringConfig | ||
|
|
||
| SUPPORTED_FMIN = 0 | ||
| SUPPORTED_FMAX = 15000 | ||
|
|
||
|
|
||
| def test_valid_frequencies() -> None: | ||
| assert FilteringConfig.validate_bandpass_frequencies( | ||
| 100, 200, SUPPORTED_FMIN, SUPPORTED_FMAX | ||
| ) == (100, 200) | ||
|
|
||
|
|
||
| def test_full_range_is_valid() -> None: | ||
| assert FilteringConfig.validate_bandpass_frequencies( | ||
| SUPPORTED_FMIN, SUPPORTED_FMAX, SUPPORTED_FMIN, SUPPORTED_FMAX | ||
| ) == (SUPPORTED_FMIN, SUPPORTED_FMAX) | ||
|
|
||
|
|
||
| def test_fmin_none_raises_error() -> None: | ||
| with pytest.raises( | ||
| ValueError, match=r"bandpass minimum frequence must be specified" | ||
| ): | ||
| FilteringConfig.validate_bandpass_frequencies( | ||
| None, 200, SUPPORTED_FMIN, SUPPORTED_FMAX | ||
| ) | ||
|
|
||
|
|
||
| def test_fmax_none_raises_error() -> None: | ||
| with pytest.raises( | ||
| ValueError, match=r"bandpass maximum frequence must be specified" | ||
| ): | ||
| FilteringConfig.validate_bandpass_frequencies( | ||
| 100, None, SUPPORTED_FMIN, SUPPORTED_FMAX | ||
| ) | ||
|
|
||
|
|
||
| def test_non_integer_raises_error() -> None: | ||
| with pytest.raises(TypeError, match=r"bandpass frequencies must be integers"): | ||
| FilteringConfig.validate_bandpass_frequencies( | ||
| 1.5, 200, SUPPORTED_FMIN, SUPPORTED_FMAX # type: ignore | ||
| ) | ||
|
|
||
|
|
||
| def test_fmin_not_smaller_than_fmax_raises_error() -> None: | ||
| with pytest.raises(ValueError, match=r"bandpass frequencies must be in the range"): | ||
| FilteringConfig.validate_bandpass_frequencies( | ||
| 200, 100, SUPPORTED_FMIN, SUPPORTED_FMAX | ||
| ) | ||
|
|
||
|
|
||
| def test_out_of_supported_range_raises_error() -> None: | ||
| with pytest.raises(ValueError, match=r"bandpass frequencies must be in the range"): | ||
| FilteringConfig.validate_bandpass_frequencies( | ||
| 100, SUPPORTED_FMAX + 1, SUPPORTED_FMIN, SUPPORTED_FMAX | ||
| ) |
69 changes: 69 additions & 0 deletions
69
...coustic_models/inference_pipeline/configs_py/InferenceConfig/test_validate_input_audio.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import numpy as np | ||
| import pytest | ||
|
|
||
| from birdnet.acoustic.inference.configs import InferenceConfig | ||
|
|
||
|
|
||
| def test_single_tuple_is_wrapped() -> None: | ||
| audio = np.zeros(3, dtype=np.float32) | ||
| result = InferenceConfig.validate_input_audio((audio, 48000)) | ||
| assert len(result) == 1 | ||
| np.testing.assert_array_equal(result[0][0], audio) | ||
| assert result[0][1] == 48000 | ||
|
|
||
|
|
||
| def test_list_of_tuples_is_valid() -> None: | ||
| audio_a = np.zeros(3, dtype=np.float32) | ||
| audio_b = np.ones(2, dtype=np.int16) | ||
| result = InferenceConfig.validate_input_audio([(audio_a, 48000), (audio_b, 32000)]) | ||
| assert len(result) == 2 | ||
|
|
||
|
|
||
| def test_non_iterable_raises_error() -> None: | ||
| with pytest.raises(ValueError, match=r"Unsupported input type: <class 'int'>"): | ||
| InferenceConfig.validate_input_audio(123) | ||
|
|
||
|
|
||
| def test_element_not_a_tuple_raises_error() -> None: | ||
| with pytest.raises(ValueError, match=r"Unsupported input type"): | ||
| InferenceConfig.validate_input_audio([123]) | ||
|
|
||
|
|
||
| def test_tuple_wrong_length_raises_error() -> None: | ||
| audio = np.zeros(3, dtype=np.float32) | ||
| with pytest.raises( | ||
| ValueError, match=r"Input audio tuple must have exactly two elements" | ||
| ): | ||
| InferenceConfig.validate_input_audio([(audio, 48000, "extra")]) | ||
|
|
||
|
|
||
| def test_first_element_not_ndarray_raises_error() -> None: | ||
| with pytest.raises( | ||
| ValueError, match=r"First element of input audio tuple must be a numpy ndarray" | ||
| ): | ||
| InferenceConfig.validate_input_audio([("not an array", 48000)]) | ||
|
|
||
|
|
||
| def test_sample_rate_not_int_raises_error() -> None: | ||
| audio = np.zeros(3, dtype=np.float32) | ||
| with pytest.raises( | ||
| ValueError, | ||
| match=r"Second element of input audio tuple must be an integer sample rate", | ||
| ): | ||
| InferenceConfig.validate_input_audio([(audio, 48000.0)]) | ||
|
|
||
|
|
||
| def test_sample_rate_not_positive_raises_error() -> None: | ||
| audio = np.zeros(3, dtype=np.float32) | ||
| with pytest.raises( | ||
| ValueError, match=r"Sample rate must be a positive integer, got 0." | ||
| ): | ||
| InferenceConfig.validate_input_audio([(audio, 0)]) | ||
|
|
||
|
|
||
| def test_wrong_dtype_raises_error() -> None: | ||
| audio = np.array(["a", "b"]) | ||
| with pytest.raises( | ||
| ValueError, match=r"Audio array must have an integer or floating-point dtype" | ||
| ): | ||
| InferenceConfig.validate_input_audio([(audio, 48000)]) |
24 changes: 24 additions & 0 deletions
24
...ts/acoustic_models/inference_pipeline/configs_py/OutputConfig/test_validate_show_stats.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import pytest | ||
|
|
||
| from birdnet.acoustic.inference.configs import OutputConfig | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("value", ["minimal", "progress", "benchmark", None]) | ||
| def test_valid_values(value: str | None) -> None: | ||
| assert OutputConfig.validate_show_stats(value) == value | ||
|
|
||
|
|
||
| def test_unknown_value_raises_error() -> None: | ||
| with pytest.raises( | ||
| ValueError, | ||
| match=r"show stats must be one of 'minimal', 'progress' or 'benchmark'", | ||
| ): | ||
| OutputConfig.validate_show_stats("verbose") # type: ignore | ||
|
|
||
|
|
||
| def test_empty_string_raises_error() -> None: | ||
| with pytest.raises( | ||
| ValueError, | ||
| match=r"show stats must be one of 'minimal', 'progress' or 'benchmark'", | ||
| ): | ||
| OutputConfig.validate_show_stats("") # type: ignore |
59 changes: 59 additions & 0 deletions
59
...erence_pipeline/configs_py/PredictionConfig/test_validate_custom_confidence_thresholds.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import pytest | ||
|
|
||
| from birdnet.acoustic.inference.configs import PredictionConfig | ||
|
|
||
| MODEL_SPECIES = ["species_a", "species_b", "species_c"] | ||
|
|
||
|
|
||
| def test_valid_thresholds() -> None: | ||
| thresholds = {"species_a": 0.5, "species_b": 0.1} | ||
| assert ( | ||
| PredictionConfig.validate_custom_confidence_thresholds(thresholds, MODEL_SPECIES) | ||
| == thresholds | ||
| ) | ||
|
|
||
|
|
||
| def test_empty_dict_is_valid() -> None: | ||
| assert PredictionConfig.validate_custom_confidence_thresholds({}, MODEL_SPECIES) == {} | ||
|
|
||
|
|
||
| def test_integer_value_is_valid() -> None: | ||
| thresholds = {"species_a": 1} | ||
| assert ( | ||
| PredictionConfig.validate_custom_confidence_thresholds(thresholds, MODEL_SPECIES) | ||
| == thresholds | ||
| ) | ||
|
|
||
|
|
||
| def test_non_dict_raises_error() -> None: | ||
| with pytest.raises( | ||
| TypeError, match=r"custom confidence thresholds must be a dictionary" | ||
| ): | ||
| PredictionConfig.validate_custom_confidence_thresholds( | ||
| [("species_a", 0.5)], MODEL_SPECIES # type: ignore | ||
| ) | ||
|
|
||
|
|
||
| def test_non_string_key_raises_error() -> None: | ||
| with pytest.raises( | ||
| TypeError, match=r"custom confidence threshold keys must be strings" | ||
| ): | ||
| PredictionConfig.validate_custom_confidence_thresholds({1: 0.5}, MODEL_SPECIES) | ||
|
|
||
|
|
||
| def test_unknown_species_raises_error() -> None: | ||
| with pytest.raises( | ||
| ValueError, match=r"species 'unknown' is not available in the model" | ||
| ): | ||
| PredictionConfig.validate_custom_confidence_thresholds( | ||
| {"unknown": 0.5}, MODEL_SPECIES | ||
| ) | ||
|
|
||
|
|
||
| def test_non_number_value_raises_error() -> None: | ||
| with pytest.raises( | ||
| TypeError, match=r"custom confidence threshold values must be numbers" | ||
| ): | ||
| PredictionConfig.validate_custom_confidence_thresholds( | ||
| {"species_a": "high"}, MODEL_SPECIES | ||
| ) |
56 changes: 56 additions & 0 deletions
56
...odels/inference_pipeline/configs_py/PredictionConfig/test_validate_custom_species_list.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from birdnet.acoustic.inference.configs import PredictionConfig | ||
|
|
||
| MODEL_SPECIES = ["species_a", "species_b", "species_c"] | ||
|
|
||
|
|
||
| def test_list_is_valid() -> None: | ||
| result = PredictionConfig.validate_custom_species_list( | ||
| ["species_a", "species_b"], MODEL_SPECIES | ||
| ) | ||
| assert result == {"species_a", "species_b"} | ||
|
|
||
|
|
||
| def test_set_is_valid() -> None: | ||
| result = PredictionConfig.validate_custom_species_list( | ||
| {"species_a"}, MODEL_SPECIES | ||
| ) | ||
| assert result == {"species_a"} | ||
|
|
||
|
|
||
| def test_reads_from_file_path(tmp_path: Path) -> None: | ||
| species_file = tmp_path / "species.txt" | ||
| species_file.write_text("species_a\nspecies_c\n", encoding="utf-8") | ||
|
|
||
| result = PredictionConfig.validate_custom_species_list(species_file, MODEL_SPECIES) | ||
| assert result == {"species_a", "species_c"} | ||
|
|
||
|
|
||
| def test_reads_from_string_path(tmp_path: Path) -> None: | ||
| species_file = tmp_path / "species.txt" | ||
| species_file.write_text("species_b\n", encoding="utf-8") | ||
|
|
||
| result = PredictionConfig.validate_custom_species_list( | ||
| str(species_file), MODEL_SPECIES | ||
| ) | ||
| assert result == {"species_b"} | ||
|
|
||
|
|
||
| def test_unknown_species_raises_error() -> None: | ||
| with pytest.raises( | ||
| ValueError, match=r"species 'unknown' is not available in the model" | ||
| ): | ||
| PredictionConfig.validate_custom_species_list(["unknown"], MODEL_SPECIES) | ||
|
|
||
|
|
||
| def test_non_collection_raises_error() -> None: | ||
| with pytest.raises(TypeError, match=r"custom species list must be a str, path"): | ||
| PredictionConfig.validate_custom_species_list(123, MODEL_SPECIES) # type: ignore | ||
|
|
||
|
|
||
| def test_non_string_element_raises_error() -> None: | ||
| with pytest.raises(TypeError, match=r"custom species list must contain strings"): | ||
| PredictionConfig.validate_custom_species_list([1, 2], MODEL_SPECIES) # type: ignore |
30 changes: 30 additions & 0 deletions
30
...erence_pipeline/configs_py/PredictionConfig/test_validate_default_confidence_threshold.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import pytest | ||
|
|
||
| from birdnet.acoustic.inference.configs import PredictionConfig | ||
|
|
||
|
|
||
| def test_float_is_valid() -> None: | ||
| assert PredictionConfig.validate_default_confidence_threshold(0.5) == 0.5 | ||
|
|
||
|
|
||
| def test_integer_is_valid() -> None: | ||
| assert PredictionConfig.validate_default_confidence_threshold(1) == 1 | ||
|
|
||
|
|
||
| def test_negative_is_returned_as_is() -> None: | ||
| # The validator only enforces the type, not the range. | ||
| assert PredictionConfig.validate_default_confidence_threshold(-0.5) == -0.5 | ||
|
|
||
|
|
||
| def test_string_raises_error() -> None: | ||
| with pytest.raises( | ||
| TypeError, match=r"default confidence threshold must be a number" | ||
| ): | ||
| PredictionConfig.validate_default_confidence_threshold("high") # type: ignore | ||
|
|
||
|
|
||
| def test_none_raises_error() -> None: | ||
| with pytest.raises( | ||
| TypeError, match=r"default confidence threshold must be a number" | ||
| ): | ||
| PredictionConfig.validate_default_confidence_threshold(None) # type: ignore | ||
34 changes: 34 additions & 0 deletions
34
...odels/inference_pipeline/configs_py/PredictionConfig/test_validate_sigmoid_sensitivity.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import pytest | ||
|
|
||
| from birdnet.acoustic.inference.configs import PredictionConfig | ||
|
|
||
|
|
||
| def test_one_is_valid() -> None: | ||
| assert PredictionConfig.validate_sigmoid_sensitivity(1.0) == 1.0 | ||
|
|
||
|
|
||
| def test_lower_bound_is_valid() -> None: | ||
| assert PredictionConfig.validate_sigmoid_sensitivity(0.5) == 0.5 | ||
|
|
||
|
|
||
| def test_upper_bound_is_valid() -> None: | ||
| assert PredictionConfig.validate_sigmoid_sensitivity(1.5) == 1.5 | ||
|
|
||
|
|
||
| def test_too_small_raises_error() -> None: | ||
| with pytest.raises( | ||
| ValueError, match=r"sigmoid sensitivity must be in the range \[0.5, 1.5\]" | ||
| ): | ||
| PredictionConfig.validate_sigmoid_sensitivity(0.1) | ||
|
|
||
|
|
||
| def test_too_large_raises_error() -> None: | ||
| with pytest.raises( | ||
| ValueError, match=r"sigmoid sensitivity must be in the range \[0.5, 1.5\]" | ||
| ): | ||
| PredictionConfig.validate_sigmoid_sensitivity(2.0) | ||
|
|
||
|
|
||
| def test_non_number_raises_error() -> None: | ||
| with pytest.raises(TypeError, match=r"sigmoid sensitivity must be a number"): | ||
| PredictionConfig.validate_sigmoid_sensitivity("high") # type: ignore |
30 changes: 30 additions & 0 deletions
30
...sts/acoustic_models/inference_pipeline/configs_py/PredictionConfig/test_validate_top_k.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import pytest | ||
|
|
||
| from birdnet.acoustic.inference.configs import PredictionConfig | ||
|
|
||
|
|
||
| def test_valid_value() -> None: | ||
| assert PredictionConfig.validate_top_k(3, max_value=5) == 3 | ||
|
|
||
|
|
||
| def test_lower_bound_is_valid() -> None: | ||
| assert PredictionConfig.validate_top_k(1, max_value=5) == 1 | ||
|
|
||
|
|
||
| def test_upper_bound_is_valid() -> None: | ||
| assert PredictionConfig.validate_top_k(5, max_value=5) == 5 | ||
|
|
||
|
|
||
| def test_zero_raises_error() -> None: | ||
| with pytest.raises(ValueError, match=r"top k must be in the range \[1, 5\]"): | ||
| PredictionConfig.validate_top_k(0, max_value=5) | ||
|
|
||
|
|
||
| def test_above_max_raises_error() -> None: | ||
| with pytest.raises(ValueError, match=r"top k must be in the range \[1, 5\]"): | ||
| PredictionConfig.validate_top_k(6, max_value=5) | ||
|
|
||
|
|
||
| def test_non_integer_raises_error() -> None: | ||
| with pytest.raises(TypeError, match=r"top k must be an integer"): | ||
| PredictionConfig.validate_top_k(1.5, max_value=5) # type: ignore |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.