| | @@ -5,6 +5,7 @@ import os |
| 5 | 5 | import re |
| 6 | 6 | from pathlib import Path |
| 7 | 7 | import subprocess |
| 8 | +추가: import sys |
| 8 | 9 | import tempfile |
| 9 | 10 | import unittest |
| 10 | 11 | from unittest.mock import patch |
| | @@ -72,6 +73,39 @@ class LifecycleTests(unittest.TestCase): |
| 72 | 73 | output) |
| 73 | 74 | self.assertIn(str(SMOKE.work_root() / "ubuntu-package-smoke"), output) |
| 74 | 75 | |
| 76 | +추가: def test_existing_installation_is_blocked_with_python_optimization(self): |
| 77 | +추가: script = """import importlib.util |
| 78 | +추가: import subprocess |
| 79 | +추가: import sys |
| 80 | +추가: from unittest.mock import patch |
| 81 | +추가: |
| 82 | +추가: spec = importlib.util.spec_from_file_location("ubuntu_smoke", sys.argv[1]) |
| 83 | +추가: module = importlib.util.module_from_spec(spec) |
| 84 | +추가: spec.loader.exec_module(module) |
| 85 | +추가: with patch.object(module.subprocess, "run", return_value=subprocess.CompletedProcess([], 0, b"installed")): |
| 86 | +추가: try: |
| 87 | +추가: module.ensure_no_existing_installation() |
| 88 | +추가: except RuntimeError: |
| 89 | +추가: print("blocked") |
| 90 | +추가: else: |
| 91 | +추가: raise SystemExit("기존 설치를 통과시킴") |
| 92 | +추가: """ |
| 93 | +추가: environment = dict(os.environ, PYTHONDONTWRITEBYTECODE="1") |
| 94 | +추가: result = subprocess.run( |
| 95 | +추가: [sys.executable, "-O", "-c", script, str(SMOKE.ROOT / "tests/release-packages/ubuntu_smoke.py")], |
| 96 | +추가: env=environment, cwd=ROOT, capture_output=True, text=True, |
| 97 | +추가: ) |
| 98 | +추가: self.assertEqual(result.returncode, 0, result.stderr) |
| 99 | +추가: self.assertEqual(result.stdout.strip(), "blocked") |
| 100 | +추가: |
| 101 | +추가: def test_existing_installation_files_are_blocked(self): |
| 102 | +추가: with ( |
| 103 | +추가: patch.object(SMOKE.subprocess, "run", return_value=subprocess.CompletedProcess([], 1, b"")), |
| 104 | +추가: patch.object(SMOKE.Path, "exists", return_value=True), |
| 105 | +추가: ): |
| 106 | +추가: with self.assertRaisesRegex(RuntimeError, "기존 파일"): |
| 107 | +추가: SMOKE.ensure_no_existing_installation() |
| 108 | +추가: |
| 75 | 109 | def test_only_first_configuration_sets_defaults(self): |
| 76 | 110 | commands = self.directory / "bin" |
| 77 | 111 | commands.mkdir() |