2014-12-09 14:14:24 +01:00
|
|
|
#!/usr/bin/python2 -O
|
2015-01-19 18:03:23 +01:00
|
|
|
# vim: fileencoding=utf-8
|
|
|
|
|
|
|
|
#
|
|
|
|
# The Qubes OS Project, https://www.qubes-os.org/
|
|
|
|
#
|
|
|
|
# Copyright (C) 2014-2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
|
|
|
|
# Copyright (C) 2014-2015 Wojtek Porczyk <woju@invisiblethingslab.com>
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
2014-12-09 14:14:24 +01:00
|
|
|
|
|
|
|
import qubes.events
|
2015-01-05 14:41:59 +01:00
|
|
|
import qubes.tests
|
|
|
|
|
|
|
|
class TC_00_Emitter(qubes.tests.QubesTestCase):
|
2014-12-09 14:14:24 +01:00
|
|
|
def test_000_add_handler(self):
|
|
|
|
# need something mutable
|
|
|
|
testevent_fired = [False]
|
|
|
|
|
|
|
|
def on_testevent(subject, event):
|
2015-01-19 19:02:28 +01:00
|
|
|
# pylint: disable=unused-argument
|
2014-12-09 14:14:24 +01:00
|
|
|
if event == 'testevent':
|
|
|
|
testevent_fired[0] = True
|
|
|
|
|
|
|
|
emitter = qubes.events.Emitter()
|
|
|
|
emitter.add_handler('testevent', on_testevent)
|
2015-06-24 15:02:49 +02:00
|
|
|
emitter.events_enabled = True
|
2014-12-09 14:14:24 +01:00
|
|
|
emitter.fire_event('testevent')
|
|
|
|
self.assertTrue(testevent_fired[0])
|
|
|
|
|
|
|
|
|
|
|
|
def test_001_decorator(self):
|
|
|
|
class TestEmitter(qubes.events.Emitter):
|
|
|
|
def __init__(self):
|
|
|
|
super(TestEmitter, self).__init__()
|
|
|
|
self.testevent_fired = False
|
|
|
|
|
|
|
|
@qubes.events.handler('testevent')
|
|
|
|
def on_testevent(self, event):
|
|
|
|
if event == 'testevent':
|
|
|
|
self.testevent_fired = True
|
|
|
|
|
|
|
|
emitter = TestEmitter()
|
2015-06-24 15:02:49 +02:00
|
|
|
emitter.events_enabled = True
|
2014-12-09 14:14:24 +01:00
|
|
|
emitter.fire_event('testevent')
|
|
|
|
self.assertTrue(emitter.testevent_fired)
|