"Fossies" - the Fresh Open Source Software Archive 
Member "polysh-polysh-0.13/tests/tests/basic.py" (11 May 2020, 2903 Bytes) of package /linux/privat/polysh-polysh-0.13.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
1 """Polysh - Tests - Basics
2
3 Copyright (c) 2006 Guillaume Chazarain <guichaz@gmail.com>
4 Copyright (c) 2018 InnoGames GmbH
5 """
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 import unittest
20 import pexpect
21 from polysh_tests import launch_polysh
22 from time import sleep
23
24
25 class TestBasic(unittest.TestCase):
26 def localhost(self, nr_localhost):
27 args = nr_localhost * ['localhost']
28
29 def start_child():
30 child = launch_polysh(args)
31 child.expect('ready \(%d\)> ' % (nr_localhost))
32 return child
33
34 def test_eof():
35 child = start_child()
36 child.sendeof()
37 child.expect(pexpect.EOF)
38
39 def test_exit():
40 child = start_child()
41 child.sendline('exit')
42 for i in range(nr_localhost):
43 child.expect('logout')
44 child.expect(pexpect.EOF)
45
46 test_eof()
47 test_exit()
48
49 def testLocalhost(self):
50 self.localhost(1)
51
52 def testLocalhostLocalhost(self):
53 self.localhost(2)
54
55 def testLocalhostLocalhostLocalhost(self):
56 self.localhost(3)
57
58 def testPrependPrompt(self):
59 child = launch_polysh(['localhost'])
60 child.expect('ready \(1\)> ')
61 child.sendline('sleep 1')
62 child.expect('waiting \(1/1\)> ')
63 sleep(1)
64 child.send('echo begin-')
65 child.expect('ready \(1\)> ')
66 child.sendline('end')
67 child.expect('begin-end')
68 child.expect('ready \(1\)> ')
69 child.sendeof()
70 child.expect(pexpect.EOF)
71
72 def testError(self):
73 child = launch_polysh(['localhost', 'localhost'])
74 child.expect('ready \(2\)> ')
75 child.sendline('kill -9 $$')
76 child.expect('Error talking to localhost')
77 child.expect('Error talking to localhost')
78 child.expect(pexpect.EOF)
79
80 def testCleanExit(self):
81 child = launch_polysh(['localhost', 'localhost'])
82 child.expect('ready \(2\)> ')
83 child.sendeof()
84 # We test for logout as this is the expected response of sending EOF to
85 # a non login shell
86 idx = child.expect(['Error talking to localhost', 'logout'])
87 self.assertEqual(idx, 1)
88 idx = child.expect(['Error talking to localhost', pexpect.EOF])
89 self.assertEqual(idx, 1)