~timo-jyrinki/ubuntu/trusty/pitivi/backport_utopic_fixes

« back to all changes in this revision

Viewing changes to tests/test_system.py

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2014-04-05 15:28:16 UTC
  • mfrom: (6.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20140405152816-6lijoax4cngiz5j5
Tags: 0.93-3
* debian/control:
  + Depend on python-gi (>= 3.10), older versions do not work
    with pitivi (Closes: #732813).
  + Add missing dependency on gir1.2-clutter-gst-2.0 (Closes: #743692).
  + Add suggests on gir1.2-notify-0.7 and gir1.2-gnomedesktop-3.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# Pitivi video editor
 
3
#
 
4
#       tests/test_system.py
 
5
#
 
6
# Copyright (c) 2012, Jean-François Fortin Tam <nekohayo@gmail.com>
 
7
#
 
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.
 
12
#
 
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.
 
17
#
 
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.
 
22
 
 
23
from unittest import TestCase
 
24
 
 
25
from pitivi.utils.system import System, getSystem, GnomeSystem, \
 
26
    INHIBIT_LOGOUT, INHIBIT_SUSPEND, INHIBIT_SESSION_IDLE, \
 
27
    INHIBIT_USER_SWITCHING
 
28
 
 
29
 
 
30
class TestSystem(TestCase):
 
31
    def setUp(self):
 
32
        self.system = System()
 
33
 
 
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"))
 
42
 
 
43
    def testScreensaverInhibit(self):
 
44
        #check that we start of uninhibited
 
45
        self.assertTrue(not self.system.screensaverIsInhibited())
 
46
 
 
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())
 
53
 
 
54
        #check that adding/removing is consistent with multiple keys
 
55
        for c in range(0, 5):
 
56
            self.system.inhibitScreensaver(str(c))
 
57
            self.assertTrue(self.system.screensaverIsInhibited(str(c)))
 
58
 
 
59
        for c in range(0, 5):
 
60
            self.system.uninhibitScreensaver(str(c))
 
61
            self.assertTrue(not self.system.screensaverIsInhibited(str(c)))
 
62
 
 
63
        self.assertTrue(not self.system.screensaverIsInhibited())
 
64
 
 
65
    def testSleepInhibit(self):
 
66
        #check that we start of uninhibited
 
67
        self.assertTrue(not self.system.sleepIsInhibited())
 
68
 
 
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())
 
75
 
 
76
        #check that adding/removing is consistent with multiple keys
 
77
        for c in range(0, 5):
 
78
            self.system.inhibitSleep(str(c))
 
79
            self.assertTrue(self.system.sleepIsInhibited(str(c)))
 
80
 
 
81
        for c in range(0, 5):
 
82
            self.system.uninhibitSleep(str(c))
 
83
            self.assertTrue(not self.system.sleepIsInhibited(str(c)))
 
84
 
 
85
        self.assertTrue(not self.system.sleepIsInhibited())
 
86
 
 
87
 
 
88
class TestGnomeSystem(TestCase):
 
89
 
 
90
    def setUp(self):
 
91
        self.system = getSystem()
 
92
 
 
93
    def testPowerInhibition(self):
 
94
        if not isinstance(self.system, GnomeSystem):
 
95
            # We can only test this on a Gnome system.
 
96
            return
 
97
 
 
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.
 
102
            return
 
103
 
 
104
        self.system.inhibitScreensaver('1')
 
105
        self.assertTrue(self.system.session_iface.IsInhibited(
 
106
            INHIBIT_SESSION_IDLE))
 
107
 
 
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(
 
116
            INHIBIT_SUSPEND))
 
117
        self.assertTrue(self.system.session_iface.IsInhibited(
 
118
            INHIBIT_LOGOUT))
 
119
 
 
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(
 
126
            INHIBIT_SUSPEND))
 
127
        self.assertFalse(self.system.session_iface.IsInhibited(
 
128
            INHIBIT_LOGOUT))
 
129
 
 
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))