-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hotfix/speech2song #1036
Merged
Merged
Hotfix/speech2song #1036
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,72 @@ | ||
from django.test import TestCase | ||
|
||
from experiment.models import Experiment | ||
from participant.models import Participant | ||
from result.models import Result | ||
from section.models import Playlist | ||
from session.models import Session | ||
|
||
from experiment.actions import Trial | ||
from experiment.rules.speech2song import next_repeated_representation, next_single_representation, sound, Speech2Song | ||
from experiment.serializers import serialize_actions | ||
|
||
|
||
class Speech2SongTest(TestCase): | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
section_csv = ("transforming,Sometimes behave so strangely.wav,0,2.14,s2s/TEST/Sometimes behave so strangely.wav,1,0\n" | ||
"transforming,And a joy it would be.wav,0,0.94,s2s/EN/Transforming/And a joy it would be.wav,1,1\n" | ||
"non-transforming,The limpid Walbrook.wav,0,1.20,s2s/EN/Non-Transforming/The limpid Walbrook.wav,0,1\n" | ||
"transforming,De abacaxi não tem.wav,0,1.19,s2s/BP/Transforming/De abacaxi não tem.wav,1,2\n" | ||
"non-transforming,Minha sobrinha.wav,0,0.99,s2s/BP/Non-Transforming/Minha sobrinha.wav,0,2\n" | ||
"transforming,三分钟读一页书.wav,0,1.51,s2s/MC/Transforming/三分钟读一页书.wav,1,3\n" | ||
"non-transforming,网上有地图.wav,0,1.13,s2s/MC/Non-Transforming/网上有地图.wav,0,3\n" | ||
"transforming,Hermit Thrush1.wav,0,1.19,s2s/ENV/Transforming/Hermit Thrush1.wav,1,4\n" | ||
"non-transforming,Snow walking.wav,0,1.30,s2s/ENV/Non-Transforming/Snow walking.wav,0,4\n" | ||
) | ||
cls.playlist = Playlist.objects.create(name='TestSpeech2Song') | ||
cls.playlist.csv = section_csv | ||
cls.playlist.update_sections() | ||
cls.participant = Participant.objects.create() | ||
cls.experiment = Experiment.objects.create( | ||
rules='SPEECH_TO_SONG', slug='s2s', rounds=42) | ||
cls.session = Session.objects.create( | ||
experiment=cls.experiment, | ||
participant=cls.participant, | ||
playlist=cls.playlist | ||
) | ||
|
||
def test_sound_method(self): | ||
section = self.playlist.section_set.first() | ||
view = sound(section) | ||
self.assertEqual(type(view), Trial) | ||
|
||
def test_single_presentation(self): | ||
group = self.playlist.section_set.first().group | ||
actions = next_single_representation(self.session, True, int(group)) | ||
self.assertEqual(type(actions), list) | ||
|
||
def test_repeated_presentation(self): | ||
section = self.playlist.section_set.first() | ||
Result.objects.create( | ||
question_key='speech2song', | ||
session=self.session, | ||
section=section, | ||
score=2 | ||
) | ||
actions = next_repeated_representation(self.session, True) | ||
self.assertEqual(type(actions), list) | ||
|
||
def test_next_round(self): | ||
speech2song = Speech2Song() | ||
actions = speech2song.next_round(self.session) | ||
self.assertEqual(type(actions), list) | ||
|
||
def test_next_round_serialization(self): | ||
speech2song = Speech2Song() | ||
actions = speech2song.next_round(self.session) | ||
serialized = serialize_actions(actions) | ||
self.assertEqual(type(serialized), list) | ||
for s in serialized: | ||
self.assertEqual(type(s), dict) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just interested: Why could this be converted to a dict already? Shouldn't serialization ideally happen at the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not if we are using copies of the same object, which speech2song does. It makes on
Trial
object, and from that creates an array of[Trial]*n_representations
. As the serialization goes through the list of actions, it will have already converted the Playback's style object to adict
, so in the next step it will attempt to apply theto_dict
method again to thestyle
attribute. Took me quite a long time to understand what was going on and why.