forked from autokey/autokey
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_headless.py
More file actions
54 lines (44 loc) · 2.04 KB
/
Copy pathtest_headless.py
File metadata and controls
54 lines (44 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Copyright (C) 2021 BlueDrink9
# 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 3 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, see <http://www.gnu.org/licenses/>.
import logging
import os
import sys
import subprocess
import unittest
from unittest.mock import patch
import pytest
skip = pytest.mark.skip
import hamcrest as hm
import autokey.headless_app as headless
import tests.helpers_for_tests as testhelpers
logger = __import__("autokey.logger").logger.get_logger(__name__)
def ret_arg(arg):
return arg
def get_errors_in_log(caplog):
errors = [record for record in caplog.get_records('call') if record.levelno >= logging.ERROR]
return errors
@pytest.mark.xfail(reason="Test requires X11/xhost and is incompatible with Wayland.")
@patch('autokey.dbus_service.AppService' , unittest.mock.MagicMock())
@patch('sys.argv', ['autokey-app-testing'])
def test_application_runs_without_errors(caplog, tmp_path):
config = str(testhelpers.make_dummy_config(tmp_path))
backup = str(tmp_path / "autokey.json~")
confman_module_path = "autokey.configmanager.configmanager"
with \
patch(confman_module_path + ".CONFIG_DEFAULT_FOLDER", str(tmp_path)), \
patch(confman_module_path + ".CONFIG_FILE", config), \
patch(confman_module_path + ".CONFIG_FILE_BACKUP", backup):
subprocess.call(["xhost", "+SI:localuser:{}".format(os.environ.get('USER'))])
app = headless.Application()
with pytest.raises(SystemExit):
app.shutdown()
hm.assert_that(get_errors_in_log(caplog), hm.empty())