frostfs-testlib/tests/test_local_shell_non_interactive.py
Vladimir Domnich f6ee129354 Implement basic version of local shell
Also added two simple reporters that can be used by the shell to report command execution details.

Signed-off-by: Vladimir Domnich <v.domnich@yadro.com>
2022-09-09 18:12:42 +04:00

46 lines
1.4 KiB
Python

from unittest import TestCase
from shell.interfaces import CommandOptions
from shell.local_shell import LocalShell
from tests.helpers import format_error_details
class TestLocalShellNonInteractive(TestCase):
@classmethod
def setUpClass(cls):
cls.shell = LocalShell()
def test_successful_command(self):
script = "print('test')"
result = self.shell.exec(f"python -c \"{script}\"")
self.assertEqual(0, result.return_code)
self.assertEqual("test", result.stdout.strip())
self.assertEqual("", result.stderr)
def test_failed_command_with_check(self):
script = "invalid script"
with self.assertRaises(RuntimeError) as exc:
self.shell.exec(f"python -c \"{script}\"")
error = format_error_details(exc.exception)
self.assertIn("Error", error)
self.assertIn("return code: 1", error)
def test_failed_command_without_check(self):
script = "invalid script"
result = self.shell.exec(f"python -c \"{script}\"", CommandOptions(check=False))
self.assertEqual(1, result.return_code)
self.assertIn("Error", result.stdout)
def test_non_existing_binary(self):
with self.assertRaises(RuntimeError) as exc:
self.shell.exec(f"not-a-command")
error = format_error_details(exc.exception)
self.assertIn("Error", error)
self.assertIn("return code: 127", error)