File: test_qltk_window.py

package info (click to toggle)
quodlibet 4.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,228 kB
  • sloc: python: 89,728; sh: 381; xml: 110; makefile: 91
file content (85 lines) | stat: -rw-r--r-- 2,349 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

from tests import TestCase, skipIf

from quodlibet.qltk.window import Window, on_first_map, Dialog
from quodlibet.util import InstanceTracker, is_osx

from .helper import realized


class TWindow(TestCase):
    def test_on_first_map(self):
        w = Window()

        calls = []

        def foo(*args):
            calls.append(args)

        on_first_map(w, foo, 1)
        w.show()
        self.assertEqual(calls, [(1,)])
        on_first_map(w, foo, 2)
        self.assertEqual(calls, [(1,), (2,)])
        w.destroy()

    def test_ctr(self):
        Window().destroy()

    def test_instance_tracking(self):
        class SomeWindow(Window, InstanceTracker):
            def __init__(self):
                super().__init__()
                self._register_instance()

        assert not SomeWindow.windows
        other = Window()
        a = SomeWindow()
        assert a in SomeWindow.windows
        assert a in SomeWindow.instances()
        a.destroy()
        assert not SomeWindow.instances()
        assert SomeWindow.windows
        other.destroy()
        assert not SomeWindow.windows

    def test_show_maybe(self):
        Window.prevent_inital_show(True)
        w = Window()
        w.show_maybe()
        assert not w.get_visible()
        Window.prevent_inital_show(False)
        w.show_maybe()
        assert w.get_visible()
        w.destroy()

    def test_use_header_bar(self):
        w = Window(title="foo")
        w.use_header_bar()
        self.assertEqual(w.get_title(), "foo")
        w.destroy()

        w = Window()
        w.use_header_bar()
        self.assertEqual(w.get_title(), None)
        w.destroy()

    @skipIf(is_osx(), "crashes on 10.13")
    def test_toggle_fullscreen(self):
        w = Window(title="foo")
        w.toggle_fullscreen()
        with realized(w):
            w.toggle_fullscreen()
            w.toggle_fullscreen()
        w.destroy()


class TDialog(TestCase):
    def test_add_icon_button(self):
        d = Dialog()
        w = d.add_icon_button("foo", "bar", 100)
        self.assertEqual(d.get_widget_for_response(100), w)