Commits

Jason R. Coombs committed 47e3139

Extracted method for skipping when the necessary signal and kill method aren't present.

Comments (0)

Files changed (1)

cherrypy/test/test_states.py

 import os
 import sys
 import time
+import signal
 
 import cherrypy
 engine = cherrypy.engine
             self.getPage("/exit")
         p.join()
 
+    def _require_signal_and_kill(self, signal_name):
+        if not hasattr(signal, signal_name):
+            self.skip("skipped (no %(signal_name)s)" % vars())
+
+        if not hasattr(os, 'kill'):
+            self.skip("skipped (no os.kill)")
+
     def test_SIGTERM(self):
-        # SIGTERM should shut down the server whether daemonized or not.
-        try:
-            from signal import SIGTERM
-        except ImportError:
-            return self.skip("skipped (no SIGTERM) ")
-
-        try:
-            from os import kill
-        except ImportError:
-            return self.skip("skipped (no os.kill) ")
+        "SIGTERM should shut down the server whether daemonized or not."
+        self._require_signal_and_kill('SIGTERM')
 
         # Spawn a normal, undaemonized process.
         p = helper.CPProcess(ssl=(self.scheme.lower()=='https'))
                 extra='test_case_name: "test_SIGTERM"')
         p.start(imports='cherrypy.test._test_states_demo')
         # Send a SIGTERM
-        os.kill(p.get_pid(), SIGTERM)
+        os.kill(p.get_pid(), signal.SIGTERM)
         # This might hang if things aren't working right, but meh.
         p.join()
 
                  extra='test_case_name: "test_SIGTERM_2"')
             p.start(imports='cherrypy.test._test_states_demo')
             # Send a SIGTERM
-            os.kill(p.get_pid(), SIGTERM)
+            os.kill(p.get_pid(), signal.SIGTERM)
             # This might hang if things aren't working right, but meh.
             p.join()
 
     def test_signal_handler_unsubscribe(self):
-        try:
-            from signal import SIGTERM
-        except ImportError:
-            return self.skip("skipped (no SIGTERM) ")
-
-        try:
-            from os import kill
-        except ImportError:
-            return self.skip("skipped (no os.kill) ")
+        self._require_signal_and_kill('SIGTERM')
 
         # Spawn a normal, undaemonized process.
         p = helper.CPProcess(ssl=(self.scheme.lower()=='https'))
 """)
         p.start(imports='cherrypy.test._test_states_demo')
         # Send a SIGTERM
-        os.kill(p.get_pid(), SIGTERM)
+        os.kill(p.get_pid(), signal.SIGTERM)
         # This might hang if things aren't working right, but meh.
         p.join()
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.