@@ -31,10 +31,12 @@ def test_write_json_map_no_synoptic(json_map_generator):
3131 json_map_generator .write_json_map ()
3232
3333
34- def test_app ():
35- result = runner .invoke (app , ["tests/t01-services/synoptic/techui.yaml" ])
36- if Path .exists (Path ("tests/t01-services/synoptic/JsonMap.json" )):
37- os .remove ("tests/t01-services/synoptic/JsonMap.json" )
34+ def test_app (tmp_path ):
35+ result = runner .invoke (
36+ app , ["tests/t01-services/synoptic/index.bob" , "--output" , tmp_path ]
37+ )
38+ if Path .exists (Path (tmp_path / "JsonMap.json" )):
39+ os .remove (tmp_path / "JsonMap.json" )
3840 assert result .exit_code == 0
3941
4042
@@ -48,18 +50,14 @@ def test_json_map_generator_techui_exception(
4850 assert "No such file or directory" in str (excinfo .value )
4951
5052
51- def test_write_json_map (json_map_generator ):
53+ def test_write_json_map (json_map_generator , tmp_path ):
5254 test_map = JsonMap (
5355 str (Path (__file__ ).parent .joinpath ("test_files/test_bob.bob" )), None
5456 )
5557
5658 # We don't want cover _generate_json_map in this test
5759 json_map_generator .generate_json_map = Mock (return_value = test_map )
5860
59- # Make sure opis/ dir exists
60- if not Path .exists (json_map_generator ._write_directory ):
61- os .mkdir (json_map_generator ._write_directory )
62-
6361 # We don't want to access the _serialise_json_map function in this test
6462 with patch (
6563 "techui_builder.generate_jsonmap._serialise_json_map"
@@ -71,20 +69,16 @@ def test_write_json_map(json_map_generator):
7169 dest_path = json_map_generator ._write_directory .joinpath ("JsonMap.json" )
7270 assert Path .exists (dest_path )
7371
74- if Path .exists (dest_path ):
75- os .remove (dest_path )
76-
7772
7873# We don't want to access the _get_action_group function in this test
7974@patch ("techui_builder.generate_jsonmap._get_action_group" )
8075def test_generate_json_map (
8176 mock_get_action_group : MagicMock ,
8277 json_map_generator_with_test_files ,
8378 example_json_map ,
79+ tmp_path ,
8480):
85- json_map_generator_with_test_files .bob_path = Path (
86- "tests/test_files/test_bob.bob"
87- ).absolute ()
81+ json_map_generator_with_test_files .bob_path = tmp_path / "test_files/test_bob.bob"
8882
8983 mock_xml = objectify .Element ("action" )
9084 mock_xml ["file" ] = "test_child_bob.bob"
@@ -105,7 +99,7 @@ def test_generate_json_map(
10599
106100
107101def test_generate_json_map_embedded_screen (
108- json_map_generator_with_test_files , example_json_map
102+ json_map_generator_with_test_files , example_json_map , tmp_path
109103):
110104 list_names = [
111105 "Display" ,
@@ -121,17 +115,17 @@ def test_generate_json_map_embedded_screen(
121115 side_effect = list_names
122116 )
123117
124- json_map_generator_with_test_files .bob_path = Path (
125- "tests/ test_files/test_bob_embedded.bob"
126- ). absolute ()
118+ json_map_generator_with_test_files .bob_path = (
119+ tmp_path / " test_files/test_bob_embedded.bob"
120+ )
127121
128122 example_json_map .file = "test_bob_embedded.bob"
129123 example_json_map .children .append (
130124 JsonMap (
131125 "$(IOC)/pmacAxis.pvi.bob" ,
132126 display_name = "Embedded Display" ,
133127 exists = False ,
134- macros = {"M" : "$(M) " , "P" : "$(P) " },
128+ macros = {"M" : ":EMBED " , "P" : "BL01T-MO-MOTOR-01" , "label" : "EMBED " },
135129 )
136130 )
137131
@@ -143,7 +137,7 @@ def test_generate_json_map_embedded_screen(
143137
144138
145139def test_generate_json_map_nav_tabs (
146- json_map_generator_with_test_files , example_json_map_root
140+ json_map_generator_with_test_files , example_json_map_root , tmp_path
147141):
148142 json_map_generator_with_test_files ._parse_display_name = Mock (
149143 side_effect = ["Display" , "Tab1" , "Tab2" ]
@@ -152,9 +146,9 @@ def test_generate_json_map_nav_tabs(
152146 side_effect = ["Display" , "Tab1" , "Tab2" ]
153147 )
154148
155- json_map_generator_with_test_files .bob_path = Path (
156- "tests/ test_files/test_bob_navtabs.bob"
157- ). absolute ()
149+ json_map_generator_with_test_files .bob_path = (
150+ tmp_path / " test_files/test_bob_navtabs.bob"
151+ )
158152
159153 example_json_map_root .file = "test_bob_navtabs.bob"
160154 example_json_map_root .children .extend (
@@ -265,11 +259,11 @@ def test_generate_json_map_get_macros(
265259
266260
267261def test_generate_json_map_xml_parse_error (
268- json_map_generator_with_test_files ,
262+ json_map_generator_with_test_files , tmp_path
269263):
270- json_map_generator_with_test_files .bob_path = Path (
271- "tests/ test_files/test_bob_bad.bob"
272- ). absolute ()
264+ json_map_generator_with_test_files .bob_path = (
265+ tmp_path / " test_files/test_bob_bad.bob"
266+ )
273267
274268 test_json_map = json_map_generator_with_test_files .generate_json_map (
275269 json_map_generator_with_test_files .bob_path ,
0 commit comments