Anonymous avatar Anonymous committed e18e55f

testing of the cherrypy, importing from two directories up, not the installe version. With patch so less errors should occur in the test environment: so no more processes would stay around bound to port 8000

Comments (0)

Files changed (3)

test/buildInfoMap.py

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 """
 
-import os, sys
+import os, sys,os
 
 def buildInfoMap(python2):
     print "Checking which python versions are installed..."
     for version, infoMap in python2.items():
         # Check if this version of python is installed:
-        path=infoMap.get('path', "python2.%s" % version)
+        path=infoMap.get('path', sys.executable )
         if path:
-            exactVersion=os.popen('%s -c "import sys; import cherrypy; print sys.version; print cherrypy.__version__"'%path).read().strip()
+            exactVersion=os.popen(
+                '%s -c "import sys,os,os.path;' % path+
+                """sys.path.insert(0,os.path.normpath(os.path.join(os.getcwd(),\'../../\')));"""+
+                'import cherrypy;'+
+                'print sys.version;'+
+                'print cherrypy.__version__"').read().strip()
         if path and exactVersion and exactVersion.find('Traceback') == -1:
             exactVersionShort=exactVersion.split()[0]
             print "    Found python version %s with CherryPy version %s " % (exactVersionShort, exactVersion.split()[-1])
                 print "If your setup is different, please edit this script and change the path for the python binary"
                 sys.exit(-1)
         else:
-            print "    Version 2.%s not found (or CherryPy not installed for this version)"%version
+            print "    Version 2.%s not found with cherrypy module, two directories up"%version
             del python2[version]
 
     if not python2:
 def startServer(infoMap):
     # Start the server in another thread
     if not hasattr(os, "fork"): # win32 mostly
-        pid=os.spawnl(os.P_NOWAIT, infoMap['path'], infoMap['path'], 'testsite.py')
+        pid=os.spawnl(os.P_NOWAIT,infoMap['path'] , os.getcwd(), 'testsite.py')
     else:
         pid=os.fork()
         if not pid:
     data=""
     i=0
     response = None
+    class EmptyClass: pass
+    cpg = EmptyClass()
+    cpg.response = EmptyClass()
+    cpg.response.body = None
+    cpg.response.headerMap = {}
     while i<10:
         try:
             conn=httplib.HTTPConnection('127.0.0.1:8000')
 
             cookies=response.msg.getallmatchingheaders("Set-Cookie")
 
-            class EmptyClass: pass
-            cpg = EmptyClass()
+            cpg=EmptyClass()
             cpg.response = EmptyClass()
             cpg.response.headerMap = {'Status': response.status}
             for line in response.msg.headers:
         except AttributeError: pass # For Python2.3
 
 def checkResult(testName, infoMap, serverMode, cpg, rule, failedList):
-    if eval(rule):
-        return True
-    else:
+    result = False
+    try:
+        result = eval(rule)
+        if result:
+            return result 
+    except:
+        pass 
+    if not result:
         failedList.append(testName +
             " for python%s" % infoMap['exactVersionShort'] + 
             " in " + serverMode + " mode failed." + """
 def f(*a, **kw): return ""
 cpg.root._cpLogMessage = f
 '''
-    f.write(code.replace('cpg.server.start', beforeStart + 'cpg.server.start'))
+    includePathsToSysPath = """
+import sys,os,os.path
+sys.path.insert(0,os.path.join(os.getcwd(),'../..'))
+"""
+    f.write(includePathsToSysPath+code.replace('cpg.server.start', beforeStart + 'cpg.server.start'))
     f.close()
 
 def checkPageResult(testName, infoMap, code, testList, failedList, extraConfig = '', extraRequestHeader = []):
 
 # Regression test suite for CherryPy
 
-import sys
+import sys,os,os.path
+sys.path.insert(0,os.path.normpath(os.path.join(os.getcwd(),'../../')))
+if not os.path.exists(os.path.join(os.curdir,'buildInfoMap.py')):
+    print "Run the test form the test directory (cherrypy/test)from the cherrypy you wish to test."
+    print "In no python executables are found, change this file (test.py) near line 31"
+    sys.exit(1)
 if len(sys.argv) == 2 and sys.argv[1] in ('-h', '--help'):
     print "Usage: unittest.py [testName+]"
+    print "Run from the test directory from within cherrypy"
     sys.exit(0)
 
 python2={}
 
 # Edit these lines to match your setup
 if sys.platform=="win32":
-    python2[3]['path']="c:\\python23\\python"
-    python2[4]['path']="c:\\python24\\python"
+    python2[3]['path']="c:\\python\\python.exe"
+    python2[4]['path']="c:\\python24\\python.exe"
 else:
     python2[3]['path']="python2.3"
     python2[4]['path']="python2.4"
 #    - test hidden classes
 #    ...
 
+raw_input('hit enter')
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.