33
44import ast
55import importlib .util
6+ import os
67from docker .errors import APIError , ContainerError , ImageLoadError
78from pathlib import Path
89from requests .exceptions import ConnectionError as RequestsConnectionError
@@ -181,14 +182,14 @@ def test_initialize_resource(resource_project):
181182 "README.md" ,
182183 "foo-bar-baz.json" ,
183184 "requirements.txt" ,
184- " example_inputs/inputs_1_invalid .json" ,
185- " example_inputs/inputs_1_update .json" ,
186- " example_inputs/inputs_1_create .json" ,
185+ f" { os . path . join ( ' example_inputs' , 'inputs_1_create .json' ) } " ,
186+ f" { os . path . join ( ' example_inputs' , 'inputs_1_invalid .json' ) } " ,
187+ f" { os . path . join ( ' example_inputs' , 'inputs_1_update .json' ) } " ,
187188 "example_inputs" ,
188189 "src" ,
189- " src/ foo_bar_baz" ,
190- " src/ foo_bar_baz/ __init__.py" ,
191- " src/ foo_bar_baz/ handlers.py" ,
190+ f" { os . path . join ( ' src' , ' foo_bar_baz' ) } " ,
191+ f" { os . path . join ( ' src' , ' foo_bar_baz' , ' __init__.py' ) } " ,
192+ f" { os . path . join ( ' src' , ' foo_bar_baz' , ' handlers.py' ) } " ,
192193 "template.yml" ,
193194 }
194195
@@ -204,8 +205,8 @@ def test_initialize_resource(resource_project):
204205 assert resource_project .entrypoint in files ["template.yml" ].read_text ()
205206
206207 # this is a rough check the generated Python code is valid as far as syntax
207- ast .parse (files [" src/ foo_bar_baz/ __init__.py" ].read_text ())
208- ast .parse (files [" src/ foo_bar_baz/ handlers.py" ].read_text ())
208+ ast .parse (files [f" { os . path . join ( ' src' , ' foo_bar_baz' , ' __init__.py' ) } " ].read_text ())
209+ ast .parse (files [f" { os . path . join ( ' src' , ' foo_bar_baz' , ' handlers.py' ) } " ].read_text ())
209210
210211
211212def test_initialize_hook (hook_project ):
@@ -219,9 +220,9 @@ def test_initialize_hook(hook_project):
219220 "foo-bar-baz.json" ,
220221 "requirements.txt" ,
221222 "src" ,
222- " src/ foo_bar_baz" ,
223- " src/ foo_bar_baz/ __init__.py" ,
224- " src/ foo_bar_baz/ handlers.py" ,
223+ f" { os . path . join ( ' src' , ' foo_bar_baz' ) } " ,
224+ f" { os . path . join ( ' src' , ' foo_bar_baz' , ' __init__.py' ) } " ,
225+ f" { os . path . join ( ' src' , ' foo_bar_baz' , ' handlers.py' ) } " ,
225226 "template.yml" ,
226227 }
227228
@@ -237,8 +238,8 @@ def test_initialize_hook(hook_project):
237238 assert hook_project .entrypoint in files ["template.yml" ].read_text ()
238239
239240 # this is a rough check the generated Python code is valid as far as syntax
240- ast .parse (files [" src/ foo_bar_baz/ __init__.py" ].read_text ())
241- ast .parse (files [" src/ foo_bar_baz/ handlers.py" ].read_text ())
241+ ast .parse (files [f" { os . path . join ( ' src' , ' foo_bar_baz' , ' __init__.py' ) } " ].read_text ())
242+ ast .parse (files [f" { os . path . join ( ' src' , ' foo_bar_baz' , ' handlers.py' ) } " ].read_text ())
242243
243244
244245def test_generate_resource (resource_project ):
@@ -248,9 +249,9 @@ def test_generate_resource(resource_project):
248249 after = get_files_in_project (resource_project )
249250 files = after .keys () - before .keys () - {"resource-role.yaml" }
250251 print ("Project files: " , get_files_in_project (resource_project ))
251- assert files == {" src/ foo_bar_baz/ models.py" }
252+ assert files == {f" { os . path . join ( ' src' , ' foo_bar_baz' , ' models.py' ) } " }
252253
253- models_path = after [" src/ foo_bar_baz/ models.py" ]
254+ models_path = after [f" { os . path . join ( ' src' , ' foo_bar_baz' , ' models.py' ) } " ]
254255 # this is a rough check the generated Python code is valid as far as syntax
255256 ast .parse (models_path .read_text ())
256257
@@ -280,11 +281,11 @@ def test_generate_hook(hook_project):
280281 files = after .keys () - before .keys () - {"hook-role.yaml" }
281282 print ("Project files: " , get_files_in_project (hook_project ))
282283 assert files == {
283- " src/ foo_bar_baz/ models.py" ,
284+ f" { os . path . join ( ' src' , ' foo_bar_baz' , ' models.py' ) } " ,
284285 "foo-bar-baz-configuration.json" ,
285286 }
286287
287- models_path = after [" src/ foo_bar_baz/ models.py" ]
288+ models_path = after [f" { os . path . join ( ' src' , ' foo_bar_baz' , ' models.py' ) } " ]
288289 # this is a rough check the generated Python code is valid as far as syntax
289290 ast .parse (models_path .read_text ())
290291
@@ -318,7 +319,10 @@ def test_generate_resource_with_type_configuration(tmp_path):
318319 project .init (type_name , PythonLanguagePlugin .NAME )
319320
320321 copyfile (
321- str (Path .cwd () / "tests/data/schema-with-typeconfiguration.json" ),
322+ str (
323+ Path .cwd ()
324+ / f"{ os .path .join ('tests' , 'data' , 'schema-with-typeconfiguration.json' )} "
325+ ),
322326 str (project .root / "schema-with-typeconfiguration.json" ),
323327 )
324328 project .type_info = ("schema" , "with" , "typeconfiguration" )
@@ -381,7 +385,8 @@ def test__pip_build_executable_not_found(tmp_path):
381385
382386 mock_cmd .assert_called_once_with (tmp_path )
383387
384- assert isinstance (excinfo .value .__cause__ , FileNotFoundError )
388+ # FileNotFoundError raised on Windows, CalledProcessError on POSIX systems
389+ assert isinstance (excinfo .value .__cause__ , (FileNotFoundError , CalledProcessError ))
385390
386391
387392def test__pip_build_called_process_error (tmp_path ):
@@ -395,7 +400,8 @@ def test__pip_build_called_process_error(tmp_path):
395400
396401 mock_cmd .assert_called_once_with (tmp_path )
397402
398- assert isinstance (excinfo .value .__cause__ , CalledProcessError )
403+ # FileNotFoundError raised on Windows, CalledProcessError on POSIX systems
404+ assert isinstance (excinfo .value .__cause__ , (FileNotFoundError , CalledProcessError ))
399405
400406
401407def test__build_pip (plugin ):
0 commit comments