Added a --user option to specify the remote user to login as.
[gsh.git] / tests / tests / command_line.py
blobf83cd9a4bfc8d57109f5c33d84f4da3262cb6ba3
1 # This program is free software; you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation; either version 2 of the License, or
4 # (at your option) any later version.
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU Library General Public License for more details.
11 # You should have received a copy of the GNU General Public License
12 # along with this program; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 # See the COPYING file for license information.
17 # Copyright (c) 2007, 2008 Guillaume Chazarain <guichaz@gmail.com>
19 import unittest
20 import pexpect
21 import os
23 from gsh_tests import launch_gsh
25 class TestCommandLine(unittest.TestCase):
26 def testGoodHostsFilename(self):
27 tmp_name = '/tmp/gsh_tests.%d' % (os.getpid())
28 tmp = open(tmp_name, 'w', 0600)
29 print >> tmp, 'localhost # Comment'
30 print >> tmp, '127.0.0.1'
31 print >> tmp, '# Ignore me'
32 print >> tmp, 'localhost.'
33 tmp.close()
34 child = launch_gsh(['--hosts-file=%s' % (tmp_name)])
35 child.expect('ready \(3\)> ')
36 child.sendeof()
37 child.expect(pexpect.EOF)
38 os.remove(tmp_name)
40 def testBadHostsFilename(self):
41 child = launch_gsh(['--hosts-file=do not exist/at all'])
42 child.expect('error')
43 child.expect(pexpect.EOF)
45 def testNoHosts(self):
46 child = launch_gsh([])
47 child.expect('error: no hosts given')
48 child.expect(pexpect.EOF)
49 child = launch_gsh(['--hosts-file=/dev/null'])
50 child.expect('error: no hosts given')
51 child.expect(pexpect.EOF)
53 def testProfile(self):
54 child = launch_gsh(['--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)
62 def testInitError(self):
63 child = launch_gsh(['--ssh=echo message', 'localhost'])
64 child.expect('message localhost')
65 child.expect(pexpect.EOF)
66 child = launch_gsh(['--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_gsh(['--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)
76 def testAbortError(self):
77 child = launch_gsh(['localhost', 'unknown_host'])
78 child.expect('Error talking to unknown_host')
79 child.sendline(':quit')
80 child.expect(pexpect.EOF)
81 child = launch_gsh(['--abort-errors', 'localhost', 'unknown_host'])
82 child.expect('Error talking to unknown_host')
83 child.expect(pexpect.EOF)
85 def testUser(self):
86 child = launch_gsh(['--ssh=echo', 'machine'])
87 child.expect('[^@]machine')
88 child.expect(pexpect.EOF)
89 child = launch_gsh(['--ssh=echo', '--user=login', 'machine'])
90 child.expect('login@machine')
91 child.expect(pexpect.EOF)