diff --git a/qubes/tests/__init__.py b/qubes/tests/__init__.py index 63bbd5c6..e709c427 100644 --- a/qubes/tests/__init__.py +++ b/qubes/tests/__init__.py @@ -779,6 +779,7 @@ def load_tests(loader, tests, pattern): # pylint: disable=unused-argument for modname in ( # unit tests 'qubes.tests.events', + 'qubes.tests.devices', 'qubes.tests.init1', 'qubes.tests.vm.init', 'qubes.tests.storage', diff --git a/qubes/tests/devices.py b/qubes/tests/devices.py new file mode 100644 index 00000000..f4aa3be7 --- /dev/null +++ b/qubes/tests/devices.py @@ -0,0 +1,82 @@ +#!/usr/bin/python2 -O +# vim: fileencoding=utf-8 +# pylint: disable=protected-access,pointless-statement + +# +# The Qubes OS Project, https://www.qubes-os.org/ +# +# Copyright (C) 2015-2016 Joanna Rutkowska +# Copyright (C) 2015-2016 Wojtek Porczyk +# +# 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. +# + +import qubes.devices + +import qubes.tests + +class TC_00_DeviceCollection(qubes.tests.QubesTestCase): + def setUp(self): + self.emitter = qubes.tests.TestEmitter() + self.collection = qubes.devices.DeviceCollection(self.emitter, 'testclass') + + def test_000_init(self): + self.assertFalse(self.collection._set) + + def test_001_attach(self): + self.collection.attach('testdev') + self.assertEventFired(self.emitter, 'device-pre-attach:testclass') + self.assertEventFired(self.emitter, 'device-attach:testclass') + self.assertEventNotFired(self.emitter, 'device-pre-detach:testclass') + self.assertEventNotFired(self.emitter, 'device-detach:testclass') + + def test_002_detach(self): + self.collection.attach('testdev') + self.collection.detach('testdev') + self.assertEventFired(self.emitter, 'device-pre-attach:testclass') + self.assertEventFired(self.emitter, 'device-attach:testclass') + self.assertEventFired(self.emitter, 'device-pre-detach:testclass') + self.assertEventFired(self.emitter, 'device-detach:testclass') + + def test_010_empty_detach(self): + with self.assertRaises(LookupError): + self.collection.detach('testdev') + + def test_011_double_attach(self): + self.collection.attach('testdev') + + with self.assertRaises(LookupError): + self.collection.attach('testdev') + + def test_012_double_detach(self): + self.collection.attach('testdev') + self.collection.detach('testdev') + + with self.assertRaises(LookupError): + self.collection.detach('testdev') + + +class TC_01_DeviceManager(qubes.tests.QubesTestCase): + def setUp(self): + self.emitter = qubes.tests.TestEmitter() + self.manager = qubes.devices.DeviceManager(self.emitter) + + def test_000_init(self): + self.assertEqual(self.manager, {}) + + def test_001_missing(self): + self.manager['testclass'].attach('testdev') + self.assertEventFired(self.emitter, 'device-attached:testclass') + diff --git a/qubes/tests/vm/init.py b/qubes/tests/vm/init.py index 22138c95..83dd8d55 100644 --- a/qubes/tests/vm/init.py +++ b/qubes/tests/vm/init.py @@ -32,60 +32,6 @@ import qubes.vm import qubes.tests -class TC_00_DeviceCollection(qubes.tests.QubesTestCase): - def setUp(self): - self.emitter = qubes.tests.TestEmitter() - self.collection = qubes.vm.DeviceCollection(self.emitter, 'testclass') - - def test_000_init(self): - self.assertFalse(self.collection._set) - - def test_001_attach(self): - self.collection.attach('testdev') - self.assertEventFired(self.emitter, 'device-pre-attached:testclass') - self.assertEventFired(self.emitter, 'device-attached:testclass') - self.assertEventNotFired(self.emitter, 'device-pre-detached:testclass') - self.assertEventNotFired(self.emitter, 'device-detached:testclass') - - def test_002_detach(self): - self.collection.attach('testdev') - self.collection.detach('testdev') - self.assertEventFired(self.emitter, 'device-pre-attached:testclass') - self.assertEventFired(self.emitter, 'device-attached:testclass') - self.assertEventFired(self.emitter, 'device-pre-detached:testclass') - self.assertEventFired(self.emitter, 'device-detached:testclass') - - def test_010_empty_detach(self): - with self.assertRaises(LookupError): - self.collection.detach('testdev') - - def test_011_double_attach(self): - self.collection.attach('testdev') - - with self.assertRaises(LookupError): - self.collection.attach('testdev') - - def test_012_double_detach(self): - self.collection.attach('testdev') - self.collection.detach('testdev') - - with self.assertRaises(LookupError): - self.collection.detach('testdev') - - -class TC_01_DeviceManager(qubes.tests.QubesTestCase): - def setUp(self): - self.emitter = qubes.tests.TestEmitter() - self.manager = qubes.vm.DeviceManager(self.emitter) - - def test_000_init(self): - self.assertEqual(self.manager, {}) - - def test_001_missing(self): - self.manager['testclass'].attach('testdev') - self.assertEventFired(self.emitter, 'device-attached:testclass') - - class TestVM(qubes.vm.BaseVM): qid = qubes.property('qid', type=int) name = qubes.property('name') diff --git a/rpm_spec/core-dom0.spec b/rpm_spec/core-dom0.spec index 77eb10e4..88759974 100644 --- a/rpm_spec/core-dom0.spec +++ b/rpm_spec/core-dom0.spec @@ -251,6 +251,7 @@ fi %{python_sitelib}/qubes/tests/__init__.py* %{python_sitelib}/qubes/tests/run.py* +%{python_sitelib}/qubes/tests/devices.py* %{python_sitelib}/qubes/tests/events.py* %{python_sitelib}/qubes/tests/init1.py* %{python_sitelib}/qubes/tests/init2.py*