Robert Brewer avatar Robert Brewer committed 2900659

Initial fix for #333.

Comments (0)

Files changed (4)

cherrypy/_cpserver.py

                 except SystemExit:
                     cherrypy.log("SystemExit raised: shutting down autoreloader", "HTTP")
                     self.stop()
+                    # We must raise here: if this is a process spawned by
+                    # autoreload, then it must return its error code to
+                    # the parent.
                     raise
                 return
         

cherrypy/test/test.py

         self.profile = False
         self.protocol = "HTTP/1.0"
         self.basedir = None
+        self.PORT = 8000
         
         self.servers = []
         self.tests = []
             set of args if you like.
         """
         
-        longopts = ['cover', 'profile', '1.1', 'help', 'basedir=', 'all']
+        longopts = ['cover', 'profile', '1.1', 'help',
+                    'basedir=', 'all', 'port=']
         longopts.extend(self.available_servers)
         longopts.extend(self.available_tests)
         try:
                 self.basedir = a
             elif o == "--all":
                 self.servers = self.available_servers.keys()
+            elif o == "--port":
+                self.PORT = int(a)
             else:
                 o = o[2:]
                 if o in self.available_servers and o not in self.servers:
         
         if conf is None:
             conf = {'server.socketHost': '127.0.0.1',
-                    'server.socketPort': 8000,
+                    'server.socketPort': self.PORT,
                     'server.threadPool': 10,
                     'server.logToScreen': False,
                     'server.environment': "production",
     def _run_all_servers(self, conf):
         # helper must be imported lazily so the coverage tool
         # can run against module-level statements within cherrypy.
-        from cherrypy.test import helper
+        # Also, we have to do a relative import here, not
+        # "from cherrypy.test import helper", because the latter
+        # would stick a second instance of webtest in sys.modules,
+        # and we wouldn't be able to globally override the port anymore.
+        import helper
         s = [self.available_servers[name] for name in self.servers]
         s.sort()
+        webtest.WebCase.PORT = self.PORT
         for priority, name, cls in s:
             print
             print "Running tests:", name
     def _run_all_servers(self, conf):
         # helper must be imported lazily so the coverage tool
         # can run against module-level statements within cherrypy.
-        from cherrypy.test import helper, test_states
+        # Also, we have to do a relative import here, not
+        # "from cherrypy.test import helper", because the latter
+        # would stick a second instance of webtest in sys.modules,
+        # and we wouldn't be able to globally override the port anymore.
+        import helper, test_states
         s = [self.available_servers[name] for name in self.servers]
         s.sort()
+        webtest.WebCase.PORT = self.PORT
         for priority, name, cls in s:
             print
             print "Running tests:", name

cherrypy/test/test_core.py

         hMap['content-type'] = "text/html"
         hMap['content-length'] = 18
         hMap['server'] = 'CherryPy headertest'
-        hMap['location'] = ('%s://127.0.0.1:8000/headers/'
-                            % cherrypy.request.scheme)
+        hMap['location'] = ('%s://127.0.0.1:%s/headers/'
+                            % (cherrypy.request.remotePort,
+                               cherrypy.request.scheme))
         
         # Set a rare header for fun
         hMap['Expires'] = 'Thu, 01 Dec 2194 16:00:00 GMT'
         
         self.getPage("/redirect?id=3")
         self.assert_(self.status in ('302 Found', '303 See Other'))
-        self.assertInBody("<a href='http://127.0.0.1:8000/redirect/?id=3'>"
-                          "http://127.0.0.1:8000/redirect/?id=3</a>")
+        self.assertInBody("<a href='http://127.0.0.1:%s/redirect/?id=3'>"
+                          "http://127.0.0.1:%s/redirect/?id=3</a>" %
+                          (self.PORT, self.PORT))
         
         self.getPage("/redirect/by_code?code=300")
         self.assertMatchesBody(r"<a href='(.*)somewhere else'>\1somewhere else</a>")

cherrypy/test/test_tutorials.py

 import sys
 
 import cherrypy
-from cherrypy.test import helper
+import helper
 
 
 class TutorialTest(helper.CPWebCase):
     def load_tut_module(self, tutorialName):
         """Import or reload tutorial module as needed."""
         cherrypy.config.reset()
+        
+        target = "cherrypy.tutorial." + tutorialName
+        if target in sys.modules:
+            module = reload(sys.modules[target])
+        else:
+            module = __import__(target, globals(), locals(), [''])
+        
         cherrypy.config.update({'server.socketHost': self.HOST,
                                 'server.socketPort': self.PORT,
                                 'server.threadPool': 10,
                                 'server.logToScreen': False,
                                 'server.environment': "production",
                                 })
-        
-        target = "cherrypy.tutorial." + tutorialName
-        if target in sys.modules:
-            module = reload(sys.modules[target])
-        else:
-            module = __import__(target, globals(), locals(), [''])
     
     def test01HelloWorld(self):
         self.load_tut_module("tut01_helloworld")
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.