rind: Switch tests to the new gtk.main_loop() function

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-04-08 13:54:52 -04:00
parent dc3377bca5
commit ea0028e482
2 changed files with 14 additions and 27 deletions

View File

@ -25,21 +25,15 @@ class TestGst(unittest.TestCase):
def tearDown(self):
self.audio.playbin.set_state(Gst.State.READY)
self.audio.seek(value=0)
time.sleep(0.1)
self.main_loop()
gtk.main_loop(delay=0.1)
self.audio.disconnect()
def tearDownClass():
curds.stop()
def main_loop(self, delay=0.0):
time.sleep(delay)
while Gtk.events_pending():
Gtk.main_iteration_do(True)
def main_loop_until(self, state):
while self.state != state:
Gtk.main_iteration_do(True)
gtk.main_loop()
def on_state_changed(self, state):
self.state = state
@ -104,7 +98,7 @@ class TestGst(unittest.TestCase):
self.main_loop_until(Gst.State.PLAYING)
self.assertTrue( gst.ProgScale.get_show_fill_level())
self.main_loop(delay=0.1)
gtk.main_loop(delay=0.1)
self.assertGreater(self.audio.progress(), 0)
self.assertGreater(self.audio.position(), 0)
self.assertEqual( self.audio.duration(), 10.0)
@ -156,16 +150,16 @@ class TestGst(unittest.TestCase):
self.assertAlmostEqual(self.audio.get_property("volume"), 1.0)
self.audio.seek(value=50.0)
self.main_loop(delay=0.1)
gtk.main_loop(delay=0.1)
self.assertEqual(self.audio.duration(), 3.0)
self.assertEqual(self.audio.position(), 1.5)
self.assertEqual(gst.Position.get_text(), "00:01")
self.assertEqual(gst.Duration.get_text(), "-00:02")
self.audio.seek_step(step=0.5 * Gst.SECOND)
self.main_loop(delay=0.1)
self.assertEqual(self.audio_duration(), 3.0)
self.assertEqual(self.audio.position(), 1.5)
gtk.main_loop(delay=0.1)
self.assertEqual(self.audio.duration(), 3.0)
self.assertEqual(self.audio.position(), 2.0)
self.assertEqual(gst.Position.get_text(), "00:02")
self.assertEqual(gst.Duration.get_text(), "-00:01")
@ -190,8 +184,7 @@ class TestGst(unittest.TestCase):
self.audio.seek(value=90)
self.main_loop_until(Gst.State.PLAYING)
self.stream = False
while self.stream == False:
Gtk.main_iteration_do(True)
while self.stream == False: gtk.main_loop()
self.main_loop_until(Gst.State.PLAYING)
self.assertEqual(curds.PlaylistManager.lookup("Collection").current, 3)
self.assertNotEqual(curds.PlaylistManager.track, track2)

View File

@ -279,9 +279,7 @@ class TestManager(unittest.TestCase):
entry.set_text("gen(.*)2")
self.model.set_filter_text(entry)
while Gtk.events_pending():
time.sleep(0.1)
Gtk.main_iteration_do(True)
gtk.main_loop(iteration_delay=0.1)
self.assertEqual(self.model.filter_re.pattern, "gen(.*)2")
self.assertFalse(entry.get_style_context().has_class("warning"))
self.assertFalse(manager.SearchPopover.is_visible())
@ -303,30 +301,26 @@ class TestManager(unittest.TestCase):
self.assertFalse(manager.LibraryPopover.is_visible())
manager.LibraryAdd.clicked()
Gtk.main_iteration_do(True)
gtk.main_loop()
self.assertTrue(manager.LibraryPopover.is_visible())
self.assertEqual(len(plist_mgr.lookup("Library")), 0)
manager.LibraryCancel.clicked()
while Gtk.events_pending():
time.sleep(0.05)
Gtk.main_iteration_do(True)
gtk.main_loop(iteration_delay=0.1)
self.assertFalse(manager.LibraryPopover.is_visible())
self.assertEqual(len(plist_mgr.lookup("Library")), 0)
manager.LibraryAdd.clicked()
Gtk.main_iteration_do(True)
gtk.main_loop()
self.assertEqual(manager.LibraryChooser.get_filename(), music_dir)
self.assertTrue(manager.LibraryPopover.is_visible())
self.assertEqual(len(plist_mgr.lookup("Library")), 0)
manager.LibraryChooser.set_filename(test_album1)
while Gtk.events_pending(): Gtk.main_iteration_do(True)
gtk.main_loop(delay=0.1)
self.assertEqual(manager.LibraryChooser.get_filename(), test_album1)
manager.LibraryOk.clicked()
while Gtk.events_pending():
time.sleep(0.05)
Gtk.main_iteration_do(True)
gtk.main_loop(iteration_delay=0.1)
self.assertEqual(len(plist_mgr.lookup("Library")), 1)
self.assertFalse(manager.LibraryPopover.is_visible())