From f128fa4754ff76c5cd0c70e843a8456cbed0888c Mon Sep 17 00:00:00 2001 From: Inga Ulusoy Date: Tue, 16 Jan 2024 11:13:22 +0100 Subject: [PATCH] check threshold for emotion and race lies in btw 0 and 100 (#175) * check threshold for emotion and race liezs in btw 0 and 100 * Update release.yml * correct order of calling args in test display --- .github/workflows/release.yml | 7 +++---- ammico/faces.py | 5 +++++ ammico/test/test_display.py | 4 ++-- ammico/test/test_faces.py | 9 +++++++++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2ff1b4e..0dc6e3d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,8 @@ name: release to pypi on: - push: - branches: - - main + release: + types: [published] workflow_dispatch: jobs: @@ -116,4 +115,4 @@ jobs: uses: pypa/gh-action-pypi-publish@release/v1 with: repository-url: https://test.pypi.org/legacy/ - \ No newline at end of file + diff --git a/ammico/faces.py b/ammico/faces.py index c9e1c43..a485cbb 100644 --- a/ammico/faces.py +++ b/ammico/faces.py @@ -97,6 +97,11 @@ class EmotionDetector(AnalysisMethod): """ super().__init__(subdict) self.subdict.update(self.set_keys()) + # check if thresholds are valid + if emotion_threshold < 0 or emotion_threshold > 100: + raise ValueError("Emotion threshold must be between 0 and 100.") + if race_threshold < 0 or race_threshold > 100: + raise ValueError("Race threshold must be between 0 and 100.") self.emotion_threshold = emotion_threshold self.race_threshold = race_threshold self.emotion_categories = { diff --git a/ammico/test/test_display.py b/ammico/test/test_display.py index e00c06a..5dc0e54 100644 --- a/ammico/test/test_display.py +++ b/ammico/test/test_display.py @@ -49,9 +49,9 @@ def test_right_output_analysis_emotions(get_AE, get_options): get_options[0], "EmotionDetector", True, + None, + None, 50, - None, - None, 50, "CIE 1976", "summary_and_questions", diff --git a/ammico/test/test_faces.py b/ammico/test/test_faces.py index 66ddad3..a1d10db 100644 --- a/ammico/test/test_faces.py +++ b/ammico/test/test_faces.py @@ -1,5 +1,6 @@ import ammico.faces as fc import json +import pytest def test_set_keys(): @@ -8,6 +9,14 @@ def test_set_keys(): assert ed.subdict["multiple_faces"] == "No" assert ed.subdict["wears_mask"] == ["No"] assert ed.subdict["emotion"] == [None] + with pytest.raises(ValueError): + fc.EmotionDetector({}, emotion_threshold=150) + with pytest.raises(ValueError): + fc.EmotionDetector({}, emotion_threshold=-50) + with pytest.raises(ValueError): + fc.EmotionDetector({}, race_threshold=150) + with pytest.raises(ValueError): + fc.EmotionDetector({}, race_threshold=-50) def test_analyse_faces(get_path):