@@ -108,7 +108,32 @@ def resource_project(tmp_path):
108
108
"rpdk.python.codegen.input_with_validation" , autospec = True , side_effect = [False ]
109
109
)
110
110
with patch_plugins , patch_wizard :
111
- project .init (TYPE_NAME , PythonLanguagePlugin .NAME )
111
+ project .init (
112
+ TYPE_NAME ,
113
+ PythonLanguagePlugin .NAME ,
114
+ settings = {"use_docker" : False , "no_docker" : True },
115
+ )
116
+ return project
117
+
118
+
119
+ @pytest .fixture
120
+ def resource_project_use_docker (tmp_path ):
121
+ project = Project (root = tmp_path )
122
+
123
+ patch_plugins = patch .dict (
124
+ "rpdk.core.plugin_registry.PLUGIN_REGISTRY" ,
125
+ {PythonLanguagePlugin .NAME : lambda : PythonLanguagePlugin },
126
+ clear = True ,
127
+ )
128
+ patch_wizard = patch (
129
+ "rpdk.python.codegen.input_with_validation" , autospec = True , side_effect = [False ]
130
+ )
131
+ with patch_plugins , patch_wizard :
132
+ project .init (
133
+ TYPE_NAME ,
134
+ PythonLanguagePlugin .NAME ,
135
+ settings = {"use_docker" : True , "no_docker" : False },
136
+ )
112
137
return project
113
138
114
139
@@ -125,7 +150,32 @@ def hook_project(tmp_path):
125
150
"rpdk.python.codegen.input_with_validation" , autospec = True , side_effect = [False ]
126
151
)
127
152
with patch_plugins , patch_wizard :
128
- project .init_hook (TYPE_NAME , PythonLanguagePlugin .NAME )
153
+ project .init_hook (
154
+ TYPE_NAME ,
155
+ PythonLanguagePlugin .NAME ,
156
+ settings = {"use_docker" : False , "no_docker" : True },
157
+ )
158
+ return project
159
+
160
+
161
+ @pytest .fixture
162
+ def hook_project_use_docker (tmp_path ):
163
+ project = Project (root = tmp_path )
164
+
165
+ patch_plugins = patch .dict (
166
+ "rpdk.core.plugin_registry.PLUGIN_REGISTRY" ,
167
+ {PythonLanguagePlugin .NAME : lambda : PythonLanguagePlugin },
168
+ clear = True ,
169
+ )
170
+ patch_wizard = patch (
171
+ "rpdk.python.codegen.input_with_validation" , autospec = True , side_effect = [False ]
172
+ )
173
+ with patch_plugins , patch_wizard :
174
+ project .init_hook (
175
+ TYPE_NAME ,
176
+ PythonLanguagePlugin .NAME ,
177
+ settings = {"use_docker" : True , "no_docker" : False },
178
+ )
129
179
return project
130
180
131
181
@@ -172,6 +222,7 @@ def test__remove_build_artifacts_file_not_found(tmp_path):
172
222
def test_initialize_resource (resource_project ):
173
223
assert resource_project .settings == {
174
224
"use_docker" : False ,
225
+ "no_docker" : True ,
175
226
"protocolVersion" : "2.0.0" ,
176
227
}
177
228
@@ -209,8 +260,53 @@ def test_initialize_resource(resource_project):
209
260
ast .parse (files [f"{ os .path .join ('src' , 'foo_bar_baz' , 'handlers.py' )} " ].read_text ())
210
261
211
262
263
+ def test_initialize_resource_use_docker (resource_project_use_docker ):
264
+ assert resource_project_use_docker .settings == {
265
+ "use_docker" : True ,
266
+ "no_docker" : False ,
267
+ "protocolVersion" : "2.0.0" ,
268
+ }
269
+
270
+ files = get_files_in_project (resource_project_use_docker )
271
+ assert set (files ) == {
272
+ ".gitignore" ,
273
+ ".rpdk-config" ,
274
+ "README.md" ,
275
+ "foo-bar-baz.json" ,
276
+ "requirements.txt" ,
277
+ f"{ os .path .join ('example_inputs' , 'inputs_1_create.json' )} " ,
278
+ f"{ os .path .join ('example_inputs' , 'inputs_1_invalid.json' )} " ,
279
+ f"{ os .path .join ('example_inputs' , 'inputs_1_update.json' )} " ,
280
+ "example_inputs" ,
281
+ "src" ,
282
+ f"{ os .path .join ('src' , 'foo_bar_baz' )} " ,
283
+ f"{ os .path .join ('src' , 'foo_bar_baz' , '__init__.py' )} " ,
284
+ f"{ os .path .join ('src' , 'foo_bar_baz' , 'handlers.py' )} " ,
285
+ "template.yml" ,
286
+ }
287
+
288
+ assert "__pycache__" in files [".gitignore" ].read_text ()
289
+ assert SUPPORT_LIB_NAME in files ["requirements.txt" ].read_text ()
290
+
291
+ readme = files ["README.md" ].read_text ()
292
+ assert resource_project_use_docker .type_name in readme
293
+ assert SUPPORT_LIB_PKG in readme
294
+ assert "handlers.py" in readme
295
+ assert "models.py" in readme
296
+
297
+ assert resource_project_use_docker .entrypoint in files ["template.yml" ].read_text ()
298
+
299
+ # this is a rough check the generated Python code is valid as far as syntax
300
+ ast .parse (files [f"{ os .path .join ('src' , 'foo_bar_baz' , '__init__.py' )} " ].read_text ())
301
+ ast .parse (files [f"{ os .path .join ('src' , 'foo_bar_baz' , 'handlers.py' )} " ].read_text ())
302
+
303
+
212
304
def test_initialize_hook (hook_project ):
213
- assert hook_project .settings == {"use_docker" : False , "protocolVersion" : "2.0.0" }
305
+ assert hook_project .settings == {
306
+ "use_docker" : False ,
307
+ "no_docker" : True ,
308
+ "protocolVersion" : "2.0.0" ,
309
+ }
214
310
215
311
files = get_files_in_project (hook_project )
216
312
assert set (files ) == {
@@ -242,6 +338,43 @@ def test_initialize_hook(hook_project):
242
338
ast .parse (files [f"{ os .path .join ('src' , 'foo_bar_baz' , 'handlers.py' )} " ].read_text ())
243
339
244
340
341
+ def test_initialize_hook_use_docker (hook_project_use_docker ):
342
+ assert hook_project_use_docker .settings == {
343
+ "use_docker" : True ,
344
+ "no_docker" : False ,
345
+ "protocolVersion" : "2.0.0" ,
346
+ }
347
+
348
+ files = get_files_in_project (hook_project_use_docker )
349
+ assert set (files ) == {
350
+ ".gitignore" ,
351
+ ".rpdk-config" ,
352
+ "README.md" ,
353
+ "foo-bar-baz.json" ,
354
+ "requirements.txt" ,
355
+ "src" ,
356
+ f"{ os .path .join ('src' , 'foo_bar_baz' )} " ,
357
+ f"{ os .path .join ('src' , 'foo_bar_baz' , '__init__.py' )} " ,
358
+ f"{ os .path .join ('src' , 'foo_bar_baz' , 'handlers.py' )} " ,
359
+ "template.yml" ,
360
+ }
361
+
362
+ assert "__pycache__" in files [".gitignore" ].read_text ()
363
+ assert SUPPORT_LIB_NAME in files ["requirements.txt" ].read_text ()
364
+
365
+ readme = files ["README.md" ].read_text ()
366
+ assert hook_project_use_docker .type_name in readme
367
+ assert SUPPORT_LIB_PKG in readme
368
+ assert "handlers.py" in readme
369
+ assert "models.py" in readme
370
+
371
+ assert hook_project_use_docker .entrypoint in files ["template.yml" ].read_text ()
372
+
373
+ # this is a rough check the generated Python code is valid as far as syntax
374
+ ast .parse (files [f"{ os .path .join ('src' , 'foo_bar_baz' , '__init__.py' )} " ].read_text ())
375
+ ast .parse (files [f"{ os .path .join ('src' , 'foo_bar_baz' , 'handlers.py' )} " ].read_text ())
376
+
377
+
245
378
def test_generate_resource (resource_project ):
246
379
resource_project .load_schema ()
247
380
before = get_files_in_project (resource_project )
@@ -406,6 +539,7 @@ def test__pip_build_called_process_error(tmp_path):
406
539
407
540
def test__build_pip (plugin ):
408
541
plugin ._use_docker = False
542
+ plugin ._no_docker = True
409
543
410
544
patch_pip = patch .object (plugin , "_pip_build" , autospec = True )
411
545
patch_docker = patch .object (plugin , "_docker_build" , autospec = True )
@@ -455,6 +589,7 @@ def test__build_pip_windows(plugin):
455
589
456
590
def test__build_docker (plugin ):
457
591
plugin ._use_docker = True
592
+ plugin ._no_docker = False
458
593
459
594
patch_pip = patch .object (plugin , "_pip_build" , autospec = True )
460
595
patch_docker = patch .object (plugin , "_docker_build" , autospec = True )
@@ -468,6 +603,7 @@ def test__build_docker(plugin):
468
603
# Test _build_docker on Linux/Unix-like systems
469
604
def test__build_docker_posix (plugin ):
470
605
plugin ._use_docker = True
606
+ plugin ._no_docker = False
471
607
472
608
patch_pip = patch .object (plugin , "_pip_build" , autospec = True )
473
609
patch_from_env = patch ("rpdk.python.codegen.docker.from_env" , autospec = True )
@@ -493,6 +629,7 @@ def test__build_docker_posix(plugin):
493
629
# Test _build_docker on Windows
494
630
def test__build_docker_windows (plugin ):
495
631
plugin ._use_docker = True
632
+ plugin ._no_docker = False
496
633
497
634
patch_pip = patch .object (plugin , "_pip_build" , autospec = True )
498
635
patch_from_env = patch ("rpdk.python.codegen.docker.from_env" , autospec = True )
@@ -518,6 +655,7 @@ def test__build_docker_windows(plugin):
518
655
# Test _build_docker if geteuid fails
519
656
def test__build_docker_no_euid (plugin ):
520
657
plugin ._use_docker = True
658
+ plugin ._no_docker = False
521
659
522
660
patch_pip = patch .object (plugin , "_pip_build" , autospec = True )
523
661
patch_from_env = patch ("rpdk.python.codegen.docker.from_env" , autospec = True )
0 commit comments