test_testbase.py :  » Template-Engines » Myghty » Myghty-1.1 » test » 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 » Template Engines » Myghty 
Myghty » Myghty 1.1 » test » test_testbase.py
"""test/test_testbase.py

Tests for stuff in test/testbase.py.
"""

import re, sys, unittest
import testbase
from myghty.component import Component

class ComponentTesterTests(testbase.ComponentTester):
    """Test cases for ComponentTester
    """
    
    srcFiles = { 'htdocs/foo.myt': 'foo',
                 'lib/barmod.py': 'def f(m): m.write("bar")',
                 }
    config = dict(module_components=[{'bar': 'barmod:f'}])
    
    def testFoo(self):
        self.runComponent("foo.myt")
        self.failUnlessEqual(self.output, 'foo')

    def testBar(self):
        self.runComponent("bar")
        self.failUnlessEqual(self.output, 'bar')

    def testRunInlineComponent(self):
        self.runComponent(
            """# comment
            howdy
            """)
        self.failUnlessEqual(self.tidyoutput, 'howdy')

    def testRunInlineModuleComponent(self):
        def comp(m):
            m.write("output")
        self.runComponent(comp)
        self.failUnlessEqual(self.output, 'output')

    def testMakeModule(self):
        testmod = self.makeModule("def f(m): m.write('boo')")
        self.runComponent(testmod.f)
        self.failUnlessEqual(self.output, "boo")

    def testMakeMemoryComponent(self):
        comp = self.makeMemoryComponent(
            '''
            <%flags>
                trim = "both"
            </%flags>
            from memory import 
            ''')
        self.failUnless(isinstance(comp, Component))
        self.runComponent(comp)
        self.failUnlessEqual(self.output, "from memory")


class TestUnwrapErrors(testbase.ComponentTester):
    """Test advice added to unittest.TestResult.addError()

    Exceptions which are wrapped in a myghty.Error should be
    unwrapped before the error is reported.
    """
    def x_test(self):
        self.runComponent("""% message = 'Boo'
                             % raise RuntimeError, message""")
        print self.output

    def test(self):
        mytest = unittest.defaultTestLoader.loadTestsFromName(
            '%s.TestUnwrapErrors.x_test' % __name__)
        result = unittest.TestResult()
        mytest.run(result)
        
        self.failUnlessEqual(len(result.errors), 1)
        failed, message = result.errors[0]
        last_line = message.rstrip().split('\n')[-1]
        self.failUnlessEqual("RuntimeError: Boo", last_line)
        
if __name__ == '__main__':
    unittest.main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.