Files
absdev-deployment/tests/unit/test_dev3_runtime.py

25 lines
973 B
Python

import os
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
from core.dev3.runtime import Runtime, RuntimeError
class RuntimeTests(unittest.TestCase):
def test_exact_command_private_environment_and_timeout(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory).resolve()
command = (sys.executable, "-c", "import os; assert 'HOME' not in os.environ")
slow = (sys.executable, "-c", "import time; time.sleep(30)")
runtime = Runtime(root, [command, slow], {"PATH": os.defpath})
runtime.run(command, cwd=root)
with self.assertRaises(RuntimeError):
runtime.run((*command, "extra"), cwd=root)
with self.assertRaises(RuntimeError):
runtime.run(command, cwd=root.parent)
with self.assertRaises(subprocess.TimeoutExpired):
runtime.run(slow, cwd=root, timeout=0.1)