diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-06-28 20:12:51 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-06-28 20:12:51 +0100 |
commit | b6e1aaf11332a1df750fcd61e7f1a9c6244a4fb6 (patch) | |
tree | aaf021a0297a4b128ed48fce2603d0660528c3c3 /systest | |
parent | 7e7fb4ccb29d831db6dc3c81ff41fdeacac17597 (diff) | |
download | systest-b6e1aaf11332a1df750fcd61e7f1a9c6244a4fb6.tar.gz |
Move systest base class to its own module.
Diffstat (limited to 'systest')
-rwxr-xr-x | systest | 54 |
1 files changed, 2 insertions, 52 deletions
@@ -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']]) |