[Zodb-checkins] CVS: ZODB3/zdaemon/tests - testzdaemon.py:1.5

Guido van Rossum guido@python.org
Wed, 13 Nov 2002 17:39:38 -0500


Update of /cvs-repository/ZODB3/zdaemon/tests
In directory cvs.zope.org:/tmp/cvs-serv17286/tests

Modified Files:
	testzdaemon.py 
Log Message:
More refactoring:
- create a subprocess management class
- turned logging methods into functions a la PEP 282
- turned a bunch of stateless helper functions into functions


=== ZODB3/zdaemon/tests/testzdaemon.py 1.4 => 1.5 ===
--- ZODB3/zdaemon/tests/testzdaemon.py:1.4	Wed Nov 13 16:33:37 2002
+++ ZODB3/zdaemon/tests/testzdaemon.py	Wed Nov 13 17:39:38 2002
@@ -52,8 +52,8 @@
                (self.ppath, self.python, self.zdaemon, self.zdsock, args))
         os.system(cmd)
         # When the daemon crashes, the following may help debug it:
-        ##os.system("%s %s -s %s %s &" %
-        ##          (self.python, self.zdaemon, self.zdsock, args))
+        ##os.system("PYTHONPATH=%s %s %s -s %s %s &" %
+        ##          (self.ppath, self.python, self.zdaemon, self.zdsock, args))
 
     def run(self, args):
         if type(args) is type(""):
@@ -135,6 +135,22 @@
                 self.fail("SystemExit expected")
         finally:
             sys.stderr = save_sys_stderr
+
+    def testSubprocessBasic(self):
+        # Check basic subprocess management: spawn, kill, wait
+        opts = zdaemon.Options([])
+        proc = zdaemon.Subprocess(opts, ["sleep", "100"])
+        self.assertEqual(proc.pid, 0)
+        pid = proc.spawn()
+        self.assertEqual(proc.pid, pid)
+        msg = proc.kill(signal.SIGTERM)
+        self.assertEqual(msg, None)
+        wpid, wsts = os.waitpid(pid, 0)
+        self.assertEqual(wpid, pid)
+        self.assertEqual(os.WIFSIGNALED(wsts), 1)
+        self.assertEqual(os.WTERMSIG(wsts), signal.SIGTERM)
+        proc.setstatus(wsts)
+        self.assertEqual(proc.pid, 0)
 
 def test_suite():
     suite = unittest.TestSuite()