Exemplo n.º 1
0
def playSound(filePath, volume, logger):
    pygame.mixer.stop()
    soundPlayer = pygame.mixer.Sound(filePath)
    setVolume(volume, soundPlayer)
    soundPlayer.play()
    print("Now playing: " + filePath)

    return soundPlayer
Exemplo n.º 2
0
    def test_setVolumeToValidValueNoSoundPlayer(self):
        pygame.mixer.init()
        newVolume = 0.5
        soundPlayer = ""
        setVolume(newVolume, soundPlayer)
        self.assertRaises(TypeError, pygame.mixer.Sound.get_volume, soundPlayer)

        pygame.mixer.quit()
Exemplo n.º 3
0
    def test_setOutOfBoundsVolume(self):
        pygame.mixer.init()
        newVolume = -0.5
        logger = IOTest()
        soundPlayer = playSound(self.filePath, self.initialVolume, logger)
        setVolume(newVolume, soundPlayer)
        self.assertNotEqual(-0.5, pygame.mixer.Sound.get_volume(soundPlayer))

        pygame.mixer.quit()
Exemplo n.º 4
0
    def test_setVolumeToMute(self):
        pygame.mixer.init()
        newVolume = 0
        logger = IOTest()
        soundPlayer = playSound(self.filePath, self.initialVolume, logger)
        setVolume(newVolume, soundPlayer)
        self.assertEqual(0, pygame.mixer.Sound.get_volume(soundPlayer))

        pygame.mixer.quit()
Exemplo n.º 5
0
    def test_setVolumeToValidValueDuringPlayback(self):
        pygame.mixer.init()
        newVolume = 0.5
        logger = IOTest()
        soundPlayer = playSound(self.filePath, self.initialVolume, logger)
        setVolume(newVolume, soundPlayer)
        self.assertEqual(0.5, pygame.mixer.Sound.get_volume(soundPlayer))

        pygame.mixer.quit()
Exemplo n.º 6
0
def playSound(filePath, volume, logger):
    pygame.mixer.stop()
    soundPlayer = pygame.mixer.Sound(filePath)
    setVolume(volume, soundPlayer)
    soundPlayer.play()

    filePathComponents = filePath.split("/")
    logger.showOutput("Now playing: " + filePathComponents[-1])

    return soundPlayer
Exemplo n.º 7
0
    def test_setOutOfBoundsVolume(self):
        pygame.mixer.init()
        filePath = "../src/Data/stubMusic/stub_bensound-dubstep.wav"
        initialVolume = 1
        newVolume = -1
        logger = IOTest()
        soundPlayer = playSound(filePath, initialVolume, logger)
        setVolume(newVolume, soundPlayer)
        self.assertNotEqual(-1, pygame.mixer.Sound.get_volume(soundPlayer))

        pygame.mixer.quit()
Exemplo n.º 8
0
    def test_setVolumeToValidValueDuringPlaybackMock(self):
        pygame.mixer.init()
        filePath = "../src/Data/stubMusic/stub_bensound-dubstep.wav"
        initialVolume = 1
        logger = IOTest()
        soundPlayer = playSound(filePath, initialVolume, logger)
        getVolume = MagicMock(return_value=0.5)
        setVolume(getVolume(), soundPlayer)
        self.assertEqual(0.5, pygame.mixer.Sound.get_volume(soundPlayer))

        pygame.mixer.quit()
Exemplo n.º 9
0
    def test_setVolumeToValidValueNoPlayback(self):
        pygame.mixer.init()
        filePath = "../src/Data/stubMusic/stub_bensound-dubstep.wav"
        initialVolume = 1
        newVolume = 0.5
        logger = IOTest()
        soundPlayer = playSound(filePath, initialVolume, logger)
        pygame.mixer.stop()
        setVolume(newVolume, soundPlayer)
        self.assertEqual(0.5, pygame.mixer.Sound.get_volume(soundPlayer))

        pygame.mixer.quit()
Exemplo n.º 10
0
    def test_setMultipleVolumesWithMock(self):
        pygame.mixer.init()
        filePath = "../../src/Data/stubMusic/stub_bensound-dubstep.wav"
        initialVolume = 1
        logger = IOTest()
        soundPlayer = playSound(filePath, initialVolume, logger)
        getVolume = MagicMock(side_effect=[0.5, 1, 0])
        setVolume(getVolume(), soundPlayer)
        setVolume(getVolume(), soundPlayer)
        setVolume(getVolume(), soundPlayer)
        self.assertEqual(0, pygame.mixer.Sound.get_volume(soundPlayer))

        pygame.mixer.quit()