Skip to content

Commit b897037

Browse files
committed
tests: Defer test fixtures interpolation
Interpolation needs to be deferred for libtmux to do its magic
1 parent b7b452a commit b897037

File tree

4 files changed

+176
-162
lines changed

4 files changed

+176
-162
lines changed

tests/fixtures/config/expand1.py

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -29,49 +29,51 @@
2929
],
3030
}
3131

32-
after_config = {
33-
"session_name": "sampleconfig",
34-
"start_directory": os.path.expanduser("~"),
35-
"windows": [
36-
{
37-
"window_name": "editor",
38-
"panes": [
39-
{"shell_command": [{"cmd": "vim"}, {"cmd": "top"}]},
40-
{"shell_command": [{"cmd": "vim"}]},
41-
{"shell_command": [{"cmd": 'cowsay "hey"'}]},
42-
],
43-
"layout": "main-verticle",
44-
},
45-
{
46-
"window_name": "logging",
47-
"panes": [{"shell_command": [{"cmd": "tail -F /var/log/syslog"}]}],
48-
},
49-
{
50-
"start_directory": "/var/log",
51-
"options": {"automatic-rename": True},
52-
"panes": [
53-
{"shell_command": [{"cmd": "htop"}]},
54-
{"shell_command": [{"cmd": "vim"}]},
55-
],
56-
},
57-
{
58-
"start_directory": os.path.normpath(
59-
os.path.join(os.path.expanduser("~"), "./")
60-
),
61-
"panes": [{"shell_command": [{"cmd": "pwd"}]}],
62-
},
63-
{
64-
"start_directory": os.path.normpath(
65-
os.path.join(os.path.expanduser("~"), "./asdf")
66-
),
67-
"panes": [{"shell_command": [{"cmd": "pwd"}]}],
68-
},
69-
{
70-
"start_directory": os.path.normpath(
71-
os.path.join(os.path.expanduser("~"), "../")
72-
),
73-
"panes": [{"shell_command": [{"cmd": "pwd"}]}],
74-
},
75-
{"panes": [{"shell_command": [{"cmd": "top"}]}]},
76-
],
77-
}
32+
33+
def after_config():
34+
return {
35+
"session_name": "sampleconfig",
36+
"start_directory": os.path.expanduser("~"),
37+
"windows": [
38+
{
39+
"window_name": "editor",
40+
"panes": [
41+
{"shell_command": [{"cmd": "vim"}, {"cmd": "top"}]},
42+
{"shell_command": [{"cmd": "vim"}]},
43+
{"shell_command": [{"cmd": 'cowsay "hey"'}]},
44+
],
45+
"layout": "main-verticle",
46+
},
47+
{
48+
"window_name": "logging",
49+
"panes": [{"shell_command": [{"cmd": "tail -F /var/log/syslog"}]}],
50+
},
51+
{
52+
"start_directory": "/var/log",
53+
"options": {"automatic-rename": True},
54+
"panes": [
55+
{"shell_command": [{"cmd": "htop"}]},
56+
{"shell_command": [{"cmd": "vim"}]},
57+
],
58+
},
59+
{
60+
"start_directory": os.path.normpath(
61+
os.path.join(os.path.expanduser("~"), "./")
62+
),
63+
"panes": [{"shell_command": [{"cmd": "pwd"}]}],
64+
},
65+
{
66+
"start_directory": os.path.normpath(
67+
os.path.join(os.path.expanduser("~"), "./asdf")
68+
),
69+
"panes": [{"shell_command": [{"cmd": "pwd"}]}],
70+
},
71+
{
72+
"start_directory": os.path.normpath(
73+
os.path.join(os.path.expanduser("~"), "../")
74+
),
75+
"panes": [{"shell_command": [{"cmd": "pwd"}]}],
76+
},
77+
{"panes": [{"shell_command": [{"cmd": "top"}]}]},
78+
],
79+
}

tests/fixtures/config/expand2.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
from .. import utils as test_utils
44

5-
unexpanded_yaml = test_utils.read_config_file("config/expand2-unexpanded.yaml")
6-
expanded_yaml = test_utils.read_config_file("config/expand2-expanded.yaml").format(
7-
HOME=os.path.expanduser("~")
8-
)
5+
6+
def unexpanded_yaml():
7+
return test_utils.read_config_file("config/expand2-unexpanded.yaml")
8+
9+
10+
def expanded_yaml():
11+
return test_utils.read_config_file("config/expand2-expanded.yaml").format(
12+
HOME=os.path.expanduser("~")
13+
)

