53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import sys
|
|
import unittest
|
|
|
|
|
|
SRC_ROOT = Path(__file__).resolve().parents[2] / "src"
|
|
|
|
if str(SRC_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(SRC_ROOT))
|
|
|
|
|
|
from ffx.process import ( # noqa: E402
|
|
COMMAND_NOT_FOUND_RETURN_CODE,
|
|
COMMAND_TIMED_OUT_RETURN_CODE,
|
|
executeProcess,
|
|
)
|
|
|
|
|
|
class ProcessTests(unittest.TestCase):
|
|
def test_execute_process_returns_stdout_for_success(self):
|
|
out, err, rc = executeProcess(
|
|
[sys.executable, "-c", "print('hello from process')"]
|
|
)
|
|
|
|
self.assertEqual(0, rc)
|
|
self.assertEqual("", err)
|
|
self.assertEqual("hello from process\n", out)
|
|
|
|
def test_execute_process_maps_missing_command_to_stable_error(self):
|
|
out, err, rc = executeProcess(["ffx-command-that-does-not-exist"])
|
|
|
|
self.assertEqual("", out)
|
|
self.assertEqual(COMMAND_NOT_FOUND_RETURN_CODE, rc)
|
|
self.assertIn("Command not found while running", err)
|
|
self.assertIn("ffx-command-that-does-not-exist", err)
|
|
|
|
def test_execute_process_maps_timeout_to_stable_error(self):
|
|
out, err, rc = executeProcess(
|
|
[sys.executable, "-c", "import time; time.sleep(0.2)"],
|
|
timeoutSeconds=0.05,
|
|
)
|
|
|
|
self.assertEqual("", out)
|
|
self.assertEqual(COMMAND_TIMED_OUT_RETURN_CODE, rc)
|
|
self.assertIn("Command timed out", err)
|
|
self.assertIn(sys.executable, err)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|