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
Этот коммит содержится в:
Inga Ulusoy 2024-01-16 11:13:22 +01:00 коммит произвёл GitHub
родитель 721bc98f7a
Коммит f128fa4754
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 19 добавлений и 6 удалений

7
.github/workflows/release.yml поставляемый
Просмотреть файл

@ -1,9 +1,8 @@
name: release to pypi name: release to pypi
on: on:
push: release:
branches: types: [published]
- main
workflow_dispatch: workflow_dispatch:
jobs: jobs:
@ -116,4 +115,4 @@ jobs:
uses: pypa/gh-action-pypi-publish@release/v1 uses: pypa/gh-action-pypi-publish@release/v1
with: with:
repository-url: https://test.pypi.org/legacy/ repository-url: https://test.pypi.org/legacy/

Просмотреть файл

@ -97,6 +97,11 @@ class EmotionDetector(AnalysisMethod):
""" """
super().__init__(subdict) super().__init__(subdict)
self.subdict.update(self.set_keys()) 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.emotion_threshold = emotion_threshold
self.race_threshold = race_threshold self.race_threshold = race_threshold
self.emotion_categories = { self.emotion_categories = {

Просмотреть файл

@ -49,9 +49,9 @@ def test_right_output_analysis_emotions(get_AE, get_options):
get_options[0], get_options[0],
"EmotionDetector", "EmotionDetector",
True, True,
None,
None,
50, 50,
None,
None,
50, 50,
"CIE 1976", "CIE 1976",
"summary_and_questions", "summary_and_questions",

Просмотреть файл

@ -1,5 +1,6 @@
import ammico.faces as fc import ammico.faces as fc
import json import json
import pytest
def test_set_keys(): def test_set_keys():
@ -8,6 +9,14 @@ def test_set_keys():
assert ed.subdict["multiple_faces"] == "No" assert ed.subdict["multiple_faces"] == "No"
assert ed.subdict["wears_mask"] == ["No"] assert ed.subdict["wears_mask"] == ["No"]
assert ed.subdict["emotion"] == [None] 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): def test_analyse_faces(get_path):