2020-02-08 13:39:35 +01:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
import util.cli
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-02-08 13:39:35 +01:00
|
|
|
class cli(unittest.TestCase):
|
|
|
|
def setUp(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
self.nonExistentCommand = "i-do-not-exist"
|
|
|
|
self.validCommand = "echo test"
|
|
|
|
self.validCommandOutput = "test\n"
|
|
|
|
self.utfCommand = "echo ÖPmŧß"
|
|
|
|
self.utfCommandOutput = "ÖPmŧß\n"
|
2020-02-08 13:39:35 +01:00
|
|
|
|
|
|
|
def test_valid_command(self):
|
|
|
|
rv = util.cli.execute(self.validCommand)
|
|
|
|
self.assertEqual(self.validCommandOutput, rv)
|
|
|
|
|
|
|
|
def test_utf_command(self):
|
|
|
|
rv = util.cli.execute(self.utfCommand)
|
|
|
|
self.assertEqual(self.utfCommandOutput, rv)
|
|
|
|
|
|
|
|
def test_invalid_command(self):
|
|
|
|
with self.assertRaises(RuntimeError):
|
|
|
|
util.cli.execute(self.nonExistentCommand)
|
|
|
|
|
|
|
|
def test_command_exit_code(self):
|
|
|
|
with self.assertRaises(RuntimeError):
|
2020-05-03 11:15:52 +02:00
|
|
|
util.cli.execute("cat {}".format(self.nonExistentCommand))
|
2020-02-08 13:39:35 +01:00
|
|
|
|
2020-02-23 13:44:49 +01:00
|
|
|
def test_command_exit_code_no_error(self):
|
|
|
|
try:
|
2020-05-03 11:15:52 +02:00
|
|
|
util.cli.execute(
|
|
|
|
"cat {}".format(self.nonExistentCommand), ignore_errors=True
|
|
|
|
)
|
2020-02-23 13:44:49 +01:00
|
|
|
except Exception:
|
2020-05-03 11:15:52 +02:00
|
|
|
self.fail("exception was thrown")
|
2020-02-23 13:44:49 +01:00
|
|
|
|
2020-02-08 13:39:35 +01:00
|
|
|
def test_async(self):
|
|
|
|
rv = util.cli.execute(self.validCommand, wait=False)
|
2020-05-03 11:15:52 +02:00
|
|
|
self.assertEqual("", rv)
|
|
|
|
|
2020-02-08 13:39:35 +01:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|