Skip to content

Commit 6921fa2

Browse files
author
Dan
committed
Added new output class tests. Added backwards compatibility test with old output format. Updated copyright notice
1 parent 1af2b32 commit 6921fa2

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@
278278
epub_title = u'Parallel-SSH'
279279
epub_author = u'P Kittenis'
280280
epub_publisher = u'P Kittenis'
281-
epub_copyright = u'2015, P Kittenis'
281+
epub_copyright = u'2017, P Kittenis'
282282

283283
# The basename for the epub file. It defaults to the project name.
284284
#epub_basename = u'Parallel-SSH'

tests/test_output.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python
2+
3+
# This file is part of parallel-ssh.
4+
5+
# Copyright (C) 2015- Panos Kittenis
6+
7+
# This library is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU Lesser General Public
9+
# License as published by the Free Software Foundation, version 2.1.
10+
11+
# This library 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 GNU
14+
# Lesser General Public License for more details.
15+
16+
# You should have received a copy of the GNU Lesser General Public
17+
# License along with this library; if not, write to the Free Software
18+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+
20+
21+
"""Unittests for :mod:`pssh.output.HostOutput` class"""
22+
23+
24+
import unittest
25+
from pssh.output import HostOutput
26+
27+
28+
class TestHostOutput(unittest.TestCase):
29+
30+
def setUp(self):
31+
self.output = HostOutput(None, None, None, None, None, None)
32+
33+
def test_update(self):
34+
host, cmd, chan, stdout, stderr, \
35+
stdin, exit_code, exception = 'host', 'cmd', 'chan', 'stdout', \
36+
'stderr', 'stdin', 1, Exception()
37+
self.output.update({'host': host,
38+
'cmd': cmd,
39+
'channel': chan,
40+
'stdout': stdout,
41+
'stderr': stderr,
42+
'stdin': stdin,
43+
'exit_code': exit_code,
44+
'exception': exception})
45+
self.assertEqual(host, self.output.host)
46+
self.assertEqual(self.output.host, self.output['host'])
47+
self.assertEqual(cmd, self.output.cmd)
48+
self.assertEqual(self.output.cmd, self.output['cmd'])
49+
self.assertEqual(chan, self.output.channel)
50+
self.assertEqual(self.output.channel, self.output['channel'])
51+
self.assertEqual(stdout, self.output.stdout)
52+
self.assertEqual(self.output.stdout, self.output['stdout'])
53+
self.assertEqual(stderr, self.output.stderr)
54+
self.assertEqual(self.output.stderr, self.output['stderr'])
55+
self.assertEqual(stdin, self.output.stdin)
56+
self.assertEqual(self.output.stdin, self.output['stdin'])
57+
self.assertEqual(exit_code, self.output.exit_code)
58+
self.assertEqual(self.output.exit_code, self.output['exit_code'])
59+
self.assertEqual(exception, self.output.exception)
60+
self.assertEqual(self.output.exception, self.output['exception'])

tests/test_pssh_client.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,5 +948,33 @@ def test_channel_timeout(self):
948948
output = self.client.run_command(cmd)
949949
self.assertRaises(socket_timeout, list, output[self.host]['stdout'])
950950

951+
def test_output_attributes(self):
952+
output = self.client.run_command(self.fake_cmd)
953+
expected_exit_code = 0
954+
expected_stdout = [self.fake_resp]
955+
expected_stderr = []
956+
self.client.join(output)
957+
exit_code = output[self.host]['exit_code']
958+
stdout = list(output[self.host]['stdout'])
959+
stderr = list(output[self.host]['stderr'])
960+
host_output = output[self.host]
961+
self.assertEqual(expected_exit_code, host_output.exit_code)
962+
self.assertEqual(expected_exit_code, host_output['exit_code'])
963+
self.assertEqual(host_output['cmd'], host_output.cmd)
964+
self.assertEqual(host_output['exception'], host_output.exception)
965+
self.assertEqual(host_output['stdout'], host_output.stdout)
966+
self.assertEqual(host_output['stderr'], host_output.stderr)
967+
self.assertEqual(host_output['stdin'], host_output.stdin)
968+
self.assertEqual(host_output['channel'], host_output.channel)
969+
self.assertEqual(host_output['host'], host_output.host)
970+
self.assertTrue(hasattr(output[self.host], 'host'))
971+
self.assertTrue(hasattr(output[self.host], 'cmd'))
972+
self.assertTrue(hasattr(output[self.host], 'channel'))
973+
self.assertTrue(hasattr(output[self.host], 'stdout'))
974+
self.assertTrue(hasattr(output[self.host], 'stderr'))
975+
self.assertTrue(hasattr(output[self.host], 'stdin'))
976+
self.assertTrue(hasattr(output[self.host], 'exception'))
977+
self.assertTrue(hasattr(output[self.host], 'exit_code'))
978+
951979
if __name__ == '__main__':
952980
unittest.main()

0 commit comments

Comments
 (0)