From 4c0ba99062bc72bffeaaac5325cc2ab9f0a4595e Mon Sep 17 00:00:00 2001 From: pcarrier Date: Sun, 28 Nov 2010 00:36:16 +0000 Subject: [tests] worker: add prompt() and mutualize the "echo lol" output git-svn-id: svn+ssh://svn.fedorahosted.org/svn/sos/trunk@1049 ef72aa8b-4018-0410-8976-d6e080ef94d8 --- tests/worker.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/tests/worker.py b/tests/worker.py index 45a39db9..4111318b 100644 --- a/tests/worker.py +++ b/tests/worker.py @@ -7,12 +7,17 @@ from re import search, escape from os import kill from signal import SIGINT, SIGUSR1 -class PexpectTest(unittest.TestCase): +class WorkerTests(unittest.TestCase): + + __exec_echo_lol_output__ = '0\r\n4\r\nlol\r\n\r\n0\r\n\r\n' + + def prompt(self, n): + return ('#%i#\r\n' % n) def setUp(self): self.worker = pexpect.spawn('python ../worker/worker.py') # worker should always be very fast to span - self.expect('#0#\r\n') + self.expect(self.prompt(0)) def sig(self, sig): kill(self.worker.pid, sig) @@ -57,47 +62,48 @@ class PexpectTest(unittest.TestCase): def test_ctrlc_on_readparms_drops(self): self.sendlines(['exec']) self.sig(SIGINT) - self.expect('#0#\r\n') + self.expect(self.prompt(0)) self.sendlines(['glob']) self.sig(SIGINT) - self.expect('#0#\r\n') + self.expect(self.prompt(0)) + def test_basic_noop(self): self.sendlines(['noop']) - self.expect('#1#\r\n') + self.expect(self.prompt(1)) self.test_exit() def test_basic_ping(self): self.sendlines(['ping']) - self.expect('ALIVE\r\n#1#\r\n') + self.expect('ALIVE\r\n' + self.prompt(1)) self.test_exit() def test_basic_glob(self): self.sendlines(['glob', '/*bin']) - self.expect('2\r\n(/bin\r\n/sbin|/sbin\r\n/bin)\r\n#1#\r\n') + self.expect('2\r\n(/bin\r\n/sbin|/sbin\r\n/bin)\r\n'+self.prompt(1)) self.test_exit() def test_empty_glob(self): self.sendlines(['glob', '/?kyzh?']) - self.expect('0\r\n#1#\r\n') + self.expect('0\r\n'+self.prompt(1)) self.test_exit() def test_increasing_counter(self): for req_counter in range(1, 5): self.sendlines(['noop']) - self.expect('#%i#\r\n' % req_counter) + self.expect(self.prompt(req_counter)) for req_counter in range(5, 10): self.sendlines(['ping']) - self.expect('ALIVE\r\n#%i#\r\n' % req_counter) + self.expect('ALIVE\r\n'+self.prompt(req_counter)) self.test_exit() def test_queuecommands(self): self.worker.send('ping\n'*5) self.worker.send('exec\necho lol\n'*5) for req_counter in range(1,6): - self.lose_expect('ALIVE\r\n#%i#\r\n' % req_counter) + self.lose_expect('ALIVE\r\n'+self.prompt(req_counter)) for req_counter in range(6,11): - self.lose_expect('0\r\n4\r\nlol\r\n\r\n0\r\n\r\n#%i#\r\n' % req_counter) + self.lose_expect(self.__exec_echo_lol_output__+self.prompt(req_counter)) self.test_exit() if __name__ == '__main__': -- cgit