summaryrefslogtreecommitdiff
path: root/tests/test_buffered_pipe.py
diff options
context:
space:
mode:
authorRobey Pointer <robey@lag.net>2006-04-11 00:39:46 -0700
committerRobey Pointer <robey@lag.net>2006-04-11 00:39:46 -0700
commit9e14a3bf58ed62ab61df7f5932648bf973a83bf8 (patch)
tree1d8aee25e92f779ca2cb40a0272671dba1672bd8 /tests/test_buffered_pipe.py
parent017d315bcece55c6db74585b31a62f767570a064 (diff)
downloadparamiko-9e14a3bf58ed62ab61df7f5932648bf973a83bf8.tar.gz
[project @ robey@lag.net-20060411073946-8830b560b276266f]
factor out BufferedPipe into its own class
Diffstat (limited to 'tests/test_buffered_pipe.py')
-rw-r--r--tests/test_buffered_pipe.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/test_buffered_pipe.py b/tests/test_buffered_pipe.py
new file mode 100644
index 00000000..8e4a4282
--- /dev/null
+++ b/tests/test_buffered_pipe.py
@@ -0,0 +1,71 @@
+# Copyright (C) 2006 Robey Pointer <robey@lag.net>
+#
+# This file is part of paramiko.
+#
+# Paramiko 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; either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# Paramiko is distrubuted 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 Paramiko; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+"""
+Some unit tests for BufferedPipe.
+"""
+
+import threading
+import time
+import unittest
+from paramiko.buffered_pipe import BufferedPipe, PipeTimeout
+
+
+def delay_thread(pipe):
+ pipe.feed('a')
+ time.sleep(0.5)
+ pipe.feed('b')
+ pipe.close()
+
+
+def close_thread(pipe):
+ time.sleep(0.2)
+ pipe.close()
+
+
+class BufferedPipeTest (unittest.TestCase):
+
+ def test_1_buffered_pipe(self):
+ p = BufferedPipe()
+ self.assert_(not p.read_ready())
+ p.feed('hello.')
+ self.assert_(p.read_ready())
+ data = p.read(6)
+ self.assertEquals('hello.', data)
+ p.close()
+ self.assert_(not p.read_ready())
+ self.assertEquals('', p.read(1))
+
+ def test_2_delay(self):
+ p = BufferedPipe()
+ self.assert_(not p.read_ready())
+ threading.Thread(target=delay_thread, args=(p,)).start()
+ self.assertEquals('a', p.read(1, 0.1))
+ try:
+ p.read(1, 0.1)
+ self.assert_(False)
+ except PipeTimeout:
+ pass
+ self.assertEquals('b', p.read(1, 0.5))
+ self.assertEquals('', p.read(1))
+
+ def test_3_close_while_reading(self):
+ p = BufferedPipe()
+ threading.Thread(target=close_thread, args=(p,)).start()
+ data = p.read(1, 1.0)
+ self.assertEquals('', data)