BoilerWorks
fix: collapse nested with statements to satisfy ruff SIM117
Commit
fb274c9b93d3b39ec3938d9ce4616e6bcee4fd2022461f6fe5d0535ae29938ec
Parent
6f8311253dfeca7…
1 file changed
+26
-16
+26
-16
| --- tests/test_generator.py | ||
| +++ tests/test_generator.py | ||
| @@ -157,13 +157,15 @@ | ||
| 157 | 157 | """When cloning ops fails, process exits.""" |
| 158 | 158 | ops_dest = tmp_path / "myproject-ops" |
| 159 | 159 | progress = MagicMock() |
| 160 | 160 | progress.add_task.return_value = "task-id" |
| 161 | 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) | |
| 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) | |
| 165 | 167 | |
| 166 | 168 | |
| 167 | 169 | class TestGenerateFromManifestErrors: |
| 168 | 170 | def test_missing_manifest_exits(self, tmp_path: Path) -> None: |
| 169 | 171 | with pytest.raises(SystemExit): |
| @@ -234,13 +236,15 @@ | ||
| 234 | 236 | if "opscode" in repo: |
| 235 | 237 | self._seed_opscode(dest) |
| 236 | 238 | else: |
| 237 | 239 | self._seed_template(dest) |
| 238 | 240 | |
| 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)) | |
| 242 | 246 | |
| 243 | 247 | assert call_count == 2 |
| 244 | 248 | assert (tmp_path / "myapp").exists() |
| 245 | 249 | assert (tmp_path / "myapp-ops").exists() |
| 246 | 250 | assert not (tmp_path / "myapp-ops" / ".git").exists() |
| @@ -267,13 +271,15 @@ | ||
| 267 | 271 | if "opscode" in repo: |
| 268 | 272 | self._seed_opscode(dest) |
| 269 | 273 | else: |
| 270 | 274 | self._seed_template(dest) |
| 271 | 275 | |
| 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)) | |
| 275 | 281 | |
| 276 | 282 | assert call_count == 2 |
| 277 | 283 | assert (tmp_path / "myapp").exists() |
| 278 | 284 | assert (tmp_path / "myapp" / "ops").exists() |
| 279 | 285 | |
| @@ -295,13 +301,15 @@ | ||
| 295 | 301 | def fake_clone(repo: str, dest: Path) -> None: |
| 296 | 302 | nonlocal call_count |
| 297 | 303 | call_count += 1 |
| 298 | 304 | self._seed_template(dest) |
| 299 | 305 | |
| 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)) | |
| 303 | 311 | |
| 304 | 312 | assert call_count == 1 |
| 305 | 313 | assert (tmp_path / "myapp").exists() |
| 306 | 314 | assert not (tmp_path / "myapp-ops").exists() |
| 307 | 315 | |
| @@ -322,11 +330,13 @@ | ||
| 322 | 330 | (tmp_path / "myapp-ops").mkdir() |
| 323 | 331 | |
| 324 | 332 | def fake_clone(repo: str, dest: Path) -> None: |
| 325 | 333 | self._seed_template(dest) |
| 326 | 334 | |
| 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)) | |
| 331 | 341 | |
| 332 | 342 | shutil.rmtree(tmp_path / "myapp", ignore_errors=True) |
| 333 | 343 |
| --- 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 |