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 Guillaume Chazarain <guichaz@gmail.com>
21 from gsh_tests
import launch_gsh
23 class TestHostSyntax(unittest
.TestCase
):
24 def assertHostSyntax(self
, to_expand
, expanded
):
25 child
= launch_gsh([to_expand
, 'localhost'])
27 child
.sendline(':list')
28 with_spaces
= [e
.replace('.', '\\.') + ' ' for e
in expanded
]
29 for i
in xrange(len(expanded
)):
30 found
= child
.expect(with_spaces
)
31 del with_spaces
[found
]
34 child
.expect(pexpect
.EOF
)
36 def testHostSyntax(self
):
37 self
.assertHostSyntax('0.0.0.<0-10>',
38 ['0.0.0.0', '0.0.0.1', '0.0.0.2', '0.0.0.3',
39 '0.0.0.4', '0.0.0.5', '0.0.0.6', '0.0.0.7',
40 '0.0.0.8', '0.0.0.9', '0.0.0.10'])
41 self
.assertHostSyntax('0.0.0.<00-10>',
42 ['0.0.0.00', '0.0.0.01', '0.0.0.02', '0.0.0.03',
43 '0.0.0.04', '0.0.0.05', '0.0.0.06', '0.0.0.07',
44 '0.0.0.08', '0.0.0.09', '0.0.0.10'])
45 self
.assertHostSyntax('0.0.0.<1-10>',
46 ['0.0.0.1', '0.0.0.2', '0.0.0.3', '0.0.0.4',
47 '0.0.0.5', '0.0.0.6', '0.0.0.7', '0.0.0.8',
48 '0.0.0.9', '0.0.0.10'])
49 self
.assertHostSyntax('0.0.0.<10-1>',
50 ['0.0.0.1', '0.0.0.2', '0.0.0.3', '0.0.0.4',
51 '0.0.0.5', '0.0.0.6', '0.0.0.7', '0.0.0.8',
52 '0.0.0.9', '0.0.0.10'])
53 self
.assertHostSyntax('0.0.0.<01-10>',
54 ['0.0.0.01', '0.0.0.02', '0.0.0.03', '0.0.0.04',
55 '0.0.0.05', '0.0.0.06', '0.0.0.07', '0.0.0.08',
56 '0.0.0.09', '0.0.0.10'])
57 self
.assertHostSyntax('0.0.<1-4>.<01-03>',
58 ['0.0.1.01', '0.0.1.02', '0.0.1.03', '0.0.2.01',
59 '0.0.2.02', '0.0.2.03', '0.0.3.01', '0.0.3.02',
60 '0.0.3.03', '0.0.4.01', '0.0.4.02', '0.0.4.03'])
61 self
.assertHostSyntax('0.0.0.<1>', ['0.0.0.1'])
62 self
.assertHostSyntax('0.0.0.<1,3-5>',
63 ['0.0.0.1', '0.0.0.3', '0.0.0.4', '0.0.0.5'])