added tests for aria breaks and precise activities
This commit is contained in:
parent
180bf4dae5
commit
0b37aeca7d
2 changed files with 57 additions and 0 deletions
|
|
@ -523,6 +523,8 @@ class FormData:
|
|||
return mask
|
||||
|
||||
def generate_aria_activity_expiration(self) -> typing.Tuple[typing.Any, ...]:
|
||||
if self.aria_precise == {}: # It means the precise activity is not defined by ARIA interface.
|
||||
return ()
|
||||
respiratory_dict = {}
|
||||
for respiratory_activity in self.aria_precise['respiratory_activity']:
|
||||
respiratory_dict[respiratory_activity['type']] = respiratory_activity['percentage']
|
||||
|
|
|
|||
55
caimira/tests/apps/calculator/test_aria_model_generator.py
Normal file
55
caimira/tests/apps/calculator/test_aria_model_generator.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
from typing import Type
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from caimira.apps.calculator import model_generator
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
["break_input", "error"],
|
||||
[
|
||||
[{"start_time": "10:00", "finish_time": "11:00"}, "All breaks should be in a list. Got <class 'dict'>."],
|
||||
[[["start_time", "10:00", "finish_time", "11:00"]], "Each break should be a dictionary. Got <class 'list'>."],
|
||||
[[{"art_time": "10:00", "finish_time": "11:00"}], 'Unable to fetch "start_time" key. Got "art_time".'],
|
||||
[[{"start_time": "10:00", "ish_time": "11:00"}], 'Unable to fetch "finish_time" key. Got "ish_time".'],
|
||||
[[{"start_time": "10", "finish_time": "11:00"}], 'Wrong time format - "HH:MM". Got "10".'],
|
||||
[[{"start_time": "10:00", "finish_time": "11"}], 'Wrong time format - "HH:MM". Got "11".'],
|
||||
]
|
||||
)
|
||||
def test_aria_break_data_structure(break_input, error, baseline_form: model_generator.FormData):
|
||||
baseline_form.aria_breaks = break_input
|
||||
with pytest.raises(TypeError, match=error):
|
||||
baseline_form.validate()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
["precise_activity_input", "error"],
|
||||
[
|
||||
[["physical_activity", "Light activity", "respiratory_activity", [{"type": "Breathing", "percentage": 50}, {"type": "Speaking", "percentage": 50}]], "The precise activities should be in a dictionary."],
|
||||
[{"pysical_activity": "Light activity", "respiratory_activity": [{"type": "Breathing", "percentage": 50}, {"type": "Speaking", "percentage": 50}]}, 'Unable to fetch "physical_activity" key. Got "pysical_activity".'],
|
||||
[{"physical_activity": "Light activity", "rspiratory_activity": [{"type": "Breathing", "percentage": 50}, {"type": "Speaking", "percentage": 50}]}, 'Unable to fetch "respiratory_activity" key. Got "rspiratory_activity".'],
|
||||
[{"physical_activity": ["Light activity"], "respiratory_activity": [{"type": "Breathing", "percentage": 50}, {"type": "Speaking", "percentage": 50}]}, "The physical activities should be a single string."],
|
||||
[{"physical_activity": "Light activity", "respiratory_activity": {"type": "Breathing", "percentage": 100}}, 'The respiratory activities should be in a list.'],
|
||||
[{"physical_activity": "Light activity", "respiratory_activity": [["type", "Speaking", "percentage", 100]]}, 'Each respiratory activity should be defined in a dictionary.'],
|
||||
[{"physical_activity": "Light activity", "respiratory_activity": [{"tpe": "Breathing", "percentage": 50}, {"type": "Speaking", "percentage": 50}]}, 'Unable to fetch "type" key. Got "tpe".'],
|
||||
[{"physical_activity": "Light activity", "respiratory_activity": [{"type": "Breathing", "percentag": 50}, {"type": "Speaking", "percentage": 50}]}, 'Unable to fetch "percentage" key. Got "percentag".'],
|
||||
]
|
||||
)
|
||||
def test_aria_precise_activity_structure(precise_activity_input, error, baseline_form: model_generator.FormData):
|
||||
baseline_form.aria_precise = precise_activity_input
|
||||
with pytest.raises(TypeError, match=error):
|
||||
baseline_form.validate()
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
["precise_activity_input", "error"],
|
||||
[
|
||||
[{"physical_activity": "Light activity", "respiratory_activity": [{"type": "Breathing", "percentage": 10}, {"type": "Speaking", "percentage": 50}]}, 'The sum of all respiratory activities should be 100. Got 60.'],
|
||||
[{"physical_activity": "Light activity", "respiratory_activity": [{"type": "Breathing", "percentage": 50}, {"type": "Speaking", "percentage": 10}]}, 'The sum of all respiratory activities should be 100. Got 60.'],
|
||||
[{"physical_activity": "Light activity", "respiratory_activity": [{"type": "Breathing", "percentage": 10}, {"type": "Speaking", "percentage": 50}, {"type": "Shouting", "percentage": 50}]}, 'The sum of all respiratory activities should be 100. Got 110.'],
|
||||
[{"physical_activity": "Light activity", "respiratory_activity": [{"type": "Breathing", "percentage": 50}]}, 'The sum of all respiratory activities should be 100. Got 50.'],
|
||||
]
|
||||
)
|
||||
def test_aria_sum_precise_activity(precise_activity_input, error, baseline_form: model_generator.FormData):
|
||||
baseline_form.aria_precise = precise_activity_input
|
||||
with pytest.raises(ValueError, match=error):
|
||||
baseline_form.validate()
|
||||
Loading…
Reference in a new issue