"Fossies" - the Fresh Open Source Software Archive 
Member "polysh-polysh-0.13/tests/tests/command_line.py" (11 May 2020, 3488 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 - Command Line
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 import os
22
23 from polysh_tests import launch_polysh
24
25
26 class TestCommandLine(unittest.TestCase):
27 def testGoodHostsFilename(self):
28 tmp_name = '/tmp/polysh_tests.%d' % (os.getpid())
29 tmp = open(tmp_name, 'w', 0o600)
30 print('localhost # Comment', file=tmp)
31 print('# Ignore me', file=tmp)
32 print('127.0.0.1', file=tmp)
33 tmp.close()
34 child = launch_polysh(['--hosts-file=%s' % (tmp_name)])
35 child.expect('ready \(2\)> ')
36 child.sendeof()
37 child.expect(pexpect.EOF)
38 os.remove(tmp_name)
39
40 def testBadHostsFilename(self):
41 child = launch_polysh(['--hosts-file=do not exist/at all'])
42 child.expect('error')
43 child.expect(pexpect.EOF)
44
45 def testNoHosts(self):
46 child = launch_polysh([])
47 child.expect('error: no hosts given')
48 child.expect(pexpect.EOF)
49 child = launch_polysh(['--hosts-file=/dev/null'])
50 child.expect('error: no hosts given')
51 child.expect(pexpect.EOF)
52
53 def testProfile(self):
54 child = launch_polysh(['--profile', 'localhost'])
55 child.expect('Profiling using ')
56 child.expect('ready \(1\)> ')
57 child.sendline(':quit')
58 child.expect(' function calls in ')
59 child.expect('Ordered by')
60 child.expect(pexpect.EOF)
61
62 def testInitError(self):
63 child = launch_polysh(['--ssh=echo message', 'localhost'])
64 child.expect('message localhost')
65 child.expect(pexpect.EOF)
66 child = launch_polysh(['--ssh=echo The authenticity of host', 'l'])
67 child.expect('Closing connection')
68 child.expect('Consider manually connecting or using ssh-keyscan')
69 child.expect(pexpect.EOF)
70 child = launch_polysh(['--ssh=echo REMOTE HOST IDENTIFICATION '
71 'HAS CHANGED', 'l'])
72 child.expect('Remote host identification has changed')
73 child.expect('Consider manually connecting or using ssh-keyscan')
74 child.expect(pexpect.EOF)
75
76 def testAbortError(self):
77 child = launch_polysh(['localhost', 'unknown_host'])
78 child.expect('Error talking to unknown_host')
79 child.sendline(':quit')
80 child.expect(pexpect.EOF)
81 child = launch_polysh(['--abort-errors', 'localhost', 'unknown_host'])
82 child.expect('Error talking to unknown_host')
83 child.expect(pexpect.EOF)
84
85 def testUser(self):
86 child = launch_polysh(['--ssh=echo', 'machine'])
87 child.expect('[^@]machine')
88 child.expect(pexpect.EOF)
89 child = launch_polysh(['--ssh=echo', '--user=login', 'machine'])
90 child.expect('login@machine')
91 child.expect(pexpect.EOF)