3
3
4
4
import ast
5
5
import importlib .util
6
+ import os
6
7
from docker .errors import APIError , ContainerError , ImageLoadError
7
8
from pathlib import Path
8
9
from requests .exceptions import ConnectionError as RequestsConnectionError
@@ -181,14 +182,14 @@ def test_initialize_resource(resource_project):
181
182
"README.md" ,
182
183
"foo-bar-baz.json" ,
183
184
"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' ) } " ,
187
188
"example_inputs" ,
188
189
"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' ) } " ,
192
193
"template.yml" ,
193
194
}
194
195
@@ -204,8 +205,8 @@ def test_initialize_resource(resource_project):
204
205
assert resource_project .entrypoint in files ["template.yml" ].read_text ()
205
206
206
207
# 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 ())
209
210
210
211
211
212
def test_initialize_hook (hook_project ):
@@ -219,9 +220,9 @@ def test_initialize_hook(hook_project):
219
220
"foo-bar-baz.json" ,
220
221
"requirements.txt" ,
221
222
"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' ) } " ,
225
226
"template.yml" ,
226
227
}
227
228
@@ -237,8 +238,8 @@ def test_initialize_hook(hook_project):
237
238
assert hook_project .entrypoint in files ["template.yml" ].read_text ()
238
239
239
240
# 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 ())
242
243
243
244
244
245
def test_generate_resource (resource_project ):
@@ -248,9 +249,9 @@ def test_generate_resource(resource_project):
248
249
after = get_files_in_project (resource_project )
249
250
files = after .keys () - before .keys () - {"resource-role.yaml" }
250
251
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' ) } " }
252
253
253
- models_path = after [" src/ foo_bar_baz/ models.py" ]
254
+ models_path = after [f" { os . path . join ( ' src' , ' foo_bar_baz' , ' models.py' ) } " ]
254
255
# this is a rough check the generated Python code is valid as far as syntax
255
256
ast .parse (models_path .read_text ())
256
257
@@ -280,11 +281,11 @@ def test_generate_hook(hook_project):
280
281
files = after .keys () - before .keys () - {"hook-role.yaml" }
281
282
print ("Project files: " , get_files_in_project (hook_project ))
282
283
assert files == {
283
- " src/ foo_bar_baz/ models.py" ,
284
+ f" { os . path . join ( ' src' , ' foo_bar_baz' , ' models.py' ) } " ,
284
285
"foo-bar-baz-configuration.json" ,
285
286
}
286
287
287
- models_path = after [" src/ foo_bar_baz/ models.py" ]
288
+ models_path = after [f" { os . path . join ( ' src' , ' foo_bar_baz' , ' models.py' ) } " ]
288
289
# this is a rough check the generated Python code is valid as far as syntax
289
290
ast .parse (models_path .read_text ())
290
291
@@ -318,7 +319,10 @@ def test_generate_resource_with_type_configuration(tmp_path):
318
319
project .init (type_name , PythonLanguagePlugin .NAME )
319
320
320
321
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
+ ),
322
326
str (project .root / "schema-with-typeconfiguration.json" ),
323
327
)
324
328
project .type_info = ("schema" , "with" , "typeconfiguration" )
@@ -381,7 +385,8 @@ def test__pip_build_executable_not_found(tmp_path):
381
385
382
386
mock_cmd .assert_called_once_with (tmp_path )
383
387
384
- assert isinstance (excinfo .value .__cause__ , FileNotFoundError )
388
+ # FileNotFoundError raised on Windows, CalledProcessError on POSIX systems
389
+ assert isinstance (excinfo .value .__cause__ , (FileNotFoundError , CalledProcessError ))
385
390
386
391
387
392
def test__pip_build_called_process_error (tmp_path ):
@@ -395,7 +400,8 @@ def test__pip_build_called_process_error(tmp_path):
395
400
396
401
mock_cmd .assert_called_once_with (tmp_path )
397
402
398
- assert isinstance (excinfo .value .__cause__ , CalledProcessError )
403
+ # FileNotFoundError raised on Windows, CalledProcessError on POSIX systems
404
+ assert isinstance (excinfo .value .__cause__ , (FileNotFoundError , CalledProcessError ))
399
405
400
406
401
407
def test__build_pip (plugin ):
0 commit comments