-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed: Fix prepare_result function calls and add type hints (#701)
* Fix: Fix prepare_result function calls in listening_conditions.py by adding key parameter * fix: Fix Trial instantiation in ListeningConditions (second parameter is html, see trial.py) * refactor: Add type hints to prepare_result function * refactor: Include type hints to Trial class constructor * Add test cases for ListeningConditions class * fix(lint): Fix formatting in trial.py and remove unnecessary lines in test_listening_conditions.py (cherry picked from commit 6f52358)
- Loading branch information
1 parent
dab5b27
commit 6458b5d
Showing
4 changed files
with
103 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
backend/experiment/rules/tests/test_listening_conditions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from django.test import TestCase | ||
from section.models import Section, Song, Playlist as PlaylistModel | ||
from participant.models import Participant | ||
from session.models import Session | ||
from experiment.models import Experiment | ||
from experiment.rules.listening_conditions import ListeningConditions | ||
from experiment.actions import Consent, Explainer, Final, Playback, Playlist, StartSession, Trial, Form | ||
from experiment.actions.form import Form | ||
from experiment.actions.playback import Playback | ||
|
||
|
||
class ListeningConditionsTest(TestCase): | ||
|
||
def setUp(self): | ||
playlist = PlaylistModel.objects.create( | ||
name='test' | ||
) | ||
song = Song.objects.create( | ||
artist="Cheese Shop", | ||
name="Gouda" | ||
) | ||
Section.objects.create( | ||
playlist=playlist, | ||
song=song, | ||
filename="not/to_be_found.mp3", | ||
tag=0 | ||
) | ||
self.experiment = Experiment.objects.create( | ||
name='test', | ||
slug='TEST', | ||
) | ||
participant = Participant.objects.create() | ||
self.session = Session.objects.create( | ||
experiment=Experiment.objects.first(), | ||
participant=participant, | ||
playlist=playlist | ||
) | ||
|
||
def test_first_round(self): | ||
listening_conditions = ListeningConditions() | ||
actions = listening_conditions.first_round(self.experiment) | ||
|
||
self.assertIsInstance(actions[0], Consent) | ||
self.assertIsInstance(actions[1], Explainer) | ||
self.assertIsInstance(actions[2], Playlist) | ||
self.assertIsInstance(actions[3], StartSession) | ||
|
||
def test_next_round_first_round(self): | ||
listening_conditions = ListeningConditions() | ||
listening_conditions.first_round(self.experiment) | ||
actions = listening_conditions.next_round(self.session) | ||
|
||
self.assertIsInstance(actions[0], Trial) | ||
|
||
self.assertIsInstance(actions[0].feedback_form, Form) | ||
self.assertEqual(len(actions[0].feedback_form.form), 1) | ||
self.assertEqual(actions[0].feedback_form.form[0].key, 'quiet_room') | ||
|
||
def test_next_round_final_round(self): | ||
listening_conditions = ListeningConditions() | ||
listening_conditions.first_round(self.experiment) | ||
listening_conditions.next_round(self.session) | ||
listening_conditions.next_round(self.session) | ||
listening_conditions.next_round(self.session) | ||
listening_conditions.next_round(self.session) | ||
actions = listening_conditions.next_round(self.session) | ||
|
||
self.assertIsInstance(actions[0], Trial) | ||
self.assertIsInstance(actions[0].playback, Playback) | ||
self.assertIsNone(actions[0].feedback_form) # Assuming no feedback form for the final round | ||
self.assertIsInstance(actions[1], Final) | ||
|
||
def test_next_round_does_not_throw_error(self): | ||
listening_conditions = ListeningConditions() | ||
listening_conditions.next_round(self.session) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters