Webware / WebKit / Testing /

Full commit
from WebKit.SidebarPage import SidebarPage

class Main(SidebarPage):
    """Testing - read and display them.

    TO DO
      * Reload only load when modified (by checking mod date).


    def title(self):
        return 'Testing'

    def cornerTitle(self):
        return 'WebKit Testing'

    def writeContent(self):
        self.writeln('<h2 style="text-align:center">Test cases</h2>')

    def writeTestCases(self):
        wr = self.writeln
        req = self.request()
        servletPath = req.servletPath()
        filename = self.serverSidePath('')
        self._cases = self.readFileNamed(filename)
        wr('<table align="center" style="margin-left:auto;margin-right:auto"'
            ' border="0" cellpadding="3" cellspacing="2">')
        wr('<tr style="color:white;background-color:#555">'
        caseNum = 1
        for case in self._cases:
            # For each URL, fix it up and make a name. Put in urls list.
            urls = []
            for url in case['URLs']:
                url = servletPath + url
                if url:
                    urlName = self.htmlEncode(url)
                    urls.append((url, urlName))
            if not urls:
            expectation = case['Expectation'] # self.htmlEncode(case['Expectation'])
            bgcolor = ['EEE', 'DDD'][caseNum % 2]
            wr('<tr style="background-color:#%s">'
                '<td>%d.</td><td>' % (bgcolor, caseNum))
            for url, urlName in urls:
                wr('<a href="%s">%s</a><br>' % (url, urlName))
            wr('<td>%s</td></tr>' % expectation)
            caseNum += 1

    def readFileNamed(self, filename):
        """Return a list of test cases.

        Each of them is a dictionary, as defined the given file.
        See for information on the format.

        f = open(filename)
        cases = self.readFile(f)
        return cases

    def readFile(self, file):
        return self.readContent(

    def readContent(self, content):
        lines = [line.strip() for line in content.splitlines()]
        lineNum = 1
        cases = []
        urls = []
        for line in lines:
            if line and line[0] != '#':
                if line[-1] == '\\': # continuation line;
                    # means there are multiple URLs for this case
                    parts = line.split('-->')
                    if len(parts) != 2:
                        self.error('Invalid line at %d.' % lineNum)
                        URLs=urls, Expectation=parts[1].strip()))
                    urls = [] # reset list of URLs
            lineNum += 1
        return cases

    def writeNotes(self):
<li>Test all links in all pages of all contexts (Examples, Admin, Testing, etc.),
including links found in the headers and footers of the pages.</li>
<li>Test functionality of interactive pages, like CountVisits and ListBox.</li>
<li>Test each link more than once.</li>
<li>Test with multiple adapters (WebKit.cgi, OneShot.cgi, etc.).</li>

    def error(self, msg):
        raise Exception(msg)