Skip to content

Commit

Permalink
Added new output class tests. Added backwards compatibility test with…
Browse files Browse the repository at this point in the history
… old output format. Updated copyright notice
  • Loading branch information
pkittenis committed Jan 26, 2017
1 parent 1af2b32 commit 6921fa2
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/conf.py
Expand Up @@ -278,7 +278,7 @@
epub_title = u'Parallel-SSH'
epub_author = u'P Kittenis'
epub_publisher = u'P Kittenis'
epub_copyright = u'2015, P Kittenis'
epub_copyright = u'2017, P Kittenis'

# The basename for the epub file. It defaults to the project name.
#epub_basename = u'Parallel-SSH'
Expand Down
60 changes: 60 additions & 0 deletions tests/test_output.py
@@ -0,0 +1,60 @@
#!/usr/bin/env python

# This file is part of parallel-ssh.

# Copyright (C) 2015- Panos Kittenis

# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation, version 2.1.

# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA


"""Unittests for :mod:`pssh.output.HostOutput` class"""


import unittest
from pssh.output import HostOutput


class TestHostOutput(unittest.TestCase):

def setUp(self):
self.output = HostOutput(None, None, None, None, None, None)

def test_update(self):
host, cmd, chan, stdout, stderr, \
stdin, exit_code, exception = 'host', 'cmd', 'chan', 'stdout', \
'stderr', 'stdin', 1, Exception()
self.output.update({'host': host,
'cmd': cmd,
'channel': chan,
'stdout': stdout,
'stderr': stderr,
'stdin': stdin,
'exit_code': exit_code,
'exception': exception})
self.assertEqual(host, self.output.host)
self.assertEqual(self.output.host, self.output['host'])
self.assertEqual(cmd, self.output.cmd)
self.assertEqual(self.output.cmd, self.output['cmd'])
self.assertEqual(chan, self.output.channel)
self.assertEqual(self.output.channel, self.output['channel'])
self.assertEqual(stdout, self.output.stdout)
self.assertEqual(self.output.stdout, self.output['stdout'])
self.assertEqual(stderr, self.output.stderr)
self.assertEqual(self.output.stderr, self.output['stderr'])
self.assertEqual(stdin, self.output.stdin)
self.assertEqual(self.output.stdin, self.output['stdin'])
self.assertEqual(exit_code, self.output.exit_code)
self.assertEqual(self.output.exit_code, self.output['exit_code'])
self.assertEqual(exception, self.output.exception)
self.assertEqual(self.output.exception, self.output['exception'])
28 changes: 28 additions & 0 deletions tests/test_pssh_client.py
Expand Up @@ -948,5 +948,33 @@ def test_channel_timeout(self):
output = self.client.run_command(cmd)
self.assertRaises(socket_timeout, list, output[self.host]['stdout'])

def test_output_attributes(self):
output = self.client.run_command(self.fake_cmd)
expected_exit_code = 0
expected_stdout = [self.fake_resp]
expected_stderr = []
self.client.join(output)
exit_code = output[self.host]['exit_code']
stdout = list(output[self.host]['stdout'])
stderr = list(output[self.host]['stderr'])
host_output = output[self.host]
self.assertEqual(expected_exit_code, host_output.exit_code)
self.assertEqual(expected_exit_code, host_output['exit_code'])
self.assertEqual(host_output['cmd'], host_output.cmd)
self.assertEqual(host_output['exception'], host_output.exception)
self.assertEqual(host_output['stdout'], host_output.stdout)
self.assertEqual(host_output['stderr'], host_output.stderr)
self.assertEqual(host_output['stdin'], host_output.stdin)
self.assertEqual(host_output['channel'], host_output.channel)
self.assertEqual(host_output['host'], host_output.host)
self.assertTrue(hasattr(output[self.host], 'host'))
self.assertTrue(hasattr(output[self.host], 'cmd'))
self.assertTrue(hasattr(output[self.host], 'channel'))
self.assertTrue(hasattr(output[self.host], 'stdout'))
self.assertTrue(hasattr(output[self.host], 'stderr'))
self.assertTrue(hasattr(output[self.host], 'stdin'))
self.assertTrue(hasattr(output[self.host], 'exception'))
self.assertTrue(hasattr(output[self.host], 'exit_code'))

if __name__ == '__main__':
unittest.main()

0 comments on commit 6921fa2

Please sign in to comment.