mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 01:16:10 +00:00
131 test modules sat next to the code they test; instances alone had 51 of them beside views.py and utils.py. They move into a tests/ package per app, and the JavaScript checks into webvirtcloud/tests/js. Each non-empty tests.py becomes tests/test_views.py; the empty generated stubs are removed. Imports of the app's own modules become absolute, paths built from __file__ go one level up, the live helper is instances.tests.livetest, and coverage omits */tests/*. The suite discovers the same 960 tests as before.
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
"""Loading the web app or novncd must not change how child processes are reaped.
|
|
|
|
With SIGCHLD ignored process-wide, the kernel reaps every child at once and
|
|
subprocess loses its exit status: a failing command reports 0.
|
|
"""
|
|
|
|
import subprocess
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent.parent
|
|
|
|
CHECK = """
|
|
import signal, subprocess
|
|
assert signal.getsignal(signal.SIGCHLD) == signal.SIG_DFL, signal.getsignal(signal.SIGCHLD)
|
|
print(subprocess.run(["false"]).returncode)
|
|
"""
|
|
|
|
LOAD_NOVNCD = """
|
|
import importlib.machinery, importlib.util
|
|
loader = importlib.machinery.SourceFileLoader("novncd", "console/novncd")
|
|
loader.exec_module(importlib.util.module_from_spec(importlib.util.spec_from_loader("novncd", loader)))
|
|
"""
|
|
|
|
|
|
class ChildProcessTestCase(unittest.TestCase):
|
|
def run_python(self, code):
|
|
result = subprocess.run(
|
|
[sys.executable, "-c", code], cwd=ROOT, capture_output=True, text=True, timeout=60
|
|
)
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
return result.stdout.strip().splitlines()[-1]
|
|
|
|
def test_failing_command_is_nonzero_after_loading_the_web_app(self):
|
|
self.assertEqual(self.run_python("import webvirtcloud.wsgi\n" + CHECK), "1")
|
|
|
|
def test_failing_command_is_nonzero_after_loading_novncd(self):
|
|
self.assertEqual(self.run_python(LOAD_NOVNCD + CHECK), "1")
|