tests/fixtures/config/shell_command_before.py

Lines changed: 114 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -36,119 +36,126 @@
3636
],
3737
}
3838

39-
config_expanded = { # shell_command_before is string in some areas
40-
"session_name": "sampleconfig",
41-
"start_directory": "/",
42-
"windows": [
43-
{
44-
"window_name": "editor",
45-
"start_directory": os.path.expanduser("~"),
46-
"shell_command_before": {
47-
"shell_command": [{"cmd": "source .venv/bin/activate"}]
48-
},
49-
"panes": [
50-
{"shell_command": [{"cmd": "vim"}]},
51-
{
52-
"shell_command_before": {
53-
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]
39+
40+
def config_expanded():
41+
return { # shell_command_before is string in some areas
42+
"session_name": "sampleconfig",
43+
"start_directory": "/",
44+
"windows": [
45+
{
46+
"window_name": "editor",
47+
"start_directory": os.path.expanduser("~"),
48+
"shell_command_before": {
49+
"shell_command": [{"cmd": "source .venv/bin/activate"}]
50+
},
51+
"panes": [
52+
{"shell_command": [{"cmd": "vim"}]},
53+
{
54+
"shell_command_before": {
55+
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]
56+
},
57+
"shell_command": [{"cmd": 'cowsay "hey"'}],
5458
},
55-
"shell_command": [{"cmd": 'cowsay "hey"'}],
59+
],
60+
"layout": "main-verticle",
61+
},
62+
{
63+
"shell_command_before": {
64+
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]
5665
},
57-
],
58-
"layout": "main-verticle",
59-
},
60-
{
61-
"shell_command_before": {
62-
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]
66+
"window_name": "logging",
67+
"panes": [
68+
{"shell_command": [{"cmd": "tail -F /var/log/syslog"}]},
69+
{"shell_command": []},
70+
],
6371
},
64-
"window_name": "logging",
65-
"panes": [
66-
{"shell_command": [{"cmd": "tail -F /var/log/syslog"}]},
67-
{"shell_command": []},
68-
],
69-
},
70-
{
71-
"window_name": "shufu",
72-
"panes": [
73-
{
74-
"shell_command_before": {
75-
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]
76-
},
77-
"shell_command": [{"cmd": "htop"}],
78-
}
79-
],
80-
},
81-
{
82-
"options": {"automatic-rename": True},
83-
"panes": [{"shell_command": [{"cmd": "htop"}]}],
84-
},
85-
{"panes": [{"shell_command": [{"cmd": "top"}]}]},
86-
],
87-
}
88-
89-
config_after = { # shell_command_before is string in some areas
90-
"session_name": "sampleconfig",
91-
"start_directory": "/",
92-
"windows": [
93-
{
94-
"window_name": "editor",
95-
"start_directory": os.path.expanduser("~"),
96-
"shell_command_before": {
97-
"shell_command": [{"cmd": "source .venv/bin/activate"}]
72+
{
73+
"window_name": "shufu",
74+
"panes": [
75+
{
76+
"shell_command_before": {
77+
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]
78+
},
79+
"shell_command": [{"cmd": "htop"}],
80+
}
81+
],
9882
},
99-
"panes": [
100-
{
101-
"shell_command": [
102-
{"cmd": "source .venv/bin/activate"},
103-
{"cmd": "vim"},
104-
]
83+
{
84+
"options": {"automatic-rename": True},
85+
"panes": [{"shell_command": [{"cmd": "htop"}]}],
86+
},
87+
{"panes": [{"shell_command": [{"cmd": "top"}]}]},
88+
],
89+
}
90+
91+
92+
def config_after():
93+
return { # shell_command_before is string in some areas
94+
"session_name": "sampleconfig",
95+
"start_directory": "/",
96+
"windows": [
97+
{
98+
"window_name": "editor",
99+
"start_directory": os.path.expanduser("~"),
100+
"shell_command_before": {
101+
"shell_command": [{"cmd": "source .venv/bin/activate"}]
105102
},
106-
{
107-
"shell_command_before": {
108-
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]
103+
"panes": [
104+
{
105+
"shell_command": [
106+
{"cmd": "source .venv/bin/activate"},
107+
{"cmd": "vim"},
108+
]
109109
},
110-
"shell_command": [
111-
{"cmd": "source .venv/bin/activate"},
112-
{"cmd": "rbenv local 2.0.0-p0"},
113-
{"cmd": 'cowsay "hey"'},
114-
],
115-
},
116-
],
117-
"layout": "main-verticle",
118-
},
119-
{
120-
"shell_command_before": {
121-
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]
110+
{
111+
"shell_command_before": {
112+
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]
113+
},
114+
"shell_command": [
115+
{"cmd": "source .venv/bin/activate"},
116+
{"cmd": "rbenv local 2.0.0-p0"},
117+
{"cmd": 'cowsay "hey"'},
118+
],
119+
},
120+
],
121+
"layout": "main-verticle",
122122
},
123-
"start_directory": "/",
124-
"window_name": "logging",
125-
"panes": [
126-
{
127-
"shell_command": [
128-
{"cmd": "rbenv local 2.0.0-p0"},
129-
{"cmd": "tail -F /var/log/syslog"},
130-
]
123+
{
124+
"shell_command_before": {
125+
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]
131126
},
132-
{"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]},
133-
],
134-
},
135-
{
136-
"start_directory": "/",
137-
"window_name": "shufu",
138-
"panes": [
139-
{
140-
"shell_command_before": {
141-
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]
127+
"start_directory": "/",
128+
"window_name": "logging",
129+
"panes": [
130+
{
131+
"shell_command": [
132+
{"cmd": "rbenv local 2.0.0-p0"},
133+
{"cmd": "tail -F /var/log/syslog"},
134+
]
142135
},
143-
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}, {"cmd": "htop"}],
144-
}
145-
],
146-
},
147-
{
148-
"start_directory": "/",
149-
"options": {"automatic-rename": True},
150-
"panes": [{"shell_command": [{"cmd": "htop"}]}],
151-
},
152-
{"start_directory": "/", "panes": [{"shell_command": [{"cmd": "top"}]}]},
153-
],
154-
}
136+
{"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]},
137+
],
138+
},
139+
{
140+
"start_directory": "/",
141+
"window_name": "shufu",
142+
"panes": [
143+
{
144+
"shell_command_before": {
145+
"shell_command": [{"cmd": "rbenv local 2.0.0-p0"}]
146+
},
147+
"shell_command": [
148+
{"cmd": "rbenv local 2.0.0-p0"},
149+
{"cmd": "htop"},
150+
],
151+
}
152+
],
153+
},
154+
{
155+
"start_directory": "/",
156+
"options": {"automatic-rename": True},
157+
"panes": [{"shell_command": [{"cmd": "htop"}]}],
158+
},
159+
{"start_directory": "/", "panes": [{"shell_command": [{"cmd": "top"}]}]},
160+
],
161+
}

