"Fossies" - the Fresh Open Source Software Archive

Member "polysh-polysh-0.13/tests/tests/host_syntax.py" (11 May 2020, 3131 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. For more information about "host_syntax.py" see the Fossies "Dox" file reference documentation.

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