Skip to content

Commit

Permalink
Merge pull request #63 from sezanzeb/discoverer-test-fix
Browse files Browse the repository at this point in the history
Fixed the discoverer test
  • Loading branch information
kassoulet committed Jan 17, 2022
2 parents 735fffe + 1e1af55 commit e266cea
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions tests/testcases/discoverer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,27 @@ class DiscovererQueueTest(unittest.TestCase):
def setUp(self):
self.gio_settings = get_gio_settings()
queue = TaskQueue()
parent = 'file:https://' + os.getcwd()
sound_files = [
SoundFile(parent + '/tests/test%20data/audio/b/c.mp3'),
SoundFile(parent + '/tests/test%20data/audio/a.wav'),
SoundFile(parent + '/tests/test%20data/audio/strângë chàrs фズ.wav'),
SoundFile(parent + '/tests/test%20data/empty/a'),
SoundFile(parent + '/tests/test%20data/empty/b/c')
parent_dir = 'file:https://' + os.getcwd()
self.sound_files = [
SoundFile(parent_dir + '/tests/test%20data/audio/b/c.mp3'),
SoundFile(parent_dir + '/tests/test%20data/audio/a.wav'),
SoundFile(parent_dir + '/tests/test%20data/empty/b/c'),
# add_discoverers will split it here into two tasks or something. Make sure
# each of them gets at least one valid audio file in order to test that they
# are doing their stuff in parallel.
SoundFile(parent_dir + '/tests/test%20data/audio/strângë chàrs фズ.wav'),
SoundFile(parent_dir + '/tests/test%20data/empty/a'),
]
self.queue = queue
self.sound_files = sound_files

def wait_for_queue(self):
while len(self.queue.done) < len(self.queue.all_tasks):
# wait for the test to copmlete
time.sleep(0.01)
gtk_iteration()

def tearDown(self):
self.wait_for_queue()

def test_add_discoverers(self):
sound_files = self.sound_files
Expand All @@ -63,20 +74,21 @@ def test_add_discoverers(self):
self.assertFalse(sound_file.readable)

queue.run()
# two tasks are running at the same time
self.assertEqual(len(queue.running), 2)

# add_discoverers creates only one task per job, each task handles
# multiple sound_files, as opposed to the converter, which only
# works on a single sound_file.
self.assertEqual(len(queue.all_tasks), 2)

while len(queue.done) < 2:
time.sleep(0.01)
gtk_iteration()
self.wait_for_queue()

# correctly figures out which sound_files contain readable information
self.assertTrue(sound_files[0].readable)
self.assertTrue(sound_files[1].readable)
self.assertTrue(sound_files[2].readable)
self.assertFalse(sound_files[3].readable)
self.assertFalse(sound_files[2].readable)
self.assertTrue(sound_files[3].readable)
self.assertFalse(sound_files[4].readable)


Expand Down

0 comments on commit e266cea

Please sign in to comment.