Skip to content

Commit 3fc8b7a

Browse files
author
Philipp Fleischhacker
authored
[STCC-169] basic sound block testcases (#90)
1 parent 0cd9b0c commit 3fc8b7a

File tree

3 files changed

+73
-13
lines changed

3 files changed

+73
-13
lines changed

config/default.ini

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ version: 0.9.1
66
build_name: Aegean cat
77
build_number: 939
88

9-
109
;-------------------------------------------------------------------------------
1110
[CATROBAT]
1211
; TODO: update this field manually every time the hierarchy changes

src/scratchtocatrobat/scratch/scratch3visitor/sound.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def visitPlay(blockcontext):
99

1010
def visitPlayuntildone(blockcontext):
1111
sound = visitGeneric(blockcontext, 'SOUND_MENU')
12-
return ['playSoundAndWait', sound]
12+
return ['doPlaySoundAndWait', sound]
1313

1414
def visitStopallsounds(blockcontext):
1515
return ["stopAllSounds"]

src/scratchtocatrobat/scratch/scratch3visitor/test_scratch3.py

+72-11
Original file line numberDiff line numberDiff line change
@@ -237,24 +237,85 @@ def test_visitGotofrontback(self):
237237
converted_block = visitBlock(context)
238238
assert converted_block[0] == "comeToFront"
239239

240-
def test_visitCostumenumbername(self):
241-
context = create_block_context("looks_costumenumbername")
240+
# def test_visitCostumenumbername(self):
241+
# context = create_block_context("looks_costumenumbername")
242+
# testblock = context.block
243+
# addInputOfType(testblock, "CHANGE", TYPE_INT)
244+
# testblock.fields["NUMBER_NAME"] = ["name"]
245+
# testblock.fields["EFFECT"] = ["testeffect"]
246+
# converted_block = visitBlock(context)
247+
# assert converted_block[0] == "costumeName"
248+
#
249+
# testblock.fields["NUMBER_NAME"] = ["number"]
250+
# converted_block = visitBlock(context)
251+
# assert converted_block[0] == "costumeIndex"
252+
253+
def test_visitSize(self):
254+
context = create_block_context("looks_size")
255+
converted_block = visitBlock(context)
256+
assert converted_block[0] == "scale"
257+
258+
259+
260+
261+
262+
######### Sound Blocks #########################################
263+
def add_menu_block(self, context, opcode, menu_name, value):
264+
menu_block = add_new_block_to_context(context, opcode)
265+
menu_block.fields[menu_name] = [value]
266+
context.block.inputs[menu_name] = [1, menu_block.name]
267+
268+
def test_visitPlay(self):
269+
context = create_block_context("sound_play")
242270
testblock = context.block
243-
addInputOfType(testblock, "CHANGE", TYPE_INT)
244-
testblock.fields["NUMBER_NAME"] = ["name"]
245-
testblock.fields["EFFECT"] = ["testeffect"]
271+
272+
block2 = add_new_block_to_context(context, "sound_sounds_menu")
273+
block2.fields["SOUND_MENU"] = ["test_sound"]
274+
# addInputToBlock(testblock, "SOUND_MENU", block2.name, INPUTTYPE_BLOCK_NO_SHADOW)
275+
testblock.inputs["SOUND_MENU"] = [1, block2.name]
276+
246277
converted_block = visitBlock(context)
247-
assert converted_block[0] == "costumeName"
278+
assert converted_block[0] == "playSound:"
279+
assert converted_block[1] == "test_sound"
248280

249-
testblock.fields["NUMBER_NAME"] = ["number"]
281+
def test_visitPlayuntildone(self):
282+
context = create_block_context("sound_playuntildone")
283+
testblock = context.block
284+
self.add_menu_block(context, "sound_sounds_menu", "SOUND_MENU", "test_sound")
250285
converted_block = visitBlock(context)
251-
assert converted_block[0] == "costumeIndex"
286+
assert converted_block[0] == "doPlaySoundAndWait"
287+
assert converted_block[1] == "test_sound"
252288

253-
def test_visitSize(self):
254-
context = create_block_context("looks_size")
289+
def test_visitStopallsounds(self):
290+
context = create_block_context("sound_stopallsounds")
255291
converted_block = visitBlock(context)
256-
assert converted_block[0] == "scale"
292+
assert converted_block[0] == "stopAllSounds"
257293

294+
def test_visitClearsoundeffects(self):
295+
context = create_block_context("sound_cleareffects")
296+
converted_block = visitBlock(context)
297+
assert converted_block[0] == "clearSoundEffects"
298+
299+
def test_visitChangevolumeby(self):
300+
context = create_block_context("sound_changevolumeby")
301+
testblock = context.block
302+
addInputOfType(testblock, "VOLUME", TYPE_INT)
303+
converted_block = visitBlock(context)
304+
assert converted_block[0] == "changeVolumeBy:"
305+
assert converted_block[1] == 1234.0
306+
307+
def test_visitSetvolumeto(self):
308+
context = create_block_context("sound_setvolumeto")
309+
testblock = context.block
310+
addInputOfType(testblock, "VOLUME", TYPE_INT)
311+
converted_block = visitBlock(context)
312+
assert converted_block[0] == "setVolumeTo:"
313+
assert converted_block[1] == 1234.0
314+
315+
def test_visitVolume(self):
316+
context = create_block_context("sound_volume")
317+
converted_block = visitBlock(context)
318+
assert converted_block[0] == "volume"
258319

259320

260321
if __name__ == "__main__":

0 commit comments

Comments
 (0)