tests/test_config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ def test_scan_config(tmp_path: pathlib.Path):
106106
def test_config_expand1(config_fixture: "ConfigFixture"):
107107
"""Expand shell commands from string to list."""
108108
test_config = config.expand(config_fixture.expand1.before_config)
109-
assert test_config == config_fixture.expand1.after_config
109+
assert test_config == config_fixture.expand1.after_config()
110110

111111

112112
def test_config_expand2(config_fixture: "ConfigFixture"):
113113
"""Expand shell commands from string to list."""
114-
unexpanded_dict = load_yaml(config_fixture.expand2.unexpanded_yaml)
115-
expanded_dict = load_yaml(config_fixture.expand2.expanded_yaml)
114+
unexpanded_dict = load_yaml(config_fixture.expand2.unexpanded_yaml())
115+
expanded_dict = load_yaml(config_fixture.expand2.expanded_yaml())
116116
assert config.expand(unexpanded_dict) == expanded_dict
117117

118118

@@ -233,10 +233,10 @@ def test_shell_command_before(config_fixture: "ConfigFixture"):
233233
test_config = config_fixture.shell_command_before.config_unexpanded
234234
test_config = config.expand(test_config)
235235

236-
assert test_config == config_fixture.shell_command_before.config_expanded
236+
assert test_config == config_fixture.shell_command_before.config_expanded()
237237

238238
test_config = config.trickle(test_config)
239-
assert test_config == config_fixture.shell_command_before.config_after
239+
assert test_config == config_fixture.shell_command_before.config_after()
240240

241241

242242
def test_in_session_scope(config_fixture: "ConfigFixture"):

0 commit comments

Comments
 (0)