From 2e2ae7474fbed041f9b0f2c6a04940e656c07788 Mon Sep 17 00:00:00 2001
From: Per Cederqvist <ceder@lysator.liu.se>
Date: Sat, 12 Mar 2005 22:47:30 +0000
Subject: [PATCH] Import test.base instead of importing unittest.  Removed
 top-level code -- use testdriver.py to run the tests instead. (TestPopen):
 Inherit from test.base.TestCase. (Timeout): Moved to test/base.py. (handler):
 Ditto. (TestPopen.setUp): Moved to test.base.TestCase. (TestPopen.tearDown):
 Ditto. (TestPopen.test_popen_sleep_1): Use assertTimeDiff instead of 
 assertAlmostEqual. (TestPopen.test_popen_sleep_1_compat): Ditto.
 (TestPopen.test_read_hello_no_eof_handling): New test.
 (TestPopen.test_read_hello_no_eof_handling_no_exception): New test.

---
 test/test_popen.py | 60 +++++++++++++++++++++++++++++-----------------
 1 file changed, 38 insertions(+), 22 deletions(-)

diff --git a/test/test_popen.py b/test/test_popen.py
index 28bb8e8..53d9a9f 100644
--- a/test/test_popen.py
+++ b/test/test_popen.py
@@ -1,25 +1,12 @@
-#!/usr/bin/env python
-import unittest
-
 import time
-import signal
 
+import pcl_expect
 from pcl_expect import Controller
 from pcl_expect.popen import Popen
 
-class Timeout(Exception): pass
-
-def handler(signo, stk):
-    raise Timeout()
-
-class TestPopen(unittest.TestCase):
-    def setUp(self):
-        signal.signal(signal.SIGALRM, handler)
-        signal.alarm(20)
-
-    def tearDown(self):
-        signal.alarm(0)
+import test.base
 
+class TestPopen(test.base.TestCase):
     def test_popen_sleep_1(self):
         t0 = time.time()
         sleeper = Popen('sleep 1')
@@ -34,8 +21,8 @@ class TestPopen(unittest.TestCase):
         status = sleeper.close()
         self.assertEqual(status, None)
         t1 = time.time()
-        self.assertAlmostEqual(t0 + 1.0, t1, 1,
-                               'sleep 1 slept too long or too short')
+        self.assertTimeDiff(t0, t1, 1.0)
+
     def test_popen_sleep_1_compat(self):
         t0 = time.time()
         sleeper = Popen('sleep 1')
@@ -50,8 +37,7 @@ class TestPopen(unittest.TestCase):
         status = sleeper.close()
         self.assertEqual(status, None)
         t1 = time.time()
-        self.assertAlmostEqual(t0 + 1.0, t1, 1,
-                               'sleep 1 slept too long or too short')
+        self.assertTimeDiff(t0, t1, 1.0)
 
     def test_read_hello(self):
         hello = Popen('echo hello, world')
@@ -100,5 +86,35 @@ class TestPopen(unittest.TestCase):
         status = hello.close()
         self.assertEqual(status, None)
 
-if __name__ == '__main__':
-    unittest.main()
+    def test_read_hello_no_eof_handling(self):
+        hello = Popen('echo hello, world')
+        seen = False
+        x = Controller()
+        try:
+            while x.loop():
+                if hello.re(x, 'hello, world\n'):
+                    if seen:
+                        self.fail("got hello twice")
+                    seen = 1
+            self.fail('no exception raised')
+        except pcl_expect.UnhandledEof:
+            pass
+        status = hello.close()
+        self.assertEqual(status, None)
+        self.assertEqual(seen, 1)
+
+    def test_read_hello_no_eof_handling_no_exception(self):
+        hello = Popen('echo hello, world')
+        seen = False
+        env = pcl_expect.Environment()
+        env.set_eof_raises_exception(False)
+        x = env.controller()
+        while x.loop():
+            if hello.re(x, 'hello, world\n'):
+                if seen:
+                    self.fail("got hello twice")
+                seen = 1
+        status = hello.close()
+        self.assertEqual(status, None)
+        self.assertEqual(seen, 1)
+
-- 
GitLab