Robert Brewer avatar Robert Brewer committed 9531c80

test_tutorials.py now runs on its own (not just as part of test.py).

Comments (0)

Files changed (3)

cherrypy/_cpconfig.py

 
 cpg = None # delayed import
 
-configMap = {
-        '/': {
-            'server.socketPort': 8080,
-            'server.socketHost': '',
-            'server.socketFile': '',
-            'server.socketQueueSize': 5,
-
-            'server.environment': 'development',
-            'server.protocolVersion': 'HTTP/1.0',
-            'server.logToScreen': True,
-            'server.logFile': '',
-            'server.reverseDNS': False,
-            'server.threadPool': 0,
-
-            'session.storageType': 'ram',
-            'session.timeout': 60,
-            'session.cleanUpDelay': 60,
-            'session.cookieName': 'CherryPySession',
-            'session.storageFileDir': '',
-        },
+defaultGlobal = {
+    'server.socketPort': 8080,
+    'server.socketHost': '',
+    'server.socketFile': '',
+    'server.socketQueueSize': 5,
+
+    'server.environment': 'development',
+    'server.protocolVersion': 'HTTP/1.0',
+    'server.logToScreen': True,
+    'server.logFile': '',
+    'server.reverseDNS': False,
+    'server.threadPool': 0,
+
+    'session.storageType': 'ram',
+    'session.timeout': 60,
+    'session.cleanUpDelay': 60,
+    'session.cookieName': 'CherryPySession',
+    'session.storageFileDir': '',
     }
+configMap = {"/": defaultGlobal.copy()}
 
 def update(updateMap=None, file=None):
     if updateMap:

cherrypy/test/test.py

     server_conf = {'server.socketHost': helper.HOST,
                    'server.socketPort': helper.PORT,
                    'server.threadPool': 10,
-                   'server.socketQueueSize': 5,
                    'server.logToScreen': False,
+                   'server.environment': "production",
 ##                   'profiling.on': True,
                    }
     
         for testmod in testList:
             # Must run each module in a separate suite,
             # because each module uses/overwrites cpg globals.
-            cpg.config.configMap.clear()
+            cpg.config.configMap.clear()
+            cpg.config.configMap["/"] = cpg.config.defaultGlobal.copy()
             cpg.config.update({'/': server_conf.copy()})
             suite = CPTestLoader.loadTestsFromName(testmod)
             CPTestRunner(verbosity=2).run(suite)

cherrypy/test/test_tutorials.py

 """
 
 import unittest
-import helper
 import sys
-from cherrypy import cpg
-
+from cherrypy import cpg
+from cherrypy.test import helper
+
+server_conf = {'server.socketHost': helper.HOST,
+               'server.socketPort': helper.PORT,
+               'server.threadPool': 10,
+               'server.logToScreen': False,
+               'server.environment': "production",
+##               'profiling.on': True,
+               }
 
 def load_tut_module(tutorialName):
     """Import or reload tutorial module as needed."""
+    cpg.config.configMap.clear()
+    cpg.config.configMap["/"] = cpg.config.defaultGlobal.copy()
+    cpg.config.update({'/': server_conf.copy()})
+    
     target = "cherrypy.tutorial." + tutorialName
     if target in sys.modules:
         module = reload(sys.modules[target])
     else:
-        module = __import__(target)
+        module = __import__(target)
+    
+    cpg.server.start(initOnly=True)
 
 
 class TutorialTest(unittest.TestCase):
     
     def test01HelloWorld(self):
         load_tut_module("tut01_helloworld")
-        cpg.server.start(initOnly=True)
         helper.request("/")
         self.assertEqual(cpg.response.body, 'Hello world!')
     
     def test02ExposeMethods(self):
         load_tut_module("tut02_expose_methods")
-        cpg.server.start(initOnly=True)
         helper.request("/showMessage")
         self.assertEqual(cpg.response.body, 'Hello world!')
     
     def test03GetAndPost(self):
         load_tut_module("tut03_get_and_post")
-        cpg.server.start(initOnly=True)
         
         helper.request("/greetUser?name=Bob")
         self.assertEqual(cpg.response.body, "Hey Bob, what's up?")
     
     def test04ComplexSite(self):
         load_tut_module("tut04_complex_site")
-        cpg.server.start(initOnly=True)
         msg = '''
             <p>Here are some extra useful links:</p>
             
     
     def test05DerivedObjects(self):
         load_tut_module("tut05_derived_objects")
-        cpg.server.start(initOnly=True)
         msg = '''
             <html>
             <head>
     
     def test06Aspects(self):
         load_tut_module("tut06_aspects")
-        cpg.server.start(initOnly=True)
         msg = '''
             <html>
             <head>
     
     def test07DefaultMethod(self):
         load_tut_module("tut07_default_method")
-        cpg.server.start(initOnly=True)
         helper.request('/hendrik')
         self.assertEqual(cpg.response.body,
                          'Hendrik Mans, CherryPy co-developer & crazy German '
     
     def test08Sessions(self):
         load_tut_module("tut08_sessions")
-        cpg.server.start(initOnly=True)
-        
-        cpg.config.configMap["/"] = {'session.storageType': 'ram',
-                                     'session.cookieName': 'CherryPySession',
-                                     'session.timeout': 60,
-                                     'session.cleanUpDelay': 60,
-                                     'session.storageFileDir': '',
-                                     }
         
         helper.request('/')
         self.assertEqual(cpg.response.body,
     
     def test09GeneratorsAndYield(self):
         load_tut_module("tut09_generators_and_yield")
-        cpg.server.start(initOnly=True)
         helper.request('/')
         self.assertEqual(cpg.response.body,
                          '<html><body><h2>Generators rule!</h2>'
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.