From b6e1aaf11332a1df750fcd61e7f1a9c6244a4fb6 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 28 Jun 2011 20:12:51 +0100 Subject: Move systest base class to its own module. --- systest | 54 ++---------------------------------------------------- 1 file changed, 2 insertions(+), 52 deletions(-) (limited to 'systest') diff --git a/systest b/systest index 7142d98..bf650b5 100755 --- a/systest +++ b/systest @@ -6,60 +6,10 @@ import re import subprocess import unittest +import systest -class AssertionFailure(cliapp.AppException): - def __init__(self, msg): - self._str = msg - - def __str__(self): - return self._str - - -class TestCase(unittest.TestCase): - - '''Base class for system tests. - - This extends ``unittest.TestCase`` with some things that are - relevant to system tests. - - ''' - - def runcmd(self, argv, stdin='', *args, **kwargs): - p = subprocess.Popen(argv, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - out, err = p.communicate(stdin) - return p.returncode, out, err - - def hostcmd(self, argv, *args, **kwargs): - '''Run external command on test host.''' - returncode, out, err = self.runcmd(argv, *args, **kwargs) - if returncode: - msg = 'host command failed: %s\n%s' % (' '.join(argv), err) - logging.error(msg) - raise cliapp.AppException(msg) - return out - - def targetcmd(self, argv, *args, **kwargs): - '''Run command on test target.''' - full_argv = (['ssh', '-l', self.settings['user'], - self.settings['target']] + - argv) - returncode, out, err = self.runcmd(full_argv, *args, **kwargs) - if returncode: - msg = 'target command failed: %s\n%s' % (' '.join(argv), err) - logging.error(msg) - raise cliapp.AppException(msg) - return out - - def assertMatches(self, pat, text, msg=None): - self.assert_(re.match(pat, text), - msg=('pattern %s does not match %s' % (pat, text)) or msg) - - -class DebianBaseTests(TestCase): +class DebianBaseTests(systest.TestCase): def test_only_ssh_port(self): out = self.hostcmd(['nmap', self.settings['target']]) -- cgit v1.2.1