CVS: nondist/sandbox/magnus/tester2 runme.py,NONE,1.1

Magnus Lie Hetland <[email protected]> Fri, 07 Feb 2003 18:14:22 -0800
Newsgroups gmane.comp.python.anygui.cvs
Message-ID <[email protected]>
Update of /cvsroot/anygui/nondist/sandbox/magnus/tester2
In directory sc8-pr-cvs1:/tmp/cvs-serv18738

Added Files:
	runme.py 
Log Message:


--- NEW FILE: runme.py ---
#!/usr/bin/env python

# 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.

import os, sys
from time import *
from glob import glob
from anygui import *
from anygui.Utils import topologicalSort

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

HEAD = """\
<html>
  <head>
    <title>Anygui Test Results</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 Results</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 Results</h1>
<strong>%s</strong></p>
<p>
</center>
</div>

<br />

<hr />

<h2>Test Results for <code>%sgui</code></h2>

  """ % (strftime('%Y-%m-%d %H:%M:%S', localtime()), backend())

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 Results</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(Application):

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

    def setupGUI(self):
        self.win = Window(text='The Anygui Test Program')
        self.passButton = Button(text='Pass')
        self.win.add(self.passButton, right=10, bottom=10,
                                      hmove=1, vmove=1)
        link(self.passButton, self.passTest)
        self.failButton = Button(text='Fail')
        self.win.add(self.failButton, right=(self.passButton,10),
                                      bottom=10,
                                      hmove=1, vmove=1)
        link(self.failButton, self.failTest)
                                      
        self.setupTests()
        self.nextTest()
        self.add(self.win)

    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()

def main(args=[]):
    tw = TestWizard(testFiles(), RESULT_FILE)
    tw.run()

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



-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com