forked from qtile/qtile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_config.py
106 lines (79 loc) · 3.15 KB
/
test_config.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Copyright (c) 2011 Florian Mounier
# Copyright (c) 2014 Sean Vig
# Copyright (c) 2014 Tycho Andersen
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from pathlib import Path
import pytest
from libqtile import config, confreader, utils
configs_dir = Path(__file__).resolve().parent / "configs"
def load_config(name):
f = confreader.Config(configs_dir / name)
f.load()
return f
def test_validate():
# bad key
f = load_config("basic.py")
f.keys[0].key = "nonexistent"
with pytest.raises(confreader.ConfigError):
f.validate()
# bad modifier
f = load_config("basic.py")
f.keys[0].modifiers = ["nonexistent"]
with pytest.raises(confreader.ConfigError):
f.validate()
def test_basic():
f = load_config("basic.py")
assert f.keys
def test_syntaxerr():
with pytest.raises(SyntaxError):
load_config("syntaxerr.py")
def test_falls_back():
f = load_config("basic.py")
# We just care that it has a default, we don't actually care what the
# default is; don't assert anything at all about the default in case
# someone changes it down the road.
assert hasattr(f, "follow_mouse_focus")
def cmd(x):
return None
def test_ezkey():
key = config.EzKey('M-A-S-a', cmd, cmd)
modkey, altkey = (config.EzConfig.modifier_keys[i] for i in 'MA')
assert key.modifiers == [modkey, altkey, 'shift']
assert key.key == 'a'
assert key.commands == (cmd, cmd)
key = config.EzKey('M-<Tab>', cmd)
assert key.modifiers == [modkey]
assert key.key == 'Tab'
assert key.commands == (cmd,)
with pytest.raises(utils.QtileError):
config.EzKey('M--', cmd)
with pytest.raises(utils.QtileError):
config.EzKey('Z-Z-z', cmd)
with pytest.raises(utils.QtileError):
config.EzKey('asdf', cmd)
with pytest.raises(utils.QtileError):
config.EzKey('M-a-A', cmd)
def test_ezclick_ezdrag():
btn = config.EzClick('M-1', cmd)
assert btn.button == 'Button1'
assert btn.modifiers == [config.EzClick.modifier_keys['M']]
btn = config.EzDrag('A-2', cmd)
assert btn.button == 'Button2'
assert btn.modifiers == [config.EzClick.modifier_keys['A']]