CVS: /nondist/sandbox/magnus/tester server.py,NONE,1.1 runme.py,1.4,1.5

Magnus Lie Hetland <[email protected]> Tue, 26 Aug 2003 11:05:54 -0700
Newsgroups gmane.comp.python.anygui.cvs
Message-ID <[email protected]>
Update of /cvsroot/anygui//nondist/sandbox/magnus/tester
In directory sc8-pr-cvs1:/tmp/cvs-serv3742

Modified Files:
	runme.py 
Added Files:
	server.py 
Log Message:


--- NEW FILE: server.py ---
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from threading import Thread
import webbrowser
import os, sys
from time import *
from glob import glob
from anygui import *
from anygui.Utils import topologicalSort


# FIXME: Currently resets all results; should keep results from other
# back-ends. Rewrite to create a single table of successes/failures for all
# back-ends, parse in existing test results from the result file, and
# display the test descriptions only once, below the table.

TEST_DIR = 'tests'
TEST_PAT = 'test_*.py'
RESULT_FILE = 'results.html'

HEAD = """\
<html>
  <head>
    <title>Anygui Test Wizard</title>
    <style>

body                    { color: #000000;
                          background-color: #ffffff; }

a:active                { color: #ff0000; }
a:visited               { color: #551a8b; }
a:link                  { color: #0000bb; }

h1, h2, h3, h4, h5, h6  { font-family: avantgarde, sans-serif;
                          font-weight: bold; }
h1                      { font-size: 180%%; }
h2                      { font-size: 150%%; }
h3, h4                  { font-size: 120%%; }
code, tt                { font-family: lucida typewriter, lucidatypewriter,
                                       monospace; }
var                     { font-family: times, serif;
                          font-style: italic;
                          font-weight: normal; }

.typelabel              { font-family: lucida, sans-serif; }

.navigation td          { background-color: #99ccff;
                          font-weight: bold;
                          font-family: avantgarde, sans-serif;
                          font-size: 110%%; }

.release-info           { font-style: italic; }

.titlegraphic           { vertical-align: top; }

.verbatim               { color: #00008b;
                          font-family: lucida typewriter, lucidatypewriter,
                                       monospace; }

.grammar                { background-color: #99ccff;
                          margin-right: 0.5in;
                          padding: 0.05in; }
.productions            { background-color: #bbeeff; }
.productions table      { vertical-align: baseline; }
.grammar-footer         { padding: 0.05in;
                          font-size: 85%%; }

.email                  { font-family: avantgarde, sans-serif; }
.mailheader             { font-family: avantgarde, sans-serif; }
.mimetype               { font-family: avantgarde, sans-serif; }
.newsgroup              { font-family: avantgarde, sans-serif; }
.url                    { font-family: avantgarde, sans-serif; }
.file                   { font-family: avantgarde, sans-serif; }

.tableheader            { background-color: #99ccff;
                          font-family: avantgarde, sans-serif; }

    </style>
  </head>
  <body>
<div class="navigation">
<table align="center" width="100%%" cellpadding="0" cellspacing="2">
<tr>
<td><img src="icons/blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
<td><img src="icons/blank.gif"
  border="0" height="32"
  alt="Up One Level" width="32"></td>
<td><img src="icons/up.gif"
  border="0" height="32"
  alt="Next Page" width="32"></td>
<td align="center" width="100%%">Anygui Test Wizard</td>
<td><img src="icons/blank.gif"
  border="0" height="32"
  alt="Contents" width="32"></td>
<td><img src="icons/blank.gif"
  border="0" height="32"
  alt="Module Index" width="32"></td>
<td><img src="icons/blank.gif"
  border="0" height="32"
  alt="Index" width="32"></td>
</tr></table>
<b class="navlabel">Up:</b> <a class="sectref" HREF="http://www.anygui.org">Anygui home</a>
<br /><hr />
</div>

<div class="titlepage">
<center>
<h1>Anygui Test Wizard</h1>
<!-- <strong>%s</strong> -->
</center>
</div>

<br />

<hr />

"""

FOOT = """\
<div class="navigation">
<hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><img src="icons/blank.gif"
  border="0" height="32"
  alt="" width="32"></td>
<td><img src="icons/blank.gif"
  border="0" height="32"
  alt="Up One Level" width="32"></td>
<td><img src="icons/up.gif"
  border="0" height="32"
  alt="Next Page" width="32"></td>
<td align="center" width="100%">Anygui Test Wizard</td>
<td><img src="icons/blank.gif"
  border="0" height="32"
  alt="Contents" width="32"></td>
<td><img src="icons/blank.gif"
  border="0" height="32"
  alt="Module Index" width="32"></td>
<td><img src="icons/blank.gif"
  border="0" height="32"
  alt="Index" width="32"></td>
</tr></table>
<b class="navlabel">Up:</b> <a class="sectref" HREF="http://www.anygui.org">Anygui home</a>
<br><hr />
</div>
  </body>
</html>"""

