File: test_gtk.py

package info (click to toggle)
python-gbulb 0.6.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 244 kB
  • sloc: python: 1,851; makefile: 3
file content (54 lines) | stat: -rw-r--r-- 1,413 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pytest

try:
    import gi

    gi.require_version("Gtk", "3.0")

    from gi.repository import Gtk
except ImportError:  # pragma: no cover
    Gtk = None


@pytest.mark.skipif(not Gtk, reason="Gtk is not available")
class TestGtkEventLoopPolicy:
    def test_new_event_loop(self, gtk_policy):
        from gbulb.gtk import GtkEventLoop

        a = gtk_policy.new_event_loop()
        b = gtk_policy.new_event_loop()

        assert isinstance(a, GtkEventLoop)
        assert isinstance(b, GtkEventLoop)
        assert a != b
        assert a == gtk_policy.get_default_loop()

    def test_new_event_loop_application(self, gtk_policy):
        a = gtk_policy.new_event_loop()
        a.set_application(Gtk.Application())
        b = gtk_policy.new_event_loop()

        assert b._application is None

    def test_event_loop_recursion(self, gtk_loop):
        loop_count = 0

        def inner():
            nonlocal loop_count
            i = loop_count
            print("starting loop", loop_count)
            loop_count += 1

            if loop_count == 10:
                print(f"loop {i} stopped")
                gtk_loop.stop()
            else:
                gtk_loop.call_soon(inner)
                gtk_loop.run()
                print(f"loop {i} stopped")
                gtk_loop.stop()

        gtk_loop.call_soon(inner)
        gtk_loop.run_forever()

        assert loop_count == 10