[tests] switch to pytest

This commit is contained in:
Tobias Witek 2020-06-20 14:53:44 +02:00
parent b2e92d816d
commit 39fa7788b4
37 changed files with 1009 additions and 2259 deletions

View file

@ -1,43 +1,27 @@
import unittest
import pytest
import util.cli
def test_valid_command():
assert util.cli.execute("echo test") == "test\n"
class cli(unittest.TestCase):
def setUp(self):
self.nonExistentCommand = "i-do-not-exist"
self.validCommand = "echo test"
self.validCommandOutput = "test\n"
self.utfCommand = "echo ÖPmŧß"
self.utfCommandOutput = "ÖPmŧß\n"
def test_utf_command():
rv = util.cli.execute("echo ÖPmŧß")
assert util.cli.execute("echo ÖPmŧß") == "ÖPmŧß\n"
def test_valid_command(self):
rv = util.cli.execute(self.validCommand)
self.assertEqual(self.validCommandOutput, rv)
def test_invalid_command():
with pytest.raises(RuntimeError):
util.cli.execute("i-do-not-exist")
def test_utf_command(self):
rv = util.cli.execute(self.utfCommand)
self.assertEqual(self.utfCommandOutput, rv)
def test_command_exit_code():
with pytest.raises(RuntimeError):
util.cli.execute("cat i-do-not-exist")
def test_invalid_command(self):
with self.assertRaises(RuntimeError):
util.cli.execute(self.nonExistentCommand)
def test_command_exit_code_no_error():
util.cli.execute("cat i-do-not-exist", ignore_errors=True)
def test_command_exit_code(self):
with self.assertRaises(RuntimeError):
util.cli.execute("cat {}".format(self.nonExistentCommand))
def test_command_exit_code_no_error(self):
try:
util.cli.execute(
"cat {}".format(self.nonExistentCommand), ignore_errors=True
)
except Exception:
self.fail("exception was thrown")
def test_async(self):
rv = util.cli.execute(self.validCommand, wait=False)
self.assertEqual("", rv)
def test_async():
assert util.cli.execute("echo test", wait=False) == ""
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4