-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconftest.py
105 lines (80 loc) · 2.29 KB
/
conftest.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
import os
import sys
from collections import namedtuple
import i3ipc
import pytest
from raiseorlaunch import Raiseorlaunch, raiseorlaunch
from tests.tree import tree
@pytest.fixture()
def default_args():
return {
"wm_class": None,
"wm_instance": None,
"wm_title": None,
"command": None,
"workspace": None,
"target_workspace": None,
"scratch": False,
"con_mark": None,
"event_time_limit": 2.0,
"ignore_case": False,
"cycle": False,
"leave_fullscreen": False,
}
@pytest.fixture()
def default_args_cli(default_args):
default_args["debug"] = False
return default_args
@pytest.fixture()
def minimal_args(default_args):
default_args["wm_class"] = "some_class"
return default_args
@pytest.fixture
def Workspace():
return namedtuple("Workspace", ("name"))
@pytest.fixture()
def Con(Workspace):
class CreateCon:
def __init__(
self,
window_class="some_class",
window_instance="some_instance",
name="some_name",
id="some_id",
workspace_name="some_workspace",
focused=False,
):
self.window_class = window_class
self.window_instance = window_instance
self.name = name
self.id = id
self.workspace_name = workspace_name
self.focused = focused
self.calls = []
def workspace(self):
return Workspace(name=self.workspace_name)
def command(self, *args, **kwargs):
self.calls += [args, kwargs]
return CreateCon
@pytest.fixture()
def sys_argv_handler():
old_sys_argv = sys.argv
yield
sys.argv = old_sys_argv
@pytest.fixture
def tree_mock():
return i3ipc.Con(tree, None, None)
@pytest.fixture
def run_command_mock(mocker):
return mocker.patch.object(raiseorlaunch.i3ipc.Connection, "command")
@pytest.fixture
def i3ipc_mock(mocker, tree_mock):
os.environ["I3SOCK"] = "/dev/null"
mocker.patch.object(
raiseorlaunch.i3ipc.Connection, "get_tree", return_value=tree_mock
)
mocker.patch.object(i3ipc.connection.socket.socket, "connect")
@pytest.fixture
def rol(minimal_args, i3ipc_mock):
rol = Raiseorlaunch(**minimal_args)
return rol