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
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/

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

@ -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 = {

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

@ -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",

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

@ -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):