mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-10-05 23:05:10 +00:00
test(starlark): fake only the editor launch, not every Popen in the request
TestPixletEditorHostDefaultsButDoesNotOverride patched subprocess.Popen for the whole request. When the captive-portal before_request hook's 30s AP-mode cache had expired, its `systemctl is-active hostapd` check went through subprocess.run, got the fake process, and raised TypeError (run() uses the process as a context manager): a 500 instead of 200. Seen on the Python 3.13 job; reproduced locally by forcing the cache to expire. Other calls now reach the real Popen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1131,9 +1131,17 @@ class TestPixletEditorHostDefaultsButDoesNotOverride:
|
|||||||
class FakeProcess:
|
class FakeProcess:
|
||||||
pid = 424242
|
pid = 424242
|
||||||
|
|
||||||
|
real_popen = mod.subprocess.Popen
|
||||||
|
|
||||||
def fake_popen(cmd, *args, env=None, **kwargs):
|
def fake_popen(cmd, *args, env=None, **kwargs):
|
||||||
if env is not None:
|
# Only the editor launch is faked. Patching subprocess.Popen
|
||||||
captured['env'] = env
|
# patches it for the whole request, and the captive-portal
|
||||||
|
# before_request hook runs `systemctl is-active hostapd` through
|
||||||
|
# subprocess.run whenever its 30s cache has expired -- which
|
||||||
|
# needs a real process (run() uses it as a context manager).
|
||||||
|
if str(script) not in cmd:
|
||||||
|
return real_popen(cmd, *args, env=env, **kwargs)
|
||||||
|
captured['env'] = env
|
||||||
return FakeProcess()
|
return FakeProcess()
|
||||||
|
|
||||||
with patch.object(mod, '_validate_starlark_app_path',
|
with patch.object(mod, '_validate_starlark_app_path',
|
||||||
|
|||||||
Reference in New Issue
Block a user