Author: gotcha
Date: Sun Feb 18 19:14:25 2007
New Revision: 39169

Modified:
   kukit/kss.buildout/trunk/dotests_win.py
Log:
almost there; thanks to Hanno

Modified: kukit/kss.buildout/trunk/dotests_win.py
==============================================================================
--- kukit/kss.buildout/trunk/dotests_win.py     (original)
+++ kukit/kss.buildout/trunk/dotests_win.py     Sun Feb 18 19:14:25 2007
@@ -1,56 +1,110 @@
 import os, signal, sys
-import subprocess
-
-java = sys.argv[1]
-seleniumbrowser = sys.argv[2]
-here = os.getcwd()
-
-#start seleniumRC server
-seleniumjar = os.path.join('parts', 'seleniumrc', 'selenium-server.jar') 
-javapid = os.spawnl(os.P_NOWAIT, java, 'java', '-jar', seleniumjar )
-
-#start zope
-# should use runzope.bat
-zope = os.path.join(here, 'parts', 'instance', 'bin', 'zopectl')
-batfile = open('script.bat', 'w')
-batfile.write(" ".join([zope, 'start']))
-batfile.close()
-subprocess.call('script.bat')
-
-#wait for zope instance to come up
 from time import sleep
-testcmd = "wget -O- http://localhost:8080";
-while subprocess.call(testcmd.split()):
-   sleep(1)
-
-#setup simple content instance
-testcmd = "wget -O- http://localhost:8080/demo";
-exitcode = subprocess.call(testcmd.split())
-if exitcode <> 0:
-   print "add"
-   setupcmd = """wget -O- --http-user=admin --http-password=admin --post-data 
add_input_name=demo&UPDATE_SUBMIT=Add 
http://localhost:8080/+/AddSimpleContent.html""";
-   exitcode = subprocess.call(setupcmd.split())
-
-#start tests
-python = sys.executable
-zope_test = os.path.join(here, 'tests')
-environ = {}
-environ['SELENIUMBROWSER'] = seleniumbrowser 
-test_command_pieces = [zope_test]
-test_command_pieces.append('--package-path')
-test_command_pieces.append(os.path.join(here, 'src', 'kss.demo', 'kss', 
'demo', 'tests'))
-test_command_pieces.append('kss.demo.tests --test-file-pattern=^seltest 
--tests-pattern=selenium_tests')
-test_command = ' '.join(test_command_pieces)
-print test_command
-std = os.popen(test_command)
-print std.read()
-test_exit = std.close()
-
-#stop seleniumRC server
-#should not use os.kill
-os.kill(javapid, signal.SIGKILL)
+from win32process import CreateProcess
+from win32process import GetExitCodeProcess
+from win32process import TerminateProcess
+from win32process import STARTUPINFO
+from win32con import CREATE_NO_WINDOW
+from win32con import CREATE_NEW_PROCESS_GROUP
+from win32con import DETACHED_PROCESS
+import subprocess 
+
+def startProcess(app, commandline):
+    print commandline
+    print
+    process, thread, processid, threadid = CreateProcess(app, commandline,
+        None, None, True, 
+        CREATE_NO_WINDOW+DETACHED_PROCESS,
+        None, None, STARTUPINFO())
+    return process
+
+def getExitCode(process):
+    while True:
+        sleep(1)
+        exit = GetExitCodeProcess(process)
+        if exit <> 259:
+            return exit 
+def main():
+    runner = Runner()
+    sys.exit(runner.process())
+
+class Runner:
+    def __init__(self):
+        self.java = sys.argv[1]
+        self.seleniumbrowser = sys.argv[2]
+        self.here = os.getcwd()
+        self.wget = "c:\\cygwin\\bin\\wget.exe"
+        self.cmd = "cmd.exe"
+        self.zope = os.path.join(self.here, 'bin', 'instance.exe')
+
+    def process(self):
+        self.startSeleniumRC()
+        self.startZope()
+        self.waitForZope()
+        self.setupKSSDemoInstance()
+        testExit = self.runTests()
+        self.stopZope()
+        self.stopSeleniumRC()
+        return testExit
+
+    def startSeleniumRC(self):
+        seleniumjar = os.path.join('parts', 'seleniumrc', 
'selenium-server.jar') 
+        command = " ".join([self.java, '-jar', seleniumjar])
+        self.javaprocess = startProcess(self.java, command)
+
+    def startZope(self):
+        command = " ".join([self.zope, 'fg'])
+        process = startProcess(self.zope, command)
+
+    def waitForZope(self):
+        command = " ".join([self.wget, "-O-",  "http://localhost:8080";])
+        exitcode = 1
+        count = 0
+        while exitcode or count > 60:
+            count +=1
+            exitcode = subprocess.call(command)
+            sleep(1)
+        if exitcode == 0:
+            print "Zope started"
+
+    def setupKSSDemoInstance(self):
+        command = " ".join([self.wget, "-O-",  "http://localhost:8080/demo";])
+        exitcode = subprocess.call(command)
+        if exitcode == 0:
+            print "demo exists"
+        if exitcode <> 0:
+            print "setup demo"
+            command = " ".join([self.wget, "-O-",
+                "--http-user=admin", "--http-password=admin",
+                "--post-data", "add_input_name=demo&UPDATE_SUBMIT=Add",
+                "http://localhost:8080/+/AddSimpleContent.html";])
+            exitcode = subprocess.call(command)
+            if exitcode == 0:
+                print "demo instantiated"
+
+    def stopZope(self):
+        command = " ".join([self.wget, "-O-",
+            "--http-user=admin", "--http-password=admin",
+            "http://localhost:8080/Control_Panel/manage_shutdown";])
+        exitcode = subprocess.call(command)
+        if exitcode == 0:
+            print "zope shutting down"
+    
+    
+    def runTests(self):
+        environ = os.environ
+        environ['SELENIUMBROWSER'] = self.seleniumbrowser 
+        testsPath = os.path.join(self.here, 'src', 'kss.demo', 'kss', 'demo', 
'tests')
+        zope_test = os.path.join(self.here, 'parts', 'instance', 'bin', 
'test.bat')
+        command = " ".join([self.cmd, "/C", zope_test, "test",
+            '--package-path', testsPath,
+            'kss.demo.tests', '--test-file-pattern=^seltest',
+            '--tests-pattern=selenium_tests'])
+        print command
+        exitcode = subprocess.call(command, env=environ)
+        return exitcode
 
-#stop zope
-subprocess.call([zope, 'stop'])
+    def stopSeleniumRC(self):
+        TerminateProcess(self.javaprocess, 0)
 
-sys.exit(test_exit)
+main()
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to