[Python-modules-commits] [python-spur] 01/04: Add tests for reading int lines from file-like obj
Ruben Undheim
rubund-guest at moszumanska.debian.org
Mon May 25 11:21:24 UTC 2015
This is an automated email from the git hooks/post-receive script.
rubund-guest pushed a commit to branch upstream
in repository python-spur.
commit 34fa749658e9d2797f449c7ffe24e15318bd1cc1
Author: Michael Williamson <mike at zwobble.org>
Date: Sun May 3 13:56:48 2015 +0100
Add tests for reading int lines from file-like obj
---
spur/ssh.py | 6 +++---
tests/ssh_tests.py | 19 +++++++++++++++++++
2 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/spur/ssh.py b/spur/ssh.py
index 6f1b31c..4d07fd0 100644
--- a/spur/ssh.py
+++ b/spur/ssh.py
@@ -175,10 +175,10 @@ class SshShell(object):
process_stdout = channel.makefile('rb')
if store_pid:
- pid = _read_int_line(process_stdout)
+ pid = _read_int_initialization_line(process_stdout)
if self._shell_type.supports_which:
- which_return_code = _read_int_line(process_stdout)
+ which_return_code = _read_int_initialization_line(process_stdout)
if which_return_code != 0:
raise NoSuchCommandError(command[0])
@@ -284,7 +284,7 @@ class SshShell(object):
return connection_error
-def _read_int_line(output_file):
+def _read_int_initialization_line(output_file):
while True:
line = output_file.readline().strip()
if line:
diff --git a/tests/ssh_tests.py b/tests/ssh_tests.py
index a9fcebb..9ae252b 100644
--- a/tests/ssh_tests.py
+++ b/tests/ssh_tests.py
@@ -1,3 +1,7 @@
+from __future__ import unicode_literals
+
+import io
+
from nose.tools import istest, assert_raises, assert_equal
import spur
@@ -149,3 +153,18 @@ class MinimalSshProcessTests(ProcessTestSet, MinimalSshTestMixin):
except spur.ssh.UnsupportedArgumentError as error:
assert_equal("'{0}' is not supported when using a minimal shell".format(name), str(error))
+
+
+ at istest
+class ReadInitializationLineTests(object):
+ @istest
+ def reading_initialization_line_returns_int_from_line_of_file(self):
+ assert_equal(42, spur.ssh._read_int_initialization_line(io.StringIO("42\n")))
+
+ @istest
+ def blank_lines_are_skipped(self):
+ assert_equal(42, spur.ssh._read_int_initialization_line(io.StringIO("\n \n\t\t\n42\n")))
+
+ @istest
+ def error_if_non_blank_line_is_not_integer(self):
+ assert_raises(ValueError, lambda: spur.ssh._read_int_initialization_line(io.StringIO("x\n")))
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-spur.git
More information about the Python-modules-commits
mailing list