33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
import json
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import time
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
import shellmcp
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
class Run(unittest.TestCase):
|
|
def test_exit_code_and_combined_output(self):
|
|
self.assertEqual(shellmcp.run("echo hi; echo oops >&2; exit 3", HERE),
|
|
"exit code 3\nhi\noops\n")
|
|
|
|
def test_long_output_keeps_head_and_tail(self):
|
|
out = shellmcp.run("printf 'a%.0s' $(seq 100); printf 'b%.0s' $(seq 100)", HERE, limit=20)
|
|
self.assertEqual(out, "exit code 0\naaaaaaaaaa\n[... 180 characters cut ...]\nbbbbbbbbbb")
|
|
|
|
def test_timeout_kills_the_whole_group(self):
|
|
start = time.monotonic()
|
|
out = shellmcp.run("sleep 30 & sleep 30", HERE, timeout=1)
|
|
self.assertLess(time.monotonic() - start, 5)
|
|
self.assertEqual(out, "timed out after 1 s, killed\n")
|
|
|
|
def test_no_stdin_and_no_pager(self):
|
|
self.assertEqual(shellmcp.run("cat; echo $PAGER", HERE), "exit code 0\ncat\n")
|