From 754a0e45d79ae9252022edd5370bf3fd9f701e5f Mon Sep 17 00:00:00 2001 From: pcarrier Date: Sat, 27 Nov 2010 22:12:49 +0000 Subject: [tests] worker: multiple helpers Handling \r\n and \n is apparently more difficult than expected... We want to make sure we do not let worker speak more than we expect -> checking that .before is empty except when using lose_expect() git-svn-id: svn+ssh://svn.fedorahosted.org/svn/sos/trunk@1040 ef72aa8b-4018-0410-8976-d6e080ef94d8 --- tests/worker.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/worker.py b/tests/worker.py index 49d8bd15..38688fd7 100644 --- a/tests/worker.py +++ b/tests/worker.py @@ -14,17 +14,34 @@ class PexpectTest(unittest.TestCase): # worker should always be very fast to span self.expect('#0#\r\n') + def sig(self, sig): + kill(self.worker.pid, sig) + + def lose_expect(self, v, timeout = 3): + self.worker.expect(v, timeout) + + def expect(self, v, timeout = 3): + self.lose_expect(v, timeout) + self.assertEqual(self.worker.before, '') + + def send(self, text): + self.worker.send(text) + self.expect(escape(text)) + def sendlines(self, lines): for line in lines: - self.worker.sendline(line) - self.worker.expect(line+'\r\n') + self.worker.send(line+'\n') + for line in lines: + self.expect(escape(line)+'\r\n') - def expect(self, v, timeout = 3): - self.worker.expect(v, timeout) - self.assertEqual(self.worker.before, "") + def __finishes_ok__(self): + self.expect(pexpect.EOF) + self.worker.close() + self.assertEqual(self.worker.exitstatus, 0) def test_exit(self): self.sendlines(['exit']) + self.__finishes_ok__() self.expect(pexpect.EOF) def test_basic_noop(self): -- cgit