@@ -108,7 +108,32 @@ def resource_project(tmp_path):
108108 "rpdk.python.codegen.input_with_validation" , autospec = True , side_effect = [False ]
109109 )
110110 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+ )
112137 return project
113138
114139
@@ -125,7 +150,32 @@ def hook_project(tmp_path):
125150 "rpdk.python.codegen.input_with_validation" , autospec = True , side_effect = [False ]
126151 )
127152 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+ )
129179 return project
130180
131181
@@ -172,6 +222,7 @@ def test__remove_build_artifacts_file_not_found(tmp_path):
172222def test_initialize_resource (resource_project ):
173223 assert resource_project .settings == {
174224 "use_docker" : False ,
225+ "no_docker" : True ,
175226 "protocolVersion" : "2.0.0" ,
176227 }
177228
@@ -209,8 +260,53 @@ def test_initialize_resource(resource_project):
209260 ast .parse (files [f"{ os .path .join ('src' , 'foo_bar_baz' , 'handlers.py' )} " ].read_text ())
210261
211262
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+
212304def 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+ }
214310
215311 files = get_files_in_project (hook_project )
216312 assert set (files ) == {
@@ -242,6 +338,43 @@ def test_initialize_hook(hook_project):
242338 ast .parse (files [f"{ os .path .join ('src' , 'foo_bar_baz' , 'handlers.py' )} " ].read_text ())
243339
244340
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+
245378def test_generate_resource (resource_project ):
246379 resource_project .load_schema ()
247380 before = get_files_in_project (resource_project )
@@ -406,6 +539,7 @@ def test__pip_build_called_process_error(tmp_path):
406539
407540def test__build_pip (plugin ):
408541 plugin ._use_docker = False
542+ plugin ._no_docker = True
409543
410544 patch_pip = patch .object (plugin , "_pip_build" , autospec = True )
411545 patch_docker = patch .object (plugin , "_docker_build" , autospec = True )
@@ -455,6 +589,7 @@ def test__build_pip_windows(plugin):
455589
456590def test__build_docker (plugin ):
457591 plugin ._use_docker = True
592+ plugin ._no_docker = False
458593
459594 patch_pip = patch .object (plugin , "_pip_build" , autospec = True )
460595 patch_docker = patch .object (plugin , "_docker_build" , autospec = True )
@@ -468,6 +603,7 @@ def test__build_docker(plugin):
468603# Test _build_docker on Linux/Unix-like systems
469604def test__build_docker_posix (plugin ):
470605 plugin ._use_docker = True
606+ plugin ._no_docker = False
471607
472608 patch_pip = patch .object (plugin , "_pip_build" , autospec = True )
473609 patch_from_env = patch ("rpdk.python.codegen.docker.from_env" , autospec = True )
@@ -493,6 +629,7 @@ def test__build_docker_posix(plugin):
493629# Test _build_docker on Windows
494630def test__build_docker_windows (plugin ):
495631 plugin ._use_docker = True
632+ plugin ._no_docker = False
496633
497634 patch_pip = patch .object (plugin , "_pip_build" , autospec = True )
498635 patch_from_env = patch ("rpdk.python.codegen.docker.from_env" , autospec = True )
@@ -518,6 +655,7 @@ def test__build_docker_windows(plugin):
518655# Test _build_docker if geteuid fails
519656def test__build_docker_no_euid (plugin ):
520657 plugin ._use_docker = True
658+ plugin ._no_docker = False
521659
522660 patch_pip = patch .object (plugin , "_pip_build" , autospec = True )
523661 patch_from_env = patch ("rpdk.python.codegen.docker.from_env" , autospec = True )
0 commit comments