コード例 #1
0
    def tearDown(self):
        self.interface.stop_all()
        os.system('pkill -f key-mapper-service')

        for _ in range(10):
            time.sleep(0.1)
            if not is_service_running():
                break

        self.assertFalse(is_service_running())
コード例 #2
0
ファイル: test_daemon.py プロジェクト: hixan/key-mapper
    def test_get_dbus_interface(self):
        # no daemon runs, should return an instance of the object instead
        self.assertFalse(is_service_running())
        self.assertIsInstance(get_dbus_interface(), Daemon)
        self.assertIsNone(get_dbus_interface(False))

        subprocess.check_output = lambda *args: None
        self.assertTrue(is_service_running())
        # now it actually tries to use the dbus, but it fails
        # because none exists, so it returns an instance again
        self.assertIsInstance(get_dbus_interface(), Daemon)
        self.assertIsNone(get_dbus_interface(False))

        class FakeConnection:
            pass

        type(SystemBus()).get = lambda *args: FakeConnection()
        self.assertIsInstance(get_dbus_interface(), FakeConnection)
        self.assertIsInstance(get_dbus_interface(False), FakeConnection)
コード例 #3
0
    def test_connect(self):
        os_system_history = []
        os.system = os_system_history.append

        self.assertFalse(is_service_running())
        # no daemon runs, should try to run it via pkexec instead.
        # It fails due to the patch and therefore exits the process
        self.assertRaises(SystemExit, Daemon.connect)
        self.assertEqual(len(os_system_history), 1)
        self.assertIsNone(Daemon.connect(False))

        class FakeConnection:
            pass

        type(SystemBus()).get = lambda *args: FakeConnection()
        self.assertIsInstance(Daemon.connect(), FakeConnection)
        self.assertIsInstance(Daemon.connect(False), FakeConnection)