rind: Various testing improvements

- Add a gtk.notify_loop() for running any queued notifications
- Add a gtk.timeout_loop() for running a main loop for a specificed
  amount of time
- Prevent filtering warnings produced by some tests

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-05-19 09:28:01 -04:00
parent 2e98dc2feb
commit 61a3c32c79
6 changed files with 21 additions and 10 deletions

View File

@ -185,7 +185,7 @@ class TestAutoPause(unittest.TestCase):
self.assertEqual(autopause.Label.get_text(), "About 10 seconds")
self.assertIsNotNone(autopause.PopCB)
gtk.main_loop(delay=5.2, iteration_delay=0.02)
gtk.timeout_loop(5.75, iteration_delay=0.05)
self.assertIsNone(autopause.PopCB)
self.assertFalse(autopause.Popover.is_visible())

View File

@ -75,6 +75,7 @@ class TestAudioWidgets(unittest.TestCase):
curds.playlist.lookup("Libraries").lookup(test_album)
curds.playlist.library.join()
gtk.notify_loop()
widgets.Next.clicked()
self.assertEqual(playbin.get_state(), Gst.State.PLAYING)
@ -82,6 +83,7 @@ class TestAudioWidgets(unittest.TestCase):
track = curds.playlist.Root.track
widgets.Next.clicked()
gtk.main_loop(delay=0.1)
self.assertEqual(playbin.get_state(), Gst.State.PLAYING)
self.assertNotEqual(curds.playlist.Root.track, track)
track2 = curds.playlist.Root.track
@ -93,6 +95,7 @@ class TestAudioWidgets(unittest.TestCase):
track3 = curds.playlist.Root.next()
widgets.NEXT_TRACK = track3
widgets.Next.clicked()
gtk.main_loop(delay=0.2)
self.assertEqual(playbin.get_state(), Gst.State.PLAYING)
self.assertEqual(curds.playlist.Root.track, track3)

View File

@ -61,8 +61,20 @@ def can_activate_entry(widget, signal):
def main_loop(delay=0.0, iteration_delay=0.0):
time.sleep(delay)
while Gtk.events_pending():
Gtk.main_iteration_do(True)
time.sleep(iteration_delay)
Gtk.main_iteration_do(True)
def notify_loop(delay=0.0, iteration_delay=0.0):
time.sleep(delay)
while curds.notify.run_queued():
time.sleep(iteration_delay)
main_loop()
def timeout_loop(timeout, iteration_delay=0.0):
timeout = time.time() + timeout
while time.time() <= timeout:
time.sleep(iteration_delay)
main_loop()
def type_focused(type):
return isinstance(Window.get_focus(), type)

View File

@ -117,9 +117,8 @@ class TestPlaylistView(unittest.TestCase):
for i in range(1, 11):
track = curds.Track.lookup(os.path.join(test_album, f"{i:02} - Test Track {i:02}.ogg"))
plist.add(track)
while curds.notify.run_queued(): pass
gtk.notify_loop()
gtk.main_loop()
self.assertEqual(self.row_inserted, 10)
view.Model.disconnect(cb)
@ -130,7 +129,7 @@ class TestPlaylistView(unittest.TestCase):
for i in range(1, 11):
track = curds.Track.lookup(os.path.join(test_album, f"{i:02} - Test Track {i:02}.ogg"))
plist.add(track)
while curds.notify.run_queued(): pass
gtk.notify_loop()
self.assertEqual(view.Runtime.get_text(), f" {plist.runtime()} ")
def test_stream_start(self):
@ -141,7 +140,7 @@ class TestPlaylistView(unittest.TestCase):
for i in range(1, 11):
track = curds.Track.lookup(os.path.join(test_album, f"{i:02} - Test Track {i:02}.ogg"))
plist.add(track)
while curds.notify.run_queued(): pass
gtk.notify_loop()
for i in range(10):
plist.current = i

View File

@ -1,6 +1,5 @@
# Copyright 2019 (c) Anna Schumaker.
from . import gtk
from . import node
import curds
import time
import unittest
@ -8,7 +7,7 @@ from gi.repository import Gtk, GObject, GLib
class TestGtk(unittest.TestCase):
def setUp(self):
node.reset()
curds.reset()
def test_builder(self):
self.assertIsInstance(gtk.Builder, Gtk.Builder)

View File

@ -1,7 +1,6 @@
# Copyright 2019 (c) Anna Schumaker.
from . import gtk
from . import library
from . import node
import curds
import os
import unittest
@ -12,7 +11,6 @@ test_album = os.path.abspath("./trier/Test Library/Test Artist 02/Test Album 1")
class TestLibrary(unittest.TestCase):
def setUp(self):
curds.reset()
node.reset()
def tearDownClass():
curds.stop()