Skip to content

Commit

Permalink
Add test for maad settings parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchellAcoustics committed Aug 14, 2023
1 parent 68b9de6 commit 6e63ee9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion soundscapy/analysis/_AnalysisSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def from_yaml(cls, filename: Union[Path, str], run_stats=True, force_run_all=Fal
AnalysisSettings object
"""
with open(filename, "r") as f:
return cls(yaml.load(f, Loader=yaml.Loader), run_stats, force_run_all, filename)
return cls(
yaml.load(f, Loader=yaml.Loader), run_stats, force_run_all, filename
)

@classmethod
def default(cls, run_stats=True, force_run_all=False):
Expand Down Expand Up @@ -132,6 +134,11 @@ def parse_maad_all_alpha_indices(self, metric: str):
channel: tuple or list of str, or str
channel(s) to run the metric on
"""
assert metric in [
"all_temporal_alpha_indices",
"all_spectral_alpha_indices",
], "metric must be all_temporal_alpha_indices or all_spectral_alpha_indices."

lib_settings = self["scikit-maad"].copy()
run = lib_settings[metric]["run"] or self.force_run_all
channel = lib_settings[metric]["channel"].copy()
Expand Down
12 changes: 12 additions & 0 deletions test/test__AnalysisSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,17 @@ def test_to_yaml(example_settings):
assert saved_data == example_settings


def test_parse_maad_all_alpha_indices():
settings = AnalysisSettings.default()
maad_settings = settings.parse_maad_all_alpha_indices("all_temporal_alpha_indices")
assert len(maad_settings) == 2
with pytest.raises(AssertionError) as excinfo:
obj = settings.parse_maad_all_alpha_indices("missing_key")
assert (
"metric must be all_temporal_alpha_indices or all_spectral_alpha_indices."
in str(excinfo.value)
)


if __name__ == "__main__":
pytest.main()

0 comments on commit 6e63ee9

Please sign in to comment.