1
# -*- coding: utf-8 -*-
6
# Copyright (c) 2012, Jean-François Fortin Tam <nekohayo@gmail.com>
8
# This program is free software; you can redistribute it and/or
9
# modify it under the terms of the GNU Lesser General Public
10
# License as published by the Free Software Foundation; either
11
# version 2.1 of the License, or (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
# Lesser General Public License for more details.
18
# You should have received a copy of the GNU Lesser General Public
19
# License along with this program; if not, write to the
20
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21
# Boston, MA 02110-1301, USA.
23
from unittest import TestCase
25
from pitivi.utils.system import System, getSystem, GnomeSystem, \
26
INHIBIT_LOGOUT, INHIBIT_SUSPEND, INHIBIT_SESSION_IDLE, \
27
INHIBIT_USER_SWITCHING
30
class TestSystem(TestCase):
32
self.system = System()
34
def testGetUniqueFilename(self):
35
self.assertNotEqual(self.system.getUniqueFilename("a/b"),
36
self.system.getUniqueFilename("a%47b"))
37
self.assertNotEqual(self.system.getUniqueFilename("a%b"),
38
self.system.getUniqueFilename("a%37b"))
39
self.assertNotEqual(self.system.getUniqueFilename("a%/b"),
40
self.system.getUniqueFilename("a%37%3747b"))
41
self.assertEqual("a b", self.system.getUniqueFilename("a b"))
43
def testScreensaverInhibit(self):
44
#check that we start of uninhibited
45
self.assertTrue(not self.system.screensaverIsInhibited())
47
#inhibit and check that we are
48
self.system.inhibitScreensaver("a")
49
self.assertTrue(self.system.screensaverIsInhibited())
50
#uninhibit and check that we are
51
self.system.uninhibitScreensaver("a")
52
self.assertTrue(not self.system.screensaverIsInhibited())
54
#check that adding/removing is consistent with multiple keys
56
self.system.inhibitScreensaver(str(c))
57
self.assertTrue(self.system.screensaverIsInhibited(str(c)))
60
self.system.uninhibitScreensaver(str(c))
61
self.assertTrue(not self.system.screensaverIsInhibited(str(c)))
63
self.assertTrue(not self.system.screensaverIsInhibited())
65
def testSleepInhibit(self):
66
#check that we start of uninhibited
67
self.assertTrue(not self.system.sleepIsInhibited())
69
#inhibit and check that we are
70
self.system.inhibitSleep("a")
71
self.assertTrue(self.system.sleepIsInhibited())
72
#uninhibit and check that we are
73
self.system.uninhibitSleep("a")
74
self.assertTrue(not self.system.sleepIsInhibited())
76
#check that adding/removing is consistent with multiple keys
78
self.system.inhibitSleep(str(c))
79
self.assertTrue(self.system.sleepIsInhibited(str(c)))
82
self.system.uninhibitSleep(str(c))
83
self.assertTrue(not self.system.sleepIsInhibited(str(c)))
85
self.assertTrue(not self.system.sleepIsInhibited())
88
class TestGnomeSystem(TestCase):
91
self.system = getSystem()
93
def testPowerInhibition(self):
94
if not isinstance(self.system, GnomeSystem):
95
# We can only test this on a Gnome system.
98
if not self.system.session_iface.IsInhibited(
99
INHIBIT_LOGOUT | INHIBIT_USER_SWITCHING | INHIBIT_SUSPEND |
100
INHIBIT_SESSION_IDLE):
101
# Other programs are inhibiting, cannot test.
104
self.system.inhibitScreensaver('1')
105
self.assertTrue(self.system.session_iface.IsInhibited(
106
INHIBIT_SESSION_IDLE))
108
self.system.inhibitSleep('2')
109
# Screensaver should be able to turn off, but
110
self.assertFalse(self.system.session_iface.IsInhibited(
111
INHIBIT_SESSION_IDLE))
112
# suspend (sleep, suspend, shutdown) and logout should be inhibited.
113
# IsInhibited will return True if just one is inhibited, so we
114
# check both separately.
115
self.assertTrue(self.system.session_iface.IsInhibited(
117
self.assertTrue(self.system.session_iface.IsInhibited(
120
self.system.uninhibitSleep('2')
121
# Screensaver should now be blocked.
122
self.assertTrue(self.system.session_iface.IsInhibited(
123
INHIBIT_SESSION_IDLE))
124
# Suspend and logout should be unblocked.
125
self.assertFalse(self.system.session_iface.IsInhibited(
127
self.assertFalse(self.system.session_iface.IsInhibited(
130
self.system.uninhibitScreensaver('1')
131
# Now everything should be unblocked.
132
self.assertFalse(self.system.session_iface.IsInhibited(
133
INHIBIT_LOGOUT | INHIBIT_USER_SWITCHING | INHIBIT_SUSPEND |
134
INHIBIT_SESSION_IDLE))