input-remapper/tests/fakes.py

47 lines
1.4 KiB
Python
Raw Normal View History

2020-10-26 22:45:22 +00:00
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# key-mapper - GUI for device specific keyboard mappings
2020-10-26 22:45:22 +00:00
# Copyright (C) 2020 sezanzeb <proxima@hip70890b.de>
#
2020-10-31 13:02:59 +00:00
# This file is part of key-mapper.
2020-10-26 22:45:22 +00:00
#
2020-10-31 13:02:59 +00:00
# key-mapper is free software: you can redistribute it and/or modify
2020-10-26 22:45:22 +00:00
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
2020-10-31 13:02:59 +00:00
# key-mapper is distributed in the hope that it will be useful,
2020-10-26 22:45:22 +00:00
# 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
2020-10-31 13:02:59 +00:00
# along with key-mapper. If not, see <https://www.gnu.org/licenses/>.
2020-10-26 22:45:22 +00:00
2020-10-31 16:00:02 +00:00
"""Patch stuff to get reproducible tests."""
2020-10-26 22:45:22 +00:00
2020-10-31 16:00:02 +00:00
from unittest.mock import patch
2020-10-26 22:45:22 +00:00
2020-10-31 16:00:02 +00:00
fake_config_path = '/tmp/keymapper-test-config'
2020-10-31 14:22:58 +00:00
2020-10-31 16:00:02 +00:00
class UseFakes:
"""Provides fake functionality for alsaaudio and some services."""
def __init__(self):
self.patches = []
2020-10-31 14:29:25 +00:00
2020-10-31 16:00:02 +00:00
def patch(self):
"""Replace the functions with various fakes."""
# self.patches.append(patch.object(keymapper, 'foo', self.foo))
for p in self.patches:
p.__enter__()
2020-10-31 14:29:25 +00:00
2020-10-31 16:00:02 +00:00
def restore(self):
"""Restore functionality."""
for p in self.patches:
p.__exit__(None, None, None)
self.patches = []