"Fossies" - the Fresh Open Source Software Archive 
Member "polysh-polysh-0.13/tests/tests/non_interactive.py" (11 May 2020, 2730 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 - Non-interactive Mode
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 TestNonInteractive(unittest.TestCase):
25 def testCommandNormal(self):
26 child = launch_polysh(['--command=echo text', 'localhost'])
27 child.expect('\033\[1;36mlocalhost : \033\[1;mtext')
28 child.expect(pexpect.EOF)
29
30 def testCommandIntr(self):
31 child = launch_polysh(['--command=echo text; cat', 'localhost'])
32 child.expect('\033\[1;36mlocalhost : \033\[1;mtext')
33 child.sendintr()
34 child.expect(pexpect.EOF)
35
36 def testSimpleCommandStdin(self):
37 child = launch_polysh(['localhost'], input_data='echo line')
38 child.expect('localhost : line')
39 child.expect(pexpect.EOF)
40
41 def testMultipleCommandStdin(self):
42 commands = """
43 echo first
44 echo next
45 echo last
46 """
47 child = launch_polysh(['localhost'], input_data=commands)
48 child.expect('localhost : first')
49 child.expect('localhost : next')
50 child.expect('localhost : last')
51 child.expect(pexpect.EOF)
52
53 def testInvalidCommandStdin(self):
54 child = launch_polysh(
55 ['localhost', '--command=date'], input_data='uptime')
56 child.expect('--command and reading from stdin are incompatible')
57 child.expect(pexpect.EOF)
58
59 def testExitCode(self):
60 def CommandCode(command, code):
61 child = launch_polysh(
62 ['--command=%s' % command] + ['localhost'] * 5)
63 child.expect(pexpect.EOF)
64 while child.isalive():
65 child.wait()
66 self.assertEqual(child.exitstatus, code)
67 CommandCode('true', 0)
68 CommandCode('false', 1)
69
70 def testInvalidCharacters(self):
71 child = launch_polysh(
72 ["--command=printf '%b' '\xacfoo\u2018bar\n'", 'localhost'])
73 child.expect('\033\[1;36mlocalhost : \033\[1;m\xacfoo\u2018bar')
74 child.expect(pexpect.EOF)