14
14
TMUXP_DIR = pathlib .Path (__file__ ).parent / ".tmuxp"
15
15
16
16
17
+ @pytest .fixture
18
+ def config_fixture ():
19
+ """Deferred import of tmuxp.tests.fixtures.*
20
+
21
+ pytest setup (conftest.py) patches os.environ["HOME"], delay execution of
22
+ os.path.expanduser until here.
23
+ """
24
+ from .fixtures import config as config_fixture
25
+
26
+ return config_fixture
27
+
28
+
17
29
def load_yaml (path : Union [str , pathlib .Path ]) -> str :
18
30
return (
19
31
kaptan .Kaptan (handler = "yaml" )
@@ -30,38 +42,34 @@ def load_config(path: Union[str, pathlib.Path]) -> str:
30
42
)
31
43
32
44
33
- def test_export_json (tmp_path : pathlib .Path ):
34
- from .fixtures import config as fixtures
35
-
45
+ def test_export_json (tmp_path : pathlib .Path , config_fixture ):
36
46
json_config_file = tmp_path / "config.json"
37
47
38
48
configparser = kaptan .Kaptan ()
39
- configparser .import_config (fixtures .sampleconfig .sampleconfigdict )
49
+ configparser .import_config (config_fixture .sampleconfig .sampleconfigdict )
40
50
41
51
json_config_data = configparser .export ("json" , indent = 2 )
42
52
43
53
json_config_file .write_text (json_config_data , encoding = "utf-8" )
44
54
45
55
new_config = kaptan .Kaptan ()
46
56
new_config_data = new_config .import_config (str (json_config_file )).get ()
47
- assert fixtures .sampleconfig .sampleconfigdict == new_config_data
48
-
57
+ assert config_fixture .sampleconfig .sampleconfigdict == new_config_data
49
58
50
- def test_export_yaml (tmp_path : pathlib .Path ):
51
- from .fixtures import config as fixtures
52
59
60
+ def test_export_yaml (tmp_path : pathlib .Path , config_fixture ):
53
61
yaml_config_file = tmp_path / "config.yaml"
54
62
55
63
configparser = kaptan .Kaptan ()
56
- sampleconfig = config .inline (fixtures .sampleconfig .sampleconfigdict )
64
+ sampleconfig = config .inline (config_fixture .sampleconfig .sampleconfigdict )
57
65
configparser .import_config (sampleconfig )
58
66
59
67
yaml_config_data = configparser .export ("yaml" , indent = 2 , default_flow_style = False )
60
68
61
69
yaml_config_file .write_text (yaml_config_data , encoding = "utf-8" )
62
70
63
71
new_config_data = load_config (str (yaml_config_file ))
64
- assert fixtures .sampleconfig .sampleconfigdict == new_config_data
72
+ assert config_fixture .sampleconfig .sampleconfigdict == new_config_data
65
73
66
74
67
75
def test_scan_config (tmp_path : pathlib .Path ):
@@ -93,20 +101,16 @@ def test_scan_config(tmp_path: pathlib.Path):
93
101
assert len (configs ) == files
94
102
95
103
96
- def test_config_expand1 ():
104
+ def test_config_expand1 (config_fixture ):
97
105
"""Expand shell commands from string to list."""
98
- from .fixtures import config as fixtures
106
+ test_config = config .expand (config_fixture .expand1 .before_config )
107
+ assert test_config == config_fixture .expand1 .after_config
99
108
100
- test_config = config .expand (fixtures .expand1 .before_config )
101
- assert test_config == fixtures .expand1 .after_config
102
109
103
-
104
- def test_config_expand2 ():
110
+ def test_config_expand2 (config_fixture ):
105
111
"""Expand shell commands from string to list."""
106
- from .fixtures import config as fixtures
107
-
108
- unexpanded_dict = load_yaml (fixtures .expand2 .unexpanded_yaml )
109
- expanded_dict = load_yaml (fixtures .expand2 .expanded_yaml )
112
+ unexpanded_dict = load_yaml (config_fixture .expand2 .unexpanded_yaml )
113
+ expanded_dict = load_yaml (config_fixture .expand2 .expanded_yaml )
110
114
assert config .expand (unexpanded_dict ) == expanded_dict
111
115
112
116
@@ -222,37 +226,31 @@ def test_inheritance_config():
222
226
assert config == inheritance_config_after
223
227
224
228
225
- def test_shell_command_before ():
229
+ def test_shell_command_before (config_fixture ):
226
230
"""Config inheritance for the nested 'start_command'."""
227
- from .fixtures import config as fixtures
228
-
229
- test_config = fixtures .shell_command_before .config_unexpanded
231
+ test_config = config_fixture .shell_command_before .config_unexpanded
230
232
test_config = config .expand (test_config )
231
233
232
- assert test_config == fixtures .shell_command_before .config_expanded
234
+ assert test_config == config_fixture .shell_command_before .config_expanded
233
235
234
236
test_config = config .trickle (test_config )
235
- assert test_config == fixtures .shell_command_before .config_after
237
+ assert test_config == config_fixture .shell_command_before .config_after
236
238
237
239
238
- def test_in_session_scope ():
239
- from .fixtures import config as fixtures
240
-
241
- sconfig = load_yaml (fixtures .shell_command_before_session .before )
240
+ def test_in_session_scope (config_fixture ):
241
+ sconfig = load_yaml (config_fixture .shell_command_before_session .before )
242
242
243
243
config .validate_schema (sconfig )
244
244
245
245
assert config .expand (sconfig ) == sconfig
246
246
assert config .expand (config .trickle (sconfig )) == load_yaml (
247
- fixtures .shell_command_before_session .expected
247
+ config_fixture .shell_command_before_session .expected
248
248
)
249
249
250
250
251
- def test_trickle_relative_start_directory ():
252
- from .fixtures import config as fixtures
253
-
254
- test_config = config .trickle (fixtures .trickle .before )
255
- assert test_config == fixtures .trickle .expected
251
+ def test_trickle_relative_start_directory (config_fixture ):
252
+ test_config = config .trickle (config_fixture .trickle .before )
253
+ assert test_config == config_fixture .trickle .expected
256
254
257
255
258
256
def test_trickle_window_with_no_pane_config ():
@@ -273,7 +271,7 @@ def test_trickle_window_with_no_pane_config():
273
271
}
274
272
275
273
276
- def test_expands_blank_panes ():
274
+ def test_expands_blank_panes (config_fixture ):
277
275
"""Expand blank config into full form.
278
276
279
277
Handle ``NoneType`` and 'blank'::
@@ -300,11 +298,9 @@ def test_expands_blank_panes():
300
298
'shell_command': ['']
301
299
302
300
"""
303
- from .fixtures import config as fixtures
304
-
305
301
yaml_config_file = EXAMPLE_PATH / "blank-panes.yaml"
306
302
test_config = load_config (yaml_config_file )
307
- assert config .expand (test_config ) == fixtures .expand_blank .expected
303
+ assert config .expand (test_config ) == config_fixture .expand_blank .expected
308
304
309
305
310
306
def test_no_session_name ():
0 commit comments