class TestAudio(unittest.TestCase): def setUp(self): self.audio = Audio() def test_loadBacktracksWavOfEmptyFolder(self): self.audio.processed_waveDir = env.TEST_ROOT_DIR_PROCESSED_EMPTY_FOLDER self.audio.loadBacktracksWav() self.assertEquals(self.audio.tracksWav.house, []) self.assertEquals(self.audio.tracksWav.latin, []) self.assertEquals(self.audio.tracksWav.jazz, []) self.assertEquals(self.audio.tracksWav.hiphop, []) def test_loadBacktracksWav_With_One_House_File(self): self.audio.processed_waveDir = env.TEST_ROOT_DIR_PROCESSED_WAV_FOLDER self.audio.loadBacktracksWav() self.assertEquals(len(self.audio.tracksWav.house), 1) self.assertEquals(len(self.audio.tracksWav.latin), 0) self.assertEquals(len(self.audio.tracksWav.jazz), 3) self.assertEquals(len(self.audio.tracksWav.hiphop), 0) self.assertEquals( self.audio.tracksWav.house[0], os.path.join(self.audio.processed_waveDir, "house", "metro1.wav")) def test_pickRandomSample_Of_Non_Existing_Category(self): self.audio.pickRandomSample("non-existing") self.assertEquals(self.audio.activeSample, None) def test_pickRandomSample_Of_ExistingCategory(self): self.audio.processed_waveDir = env.TEST_ROOT_DIR_PROCESSED_WAV_FOLDER self.audio.loadBacktracksWav() self.audio.pickRandomSample("jazz") self.assertNotEqual(self.audio.activeSample, None) self.assertEqual( self.audio.activeSample[0] in self.audio.tracksWav.jazz, True) self.assertGreaterEqual(self.audio.activeSample[1], 0) self.assertLessEqual(self.audio.activeSample[1], len(self.audio.tracksWav.jazz)) def tearDown(self): del self.audio
class TestAudio(unittest.TestCase): def setUp(self): pass def test_emptyTest(self): self.assertEqual(0, 0) def test_whenSoundIsCreatedMixerVolumeIsSetToVolLow(self): self.sound = Audio() # .3 is choose arbitraty because .1 is not always correctly rounded self.assertLess(round(pygame.mixer.music.get_volume()), .3) def test_pickRandomSampleOfAnEmptyArrayDontRaiseError(self): self.sound = Audio() try: self.sound.pickRandomSample([]) except Exception: self.fail("pickRandomSample([]) raised Exception unexpectedly !") # def test_loadAndPlayMetronomeTick(self): # self.tick = Sound().metroTick # try: # pygame.mixer.music.load(self.tick) # except Exception: # self.fail( # "pygame.mixer.music.load(self.metroTick) raised Exception unexpectedly!") # try: # pygame.mixer.music.play() # except Exception: # self.fail("pygame.mixer.music.play() raised Exception unexpectedly!") def test_setVolumeOver100ShouldMakeVolume100(self): newVolume = 150 self.sound = Audio() self.sound.setVolume(newVolume) realVolume = pygame.mixer.music.get_volume() self.assertLessEqual(round(realVolume), round(1))
def test_setVolumeOver100ShouldMakeVolume100(self): newVolume = 150 self.sound = Audio() self.sound.setVolume(newVolume) realVolume = pygame.mixer.music.get_volume() self.assertLessEqual(round(realVolume), round(1))
def test_pickRandomSampleOfAnEmptyArrayDontRaiseError(self): self.sound = Audio() try: self.sound.pickRandomSample([]) except Exception: self.fail("pickRandomSample([]) raised Exception unexpectedly !")
def test_whenSoundIsCreatedMixerVolumeIsSetToVolLow(self): self.sound = Audio() # .3 is choose arbitraty because .1 is not always correctly rounded self.assertLess(round(pygame.mixer.music.get_volume()), .3)
def setUp(self): self.audio = Audio()
def sliderMoved(self, value): mSound = Audio.setVolume(None, value)
def changeVolume(self, offset ): actualVol = Audio.getVolume() if actualVol + offset <= 0.01: Autoload().getInstanceAudio().setVolume(0) else: Autoload().getInstanceAudio().setVolume(actualVol+offset)