runner.py :  » Web-Frameworks » Nevow » Nevow-0.10.0 » nevow » livetrial » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Frameworks » Nevow 
Nevow » Nevow 0.10.0 » nevow » livetrial » runner.py
from twisted.python import filepath

from nevow import athena,loaders,tags,rend,url,static,util

staticData = filepath.FilePath(__file__).parent().child('static')

class TestSuiteFragment(athena.LiveFragment):
    jsClass = u'Nevow.Athena.Test.TestSuite'
    docFactory = loaders.stan(tags.invisible(render=tags.directive('tests')))

    def __init__(self, suite):
        super(TestSuiteFragment, self).__init__()
        self.suite = suite
        self.testInstances = suite.gatherInstances()


    def gatherTests(self, testInstances):
        suiteTag = tags.div()
        for test in testInstances:
            if isinstance(test, list):
                suiteTag[self.gatherTests(testInstances)]
            else:
                test.setFragmentParent(self)
                suiteTag[test]
        return suiteTag


    def gatherHead(self):
        head = []
        def gather(testInstances):
            for test in testInstances:
                if isinstance(test, list):
                    head.extend(gather(test))
                else:
                    head.append(test.head())
        gather(self.testInstances)
        return filter(None, head)


    def render_tests(self, ctx, data):
        return ctx.tag[self.gatherTests(self.testInstances)]



class TestRunner(TestSuiteFragment):
    jsClass = u'Nevow.Athena.Test.TestRunner'
    docFactory = loaders.stan(
        tags.div(_class='test-runner', render=tags.directive('liveFragment'))[
            tags.form(action='#')[
                athena.handler(event='onsubmit', handler='runWithDefaults'),
                tags.input(type='submit', value='Run Tests')],
            tags.div[
                tags.div[
                    tags.div['Tests passed: ', tags.span(_class='test-success-count')[0]],
                    tags.div['Tests failed: ', tags.span(_class='test-failure-count')[0]],
                    tags.div['Tests completed in: ', tags.span(_class='test-time')['-']],
                    tags.div(render=tags.directive('debug'))],
                tags.hr,
                tags.div[tags.span(_class='test-results')],
                tags.hr,
                tags.div(render=tags.directive('tests'))]])


    def render_debug(self, ctx, data):
        f = athena.IntrospectionFragment()
        f.setFragmentParent(self)
        return f



DOCTYPE_XHTML = (
    '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '
    '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">')

class TestFramework(athena.LivePage):
    addSlash = True
    docFactory = loaders.stan([
        tags.xml(DOCTYPE_XHTML),
        tags.html[
            tags.head(render=tags.directive('liveglue'))[
                tags.link(rel='stylesheet', href='livetest.css'),
                tags.directive('head')],
            tags.body[
                tags.invisible(render=tags.directive('runner'))]]])

    def __init__(self, testSuite):
        super(TestFramework, self).__init__()
        self.testSuite = testSuite
        self.children = {
            'livetest.css': static.File(util.resource_filename('nevow.livetrial', 'livetest.css')),
        }


    def beforeRender(self, ctx):
        self.runner = TestRunner(self.testSuite)


    def render_runner(self, ctx, data):
        self.runner.setFragmentParent(self)
        return self.runner


    def render_head(self, ctx, data):
        return self.runner.gatherHead()


class TestFrameworkRoot(rend.Page):
    def child_app(self, ctx):
        return TestFramework(self.original)
    child_ = url.URL.fromString('/app')
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.