def testFiles():
    return glob(os.path.join(TEST_DIR, TEST_PAT))

"""

class TestResult:

    status = 'Failed'
    
    def __init__(self, name, scope):
        self.name = name
        self.scope = scope

    def __str__(self):
        
        docs = self.scope.get('__doc__', '(No description available)')
        docs = '<p>' + docs.replace('\n\n', '\n</p>\n<p>') + '\n</p>'
        return '''<h3>%s: %s</h3>
        
        %s
        ''' % (self.name, self.status, docs)

class TestWizard:

    def __init__(self, files, resultFile, *args, **kwds):
        Application.__init__(self, *args, **kwds)
        self.files = files
        self.resultFile = resultFile
        self.results = []
        self.setupGUI()

    def setupTests(self):
        testScopes = []
        testNames = []
        constraints = []
        for fname in self.files:
            scope = {}
            exec open(fname) in scope
            testScopes.append(scope)
            name = os.path.basename(fname)
            testNames.append(name)
            for other in eval('after', scope):
                constraints.append((other, name))
        topologicalSort(testNames, testScopes, constraints)
        testScopes.reverse()
        testNames.reverse()
        self.testScopes = testScopes
        self.testNames = testNames

    def nextTest(self):
        if not self.testScopes: 
            self.writeResults()
            sys.exit()
        scope = self.testScopes.pop()
        name = self.testNames.pop()
        try: self.win.remove(self.frame)
        except AttributeError: pass
        self.frame = Frame()
        assert not hasattr(scope, '__supplied_frame')
        scope['__supplied_frame'] = self.frame
        exec 'setup(__supplied_frame)' in scope
        self.win.add(self.frame, top=0, left=0, right=0,
                     bottom=(self.passButton, 10),
                     hstretch=1, vstretch=1)
        self.results.append(TestResult(name, scope))

    def writeResults(self):
        out = open(self.resultFile, 'w')
        print >> out, HEAD
        for result in self.results:
            print >> out, result
        print >> out, FOOT
        out.close()

    def passTest(self, event):
        self.results[-1].status = 'Passed'
        self.nextTest()

    def failTest(self, event):
        self.nextTest()

"""

class RequestHandler(BaseHTTPRequestHandler):

    def __init__(self, *args, **kwds):
        BaseHTTPRequestHandler.__init__(self, *args, **kwds)
        self.setupTests()

    def setupTests(self):
        testScopes = []
        testNames = []
        constraints = []
        for fname in testFiles():
            scope = {}
            exec open(fname) in scope
            testScopes.append(scope)
            name = os.path.basename(fname)
            testNames.append(name)
            for other in eval('after', scope):
                constraints.append((other, name))
        topologicalSort(testNames, testScopes, constraints)
        testScopes.reverse()
        testNames.reverse()
        self.testScopes = testScopes
        self.testNames = testNames
    
    def do_GET(self):
        if self.client_address[0] != "127.0.0.1":
            self.send_error(403)
            return

        if self.path in ['/icons/blank.gif', '/icons/up.gif']:
            print >> self.wfile, "Content-type: image/gif\n"
            self.wfile.write(open(self.path[1:], 'rb').read())
            return
        
        print >> self.wfile, "Content-type: text/html\n"

        print >> self.wfile, HEAD

        # [...]

        print >> self.wfile, FOOT


def main(args=[]):    
    webbrowser.open('http://localhost:8000')
    server = HTTPServer(('', 8000), RequestHandler)
    try: server.serve_forever()
    except KeyboardInterrupt: pass

    #tw = TestWizard(testFiles(), RESULT_FILE)
    #tw.run()

if __name__ == '__main__':
    main(sys.argv)

Index: runme.py
===================================================================
RCS file: /cvsroot/anygui//nondist/sandbox/magnus/tester/runme.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** runme.py	9 Jun 2003 18:40:37 -0000	1.4
--- runme.py	26 Aug 2003 18:05:52 -0000	1.5
***************
*** 23,26 ****
--- 23,27 ----
      <title>Anygui Test Results</title>
      <style>
+ 
  body                    { color: #000000;
                            background-color: #ffffff; }



-------------------------------------------------------
This SF.net email is sponsored by: VM Ware
With VMware you can run multiple operating systems on a single machine.
WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines
at the same time. Free trial click here:http://www.vmware.com/wl/offer/358/0