BoilerWorks

fix: collapse nested with statements to satisfy ruff SIM117

anonymous 2026-03-30 03:20 trunk
Commit fb274c9b93d3b39ec3938d9ce4616e6bcee4fd2022461f6fe5d0535ae29938ec
1 file changed +26 -16
--- tests/test_generator.py
+++ tests/test_generator.py
@@ -157,13 +157,15 @@
157157
"""When cloning ops fails, process exits."""
158158
ops_dest = tmp_path / "myproject-ops"
159159
progress = MagicMock()
160160
progress.add_task.return_value = "task-id"
161161
162
- with patch("boilerworks.generator._clone_repo", side_effect=RuntimeError("clone failed")):
163
- with pytest.raises(SystemExit):
164
- _clone_and_render_ops("myproject", "aws", "us-east-1", None, ops_dest, progress)
162
+ with (
163
+ patch("boilerworks.generator._clone_repo", side_effect=RuntimeError("clone failed")),
164
+ pytest.raises(SystemExit),
165
+ ):
166
+ _clone_and_render_ops("myproject", "aws", "us-east-1", None, ops_dest, progress)
165167
166168
167169
class TestGenerateFromManifestErrors:
168170
def test_missing_manifest_exits(self, tmp_path: Path) -> None:
169171
with pytest.raises(SystemExit):
@@ -234,13 +236,15 @@
234236
if "opscode" in repo:
235237
self._seed_opscode(dest)
236238
else:
237239
self._seed_template(dest)
238240
239
- with patch("boilerworks.generator._clone_repo", side_effect=fake_clone):
240
- with patch("boilerworks.generator.subprocess.run"):
241
- generate_from_manifest(manifest_path=str(manifest_file), output_dir=str(tmp_path))
241
+ with (
242
+ patch("boilerworks.generator._clone_repo", side_effect=fake_clone),
243
+ patch("boilerworks.generator.subprocess.run"),
244
+ ):
245
+ generate_from_manifest(manifest_path=str(manifest_file), output_dir=str(tmp_path))
242246
243247
assert call_count == 2
244248
assert (tmp_path / "myapp").exists()
245249
assert (tmp_path / "myapp-ops").exists()
246250
assert not (tmp_path / "myapp-ops" / ".git").exists()
@@ -267,13 +271,15 @@
267271
if "opscode" in repo:
268272
self._seed_opscode(dest)
269273
else:
270274
self._seed_template(dest)
271275
272
- with patch("boilerworks.generator._clone_repo", side_effect=fake_clone):
273
- with patch("boilerworks.generator.subprocess.run"):
274
- generate_from_manifest(manifest_path=str(manifest_file), output_dir=str(tmp_path))
276
+ with (
277
+ patch("boilerworks.generator._clone_repo", side_effect=fake_clone),
278
+ patch("boilerworks.generator.subprocess.run"),
279
+ ):
280
+ generate_from_manifest(manifest_path=str(manifest_file), output_dir=str(tmp_path))
275281
276282
assert call_count == 2
277283
assert (tmp_path / "myapp").exists()
278284
assert (tmp_path / "myapp" / "ops").exists()
279285
@@ -295,13 +301,15 @@
295301
def fake_clone(repo: str, dest: Path) -> None:
296302
nonlocal call_count
297303
call_count += 1
298304
self._seed_template(dest)
299305
300
- with patch("boilerworks.generator._clone_repo", side_effect=fake_clone):
301
- with patch("boilerworks.generator.subprocess.run"):
302
- generate_from_manifest(manifest_path=str(manifest_file), output_dir=str(tmp_path))
306
+ with (
307
+ patch("boilerworks.generator._clone_repo", side_effect=fake_clone),
308
+ patch("boilerworks.generator.subprocess.run"),
309
+ ):
310
+ generate_from_manifest(manifest_path=str(manifest_file), output_dir=str(tmp_path))
303311
304312
assert call_count == 1
305313
assert (tmp_path / "myapp").exists()
306314
assert not (tmp_path / "myapp-ops").exists()
307315
@@ -322,11 +330,13 @@
322330
(tmp_path / "myapp-ops").mkdir()
323331
324332
def fake_clone(repo: str, dest: Path) -> None:
325333
self._seed_template(dest)
326334
327
- with patch("boilerworks.generator._clone_repo", side_effect=fake_clone):
328
- with patch("boilerworks.generator.subprocess.run"):
329
- with pytest.raises(SystemExit):
330
- generate_from_manifest(manifest_path=str(manifest_file), output_dir=str(tmp_path))
335
+ with (
336
+ patch("boilerworks.generator._clone_repo", side_effect=fake_clone),
337
+ patch("boilerworks.generator.subprocess.run"),
338
+ pytest.raises(SystemExit),
339
+ ):
340
+ generate_from_manifest(manifest_path=str(manifest_file), output_dir=str(tmp_path))
331341
332342
shutil.rmtree(tmp_path / "myapp", ignore_errors=True)
333343
--- tests/test_generator.py
+++ tests/test_generator.py
@@ -157,13 +157,15 @@
157 """When cloning ops fails, process exits."""
158 ops_dest = tmp_path / "myproject-ops"
159 progress = MagicMock()
160 progress.add_task.return_value = "task-id"
161
162 with patch("boilerworks.generator._clone_repo", side_effect=RuntimeError("clone failed")):
163 with pytest.raises(SystemExit):
164 _clone_and_render_ops("myproject", "aws", "us-east-1", None, ops_dest, progress)
 
 
165
166
167 class TestGenerateFromManifestErrors:
168 def test_missing_manifest_exits(self, tmp_path: Path) -> None:
169 with pytest.raises(SystemExit):
@@ -234,13 +236,15 @@
234 if "opscode" in repo:
235 self._seed_opscode(dest)
236 else:
237 self._seed_template(dest)
238
239 with patch("boilerworks.generator._clone_repo", side_effect=fake_clone):
240 with patch("boilerworks.generator.subprocess.run"):
241 generate_from_manifest(manifest_path=str(manifest_file), output_dir=str(tmp_path))
 
 
242
243 assert call_count == 2
244 assert (tmp_path / "myapp").exists()
245 assert (tmp_path / "myapp-ops").exists()
246 assert not (tmp_path / "myapp-ops" / ".git").exists()
@@ -267,13 +271,15 @@
267 if "opscode" in repo:
268 self._seed_opscode(dest)
269 else:
270 self._seed_template(dest)
271
272 with patch("boilerworks.generator._clone_repo", side_effect=fake_clone):
273 with patch("boilerworks.generator.subprocess.run"):
274 generate_from_manifest(manifest_path=str(manifest_file), output_dir=str(tmp_path))
 
 
275
276 assert call_count == 2
277 assert (tmp_path / "myapp").exists()
278 assert (tmp_path / "myapp" / "ops").exists()
279
@@ -295,13 +301,15 @@
295 def fake_clone(repo: str, dest: Path) -> None:
296 nonlocal call_count
297 call_count += 1
298 self._seed_template(dest)
299
300 with patch("boilerworks.generator._clone_repo", side_effect=fake_clone):
301 with patch("boilerworks.generator.subprocess.run"):
302 generate_from_manifest(manifest_path=str(manifest_file), output_dir=str(tmp_path))
 
 
303
304 assert call_count == 1
305 assert (tmp_path / "myapp").exists()
306 assert not (tmp_path / "myapp-ops").exists()
307
@@ -322,11 +330,13 @@
322 (tmp_path / "myapp-ops").mkdir()
323
324 def fake_clone(repo: str, dest: Path) -> None:
325 self._seed_template(dest)
326
327 with patch("boilerworks.generator._clone_repo", side_effect=fake_clone):
328 with patch("boilerworks.generator.subprocess.run"):
329 with pytest.raises(SystemExit):
330 generate_from_manifest(manifest_path=str(manifest_file), output_dir=str(tmp_path))
 
 
331
332 shutil.rmtree(tmp_path / "myapp", ignore_errors=True)
333
--- tests/test_generator.py
+++ tests/test_generator.py
@@ -157,13 +157,15 @@
157 """When cloning ops fails, process exits."""
158 ops_dest = tmp_path / "myproject-ops"
159 progress = MagicMock()
160 progress.add_task.return_value = "task-id"
161
162 with (
163 patch("boilerworks.generator._clone_repo", side_effect=RuntimeError("clone failed")),
164 pytest.raises(SystemExit),
165 ):
166 _clone_and_render_ops("myproject", "aws", "us-east-1", None, ops_dest, progress)
167
168
169 class TestGenerateFromManifestErrors:
170 def test_missing_manifest_exits(self, tmp_path: Path) -> None:
171 with pytest.raises(SystemExit):
@@ -234,13 +236,15 @@
236 if "opscode" in repo:
237 self._seed_opscode(dest)
238 else:
239 self._seed_template(dest)
240
241 with (
242 patch("boilerworks.generator._clone_repo", side_effect=fake_clone),
243 patch("boilerworks.generator.subprocess.run"),
244 ):
245 generate_from_manifest(manifest_path=str(manifest_file), output_dir=str(tmp_path))
246
247 assert call_count == 2
248 assert (tmp_path / "myapp").exists()
249 assert (tmp_path / "myapp-ops").exists()
250 assert not (tmp_path / "myapp-ops" / ".git").exists()
@@ -267,13 +271,15 @@
271 if "opscode" in repo:
272 self._seed_opscode(dest)
273 else:
274 self._seed_template(dest)
275
276 with (
277 patch("boilerworks.generator._clone_repo", side_effect=fake_clone),
278 patch("boilerworks.generator.subprocess.run"),
279 ):
280 generate_from_manifest(manifest_path=str(manifest_file), output_dir=str(tmp_path))
281
282 assert call_count == 2
283 assert (tmp_path / "myapp").exists()
284 assert (tmp_path / "myapp" / "ops").exists()
285
@@ -295,13 +301,15 @@
301 def fake_clone(repo: str, dest: Path) -> None:
302 nonlocal call_count
303 call_count += 1
304 self._seed_template(dest)
305
306 with (
307 patch("boilerworks.generator._clone_repo", side_effect=fake_clone),
308 patch("boilerworks.generator.subprocess.run"),
309 ):
310 generate_from_manifest(manifest_path=str(manifest_file), output_dir=str(tmp_path))
311
312 assert call_count == 1
313 assert (tmp_path / "myapp").exists()
314 assert not (tmp_path / "myapp-ops").exists()
315
@@ -322,11 +330,13 @@
330 (tmp_path / "myapp-ops").mkdir()
331
332 def fake_clone(repo: str, dest: Path) -> None:
333 self._seed_template(dest)
334
335 with (
336 patch("boilerworks.generator._clone_repo", side_effect=fake_clone),
337 patch("boilerworks.generator.subprocess.run"),
338 pytest.raises(SystemExit),
339 ):
340 generate_from_manifest(manifest_path=str(manifest_file), output_dir=str(tmp_path))
341
342 shutil.rmtree(tmp_path / "myapp", ignore_errors=True)
343

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button