1# This program is free software; you can redistribute it and/or modify
2# it under the terms of the GNU General Public License as published by
3# the Free Software Foundation; either version 2 of the License, or
4# (at your option) any later version.
5
6from gi.repository import Gtk
7
8from tests import TestCase
9
10from quodlibet import config
11from quodlibet.qltk.ccb import ConfigCheckButton, ConfigCheckMenuItem
12
13
14class TConfigCheckButton(TestCase):
15    def setUp(self):
16        config.init()
17
18    def tearDown(self):
19        config.quit()
20
21    def test_toggle(self):
22        config.set("memory", "bar", "on")
23        c = ConfigCheckButton("dummy", "memory", "bar")
24        c.set_active(True)
25        self.failUnless(config.getboolean("memory", "bar") and c.get_active())
26        c.set_active(False)
27        while Gtk.events_pending():
28            Gtk.main_iteration()
29        self.failIf(config.getboolean("memory", "bar") or c.get_active())
30
31    def test_populate(self):
32        # Assert that active state works
33        config.set("memory", "bar", "on")
34        c = ConfigCheckButton("dummy", "memory", "bar", populate=True)
35        while Gtk.events_pending():
36            Gtk.main_iteration()
37        self.failUnless(c.get_active())
38        # ...and inactive
39        config.set("memory", "bar", "off")
40        c = ConfigCheckButton("dummy", "memory", "bar", populate=True)
41        while Gtk.events_pending():
42            Gtk.main_iteration()
43        self.failIf(c.get_active())
44
45
46class TConfigCheckMenuItem(TestCase):
47    def setUp(self):
48        config.init()
49
50    def tearDown(self):
51        config.quit()
52
53    def test_toggle(self):
54        config.set("memory", "bar", "on")
55        c = ConfigCheckMenuItem("dummy", "memory", "bar")
56        c.set_active(True)
57        self.failUnless(config.getboolean("memory", "bar") and c.get_active())
58        c.set_active(False)
59        while Gtk.events_pending():
60            Gtk.main_iteration()
61        self.failIf(config.getboolean("memory", "bar") or c.get_active())
62
63    def test_populate(self):
64        # Assert that active state works
65        config.set("memory", "bar", "on")
66        c = ConfigCheckMenuItem("dummy", "memory", "bar", populate=True)
67        while Gtk.events_pending():
68            Gtk.main_iteration()
69        self.failUnless(c.get_active())
70        # ...and inactive
71        config.set("memory", "bar", "off")
72        c = ConfigCheckMenuItem("dummy", "memory", "bar", populate=True)
73        while Gtk.events_pending():
74            Gtk.main_iteration()
75        self.failIf(c.get_active())
76