1414TMUXP_DIR = pathlib .Path (__file__ ).parent / ".tmuxp"
1515
1616
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+
1729def load_yaml (path : Union [str , pathlib .Path ]) -> str :
1830 return (
1931 kaptan .Kaptan (handler = "yaml" )
@@ -30,38 +42,34 @@ def load_config(path: Union[str, pathlib.Path]) -> str:
3042 )
3143
3244
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 ):
3646 json_config_file = tmp_path / "config.json"
3747
3848 configparser = kaptan .Kaptan ()
39- configparser .import_config (fixtures .sampleconfig .sampleconfigdict )
49+ configparser .import_config (config_fixture .sampleconfig .sampleconfigdict )
4050
4151 json_config_data = configparser .export ("json" , indent = 2 )
4252
4353 json_config_file .write_text (json_config_data , encoding = "utf-8" )
4454
4555 new_config = kaptan .Kaptan ()
4656 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
4958
50- def test_export_yaml (tmp_path : pathlib .Path ):
51- from .fixtures import config as fixtures
5259
60+ def test_export_yaml (tmp_path : pathlib .Path , config_fixture ):
5361 yaml_config_file = tmp_path / "config.yaml"
5462
5563 configparser = kaptan .Kaptan ()
56- sampleconfig = config .inline (fixtures .sampleconfig .sampleconfigdict )
64+ sampleconfig = config .inline (config_fixture .sampleconfig .sampleconfigdict )
5765 configparser .import_config (sampleconfig )
5866
5967 yaml_config_data = configparser .export ("yaml" , indent = 2 , default_flow_style = False )
6068
6169 yaml_config_file .write_text (yaml_config_data , encoding = "utf-8" )
6270
6371 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
6573
6674
6775def test_scan_config (tmp_path : pathlib .Path ):
@@ -93,20 +101,16 @@ def test_scan_config(tmp_path: pathlib.Path):
93101 assert len (configs ) == files
94102
95103
96- def test_config_expand1 ():
104+ def test_config_expand1 (config_fixture ):
97105 """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
99108
100- test_config = config .expand (fixtures .expand1 .before_config )
101- assert test_config == fixtures .expand1 .after_config
102109
103-
104- def test_config_expand2 ():
110+ def test_config_expand2 (config_fixture ):
105111 """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 )
110114 assert config .expand (unexpanded_dict ) == expanded_dict
111115
112116
@@ -222,37 +226,31 @@ def test_inheritance_config():
222226 assert config == inheritance_config_after
223227
224228
225- def test_shell_command_before ():
229+ def test_shell_command_before (config_fixture ):
226230 """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
230232 test_config = config .expand (test_config )
231233
232- assert test_config == fixtures .shell_command_before .config_expanded
234+ assert test_config == config_fixture .shell_command_before .config_expanded
233235
234236 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
236238
237239
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 )
242242
243243 config .validate_schema (sconfig )
244244
245245 assert config .expand (sconfig ) == sconfig
246246 assert config .expand (config .trickle (sconfig )) == load_yaml (
247- fixtures .shell_command_before_session .expected
247+ config_fixture .shell_command_before_session .expected
248248 )
249249
250250
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
256254
257255
258256def test_trickle_window_with_no_pane_config ():
@@ -273,7 +271,7 @@ def test_trickle_window_with_no_pane_config():
273271 }
274272
275273
276- def test_expands_blank_panes ():
274+ def test_expands_blank_panes (config_fixture ):
277275 """Expand blank config into full form.
278276
279277 Handle ``NoneType`` and 'blank'::
@@ -300,11 +298,9 @@ def test_expands_blank_panes():
300298 'shell_command': ['']
301299
302300 """
303- from .fixtures import config as fixtures
304-
305301 yaml_config_file = EXAMPLE_PATH / "blank-panes.yaml"
306302 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
308304
309305
310306def test_no_session_name ():
0 commit comments