|
4 | 4 | import json |
5 | 5 | from pathlib import Path |
6 | 6 | import subprocess |
| 7 | +import sys |
7 | 8 | import unittest |
8 | 9 | from unittest.mock import patch |
9 | 10 |
|
10 | 11 |
|
| 12 | +REAL_RUN = subprocess.run |
11 | 13 | SCRIPT = Path(__file__).resolve().parents[1] / "hack" / "satellite-pre-stop.py" |
12 | 14 | SPEC = importlib.util.spec_from_file_location("satellite_pre_stop", SCRIPT) |
13 | 15 | hook = importlib.util.module_from_spec(SPEC) |
@@ -200,6 +202,23 @@ def test_unknown_argument_prevents_even_status(self): |
200 | 202 | hook.main() |
201 | 203 | self.run.assert_not_called() |
202 | 204 |
|
| 205 | + def test_chart_command_form_passes_execute_as_the_only_argument(self): |
| 206 | + # The chart renders `python3 -c <script> --execute`; CPython sets |
| 207 | + # sys.argv[0] to "-c" for that form, so main() receives ["--execute"]. |
| 208 | + probe = REAL_RUN([sys.executable, "-c", "import sys; print(sys.argv)", "--execute"], |
| 209 | + capture_output=True, text=True, check=True) |
| 210 | + self.assertEqual(probe.stdout.strip(), "['-c', '--execute']") |
| 211 | + hook.sys.argv = ["-c", "--execute"] |
| 212 | + self.run.return_value = self.status() |
| 213 | + hook.main() |
| 214 | + self.events.assert_called_once_with("finished", execute=True, resources=0) |
| 215 | + |
| 216 | + def test_script_name_placeholder_before_execute_is_rejected(self): |
| 217 | + hook.sys.argv = ["-c", "hook", "--execute"] |
| 218 | + with self.assertRaisesRegex(ValueError, "unsupported-arguments"): |
| 219 | + hook.main() |
| 220 | + self.run.assert_not_called() |
| 221 | + |
203 | 222 | def test_empty_resource_list_is_a_noop(self): |
204 | 223 | self.run.return_value = self.status() |
205 | 224 | hook.main() |
|
0 commit comments