[Zope-CVS] CVS: Packages/FunctionalTests/FunctionalTests/tests - __init__.py:1.1 config.ini:1.1 test_ConfigParserExt.py:1.1 test_Result.py:1.1 test_Scenario.py:1.1 test_all.py:1.1

Tres Seaver tseaver@zope.com
Thu, 24 Apr 2003 17:39:53 -0400


Update of /cvs-repository/Packages/FunctionalTests/FunctionalTests/tests
In directory cvs.zope.org:/tmp/cvs-serv3971/FunctionalTests/tests

Added Files:
	__init__.py config.ini test_ConfigParserExt.py test_Result.py 
	test_Scenario.py test_all.py 
Log Message:


  - Repackage for distutils.


=== Added File Packages/FunctionalTests/FunctionalTests/tests/__init__.py ===
"""
    Unit tests for the FunctionalTests package.
"""


=== Added File Packages/FunctionalTests/FunctionalTests/tests/config.ini ===
[Header]
Title: The Title
Description: A more verbose description of the item, perhaps even
    wrapped across lines

[Section_1]
key: %(prefix)s_1

[Section_2]
key: %(prefix)s_2

[Section_3]
key: %(prefix)s_3

[Section_4]
key: %(prefix)s_4

[Section_5]
key: %(prefix)s_5

[DEFAULT]
prefix: section


=== Added File Packages/FunctionalTests/FunctionalTests/tests/test_ConfigParserExt.py ===
import unittest


class CPETests( unittest.TestCase ):

    def _makeOne( self, *args, **kw ):
        from FunctionalTests.ConfigParserExt import ConfigParserExt
        return ConfigParserExt( *args, **kw )

    def test_empty( self ):

        empty = self._makeOne()

        self.assertEquals( empty.listSpecialSections(), ( 'DEFAULT', ) )
        self.failIf( empty.listOtherSections() )

    def _getTestPath( self, *args ):
        import os
        import FunctionalTests
        package_path = os.path.abspath( FunctionalTests.__path__[0] )
        return os.path.join( package_path, *args )

    def test_withFile( self ):

        cpe = self._makeOne( ( 'Header', 'DEFAULT' ) )

        self.assertEquals( len( cpe.listSpecialSections() ), 2 )
        self.failUnless( 'Header' in cpe.listSpecialSections() )
        self.failUnless( 'DEFAULT' in cpe.listSpecialSections() )
        self.failIf( cpe.listOtherSections() )

        filename =  self._getTestPath( 'tests', 'config.ini' )
        cpe.read( filename )

        self.assertEquals( len( cpe.listOtherSections() ), 5 )

        for i in range( 6 )[1:]:
            section = 'Section_%d' % i
            self.failUnless( section in cpe.listOtherSections() )
            self.assertEquals( cpe.get( section, 'key' ), section.lower() )


def test_suite():
    return unittest.makeSuite( CPETests )

if __name__ == '__main__':
    unittest.main()


=== Added File Packages/FunctionalTests/FunctionalTests/tests/test_Result.py ===
import unittest



class FauxInvocation:

    def __init__( self, result, elapsed ):
        self._result    = result
        self._elapsed   = elapsed

    def getResult( self ):
        return self._result

    def getElapsedTime( self ):
        return self._elapsed

class FauxRequest:

    def __init__( self, name, result, time ):
        self._name      = name
        self._result    = result
        self._time      = time

    def getName( self ):
        return self._name

    def getExpectedResult( self ):
        return self._result

    def getExpectedTime( self ):
        return self._time

MARKER = []
MARKER2 = []
class ResultTests( unittest.TestCase ):

    def _makeOne( self, *args, **kw ):
        from FunctionalTests.Framework import Result
        return Result( *args, **kw )

    def test_empty( self ):

        empty = self._makeOne( test=MARKER )

        self.failUnless( empty.getTest() is MARKER )
        self.failUnless( empty.timeRequests() )
        self.failUnless( empty.checkResponses() )
        self.failUnless( empty.checkElapsedTimes() )
        self.failIf( empty.listInvocations() )
        self.failIf( empty.listErrors() )
        self.failIf( empty.listErrors( fatal_only=1 ) )
        self.failIf( empty.listChildren() )

    def test_apathy( self ):

        apathy = self._makeOne( test=MARKER
                              , time_requests=0
                              , check_responses=0
                              , check_elapsed_times=0
                              )

        self.failUnless( apathy.getTest() is MARKER )
        self.failIf( apathy.timeRequests() )
        self.failIf( apathy.checkResponses() )
        self.failIf( apathy.checkElapsedTimes() )

        apathy.addInvocation( FauxInvocation( 500, 3600.0 )
                            , FauxRequest( 'foo', 200, 1.0 )
                            )
        self.assertEquals( len( apathy.listInvocations() ), 1 )
        self.failIf( apathy.listErrors() )
        self.failIf( apathy.listErrors( fatal_only=1 ) )
        self.failIf( apathy.listChildren() )

    def test_responseOnly( self ):

        driven = self._makeOne( test=MARKER
                              , time_requests=0
                              , check_responses=1
                              , check_elapsed_times=0
                              )

        self.failUnless( driven.getTest() is MARKER )
        self.failIf( driven.timeRequests() )
        self.failUnless( driven.checkResponses() )
        self.failIf( driven.checkElapsedTimes() )

        driven.addInvocation( FauxInvocation( 500, 3600.0 )
                            , FauxRequest( 'foo', 200, 1.0 )
                            )
        self.assertEquals( len( driven.listInvocations() ), 1 )
        self.assertEquals( len( driven.listErrors() ), 1 )
        self.assertEquals( len( driven.listErrors( fatal_only=1 ) ), 1 )
        self.failIf( driven.listChildren() )

    def test_timeOnly( self ):

        consistent = self._makeOne( test=MARKER
                                  , time_requests=0
                                  , check_responses=0
                                  , check_elapsed_times=1
                                  )

        self.failIf( consistent.timeRequests() )

        really = self._makeOne( test=MARKER
                              , time_requests=1
                              , check_responses=0
                              , check_elapsed_times=1
                              )

        self.failUnless( really.timeRequests() )

        impatiens = self._makeOne( test=MARKER
                                 , time_requests=1
                                 , check_responses=0
                                 , check_elapsed_times=1
                                 )

        self.failUnless( impatiens.getTest() is MARKER )
        self.failUnless( impatiens.timeRequests() )
        self.failIf( impatiens.checkResponses() )
        self.failUnless( impatiens.checkElapsedTimes() )

        impatiens.addInvocation( FauxInvocation( 500, 3600.0 )
                            , FauxRequest( 'foo', 200, 1.0 )
                            )
        self.assertEquals( len( impatiens.listInvocations() ), 1 )
        self.assertEquals( len( impatiens.listErrors() ), 1 )
        self.failIf( impatiens.listErrors( fatal_only=1 ) )
        self.failIf( impatiens.listChildren() )

    def test_composite( self ):

        top = self._makeOne( test=MARKER )

        self.failUnless( top.getTest() is MARKER )
        self.failUnless( top.timeRequests() )
        self.failUnless( top.checkResponses() )
        self.failUnless( top.checkElapsedTimes() )

        child = top.newChild( test=MARKER2 )

        self.failUnless( child.getTest() is MARKER2 )
        self.assertEquals( child.timeRequests(), top.timeRequests() )
        self.assertEquals( child.checkResponses(), top.checkResponses() )
        self.assertEquals( child.checkElapsedTimes(), top.checkElapsedTimes() )

        child.addInvocation( FauxInvocation( 500, 3600.0 )
                            , FauxRequest( 'foo', 200, 1.0 )
                            )
        self.assertEquals( len( child.listInvocations() ), 1 )
        self.assertEquals( len( child.listErrors() ), 1 )
        self.assertEquals( len( child.listErrors( fatal_only=1 ) ), 1 )

        self.assertEquals( len( top.listInvocations() ), 1 )
        self.assertEquals( len( top.listInvocations( roll_up=0 ) ), 0 )
        self.assertEquals( len( top.listErrors() ), 1 )
        self.assertEquals( len( top.listErrors( roll_up=0 ) ), 0 )
        self.assertEquals( len( top.listErrors( fatal_only=1 ) ), 1 )
        self.assertEquals( len( top.listErrors( fatal_only=1, roll_up=0 ) ), 0 )
        self.assertEquals( len( top.listChildren() ), 1 )

        top = self._makeOne( test=MARKER
                           , application=[]
                           , defaults={ 'foo':0 }
                           , time_requests=0
                           , check_responses=0
                           , check_elapsed_times=0
                           )
        child = top.newChild( test=MARKER2 )
        self.failUnless( child.getApplication() is top.getApplication() )
        self.assertEquals( child.getDefaults(), top.getDefaults() )
        self.assertEquals( child.timeRequests(), top.timeRequests() )
        self.assertEquals( child.checkResponses(), top.checkResponses() )
        self.assertEquals( child.checkElapsedTimes(), top.checkElapsedTimes() )


def test_suite():
    return unittest.makeSuite( ResultTests )

if __name__ == '__main__':
    unittest.main()


=== Added File Packages/FunctionalTests/FunctionalTests/tests/test_Scenario.py ===
import unittest

class DummyRequest:

    _called_with = None
    _fail = 0

    def __init__( self, id ):
        self._id = id

    def getId( self ):
        return self._id

    def setFail( self ):
        self._fail = 1

    def __call__( self, result ):

        self._called_with = result

        if self._fail:
            result.setAbend()

        return self._id

class DummyResult:

    _ok = 1
    _setup_called = 0
    _teardown_called = 0

    def __init__( self ):

        self._invocations = []

    def __call__( self ):

        return self._ok

    def isAbend( self ):

        return not self._ok

    def getSetupCalled( self ):

        return self._setup_called

    def getTeardownCalled( self ):

        return self._teardown_called

    def setAbend( self ):

        self._ok = 0

    def setSetupCalled( self ):

        self._setup_called = 1

    def setTeardownCalled( self ):

        self._teardown_called = 1

    def addInvocation( self, inv, req ):

        self._invocations.append( ( inv, req ) )

    def listInvocations( self ):

        return self._invocations

class ScenarioTests( unittest.TestCase ):

    def _makeOne( self, *args, **kw ):
        from FunctionalTests.Framework import Scenario
        return Scenario( *args, **kw )

    def test_empty( self ):

        empty = self._makeOne()

        self.failIf( empty.getUseCase() )
        self.failIf( empty.getPostcondition() )
        self.failIf( empty.listRequests() )
        self.failIf( empty.getLoadSequence() )

        self.failIf( empty.hasLoadRequests() )
        self.assertRaises( IndexError, empty.nextLoadRequest )

    def _makeRequests( self, *ids ):

        result = []

        for id in ids:
            result.append( DummyRequest( id ) )

        return tuple( result )

    def test_addRequest( self ):

        adder = self._makeOne()

        REQUESTS = self._makeRequests( 'one', 'two', 'three' )

        for request in REQUESTS:
            adder.addRequest( request )

        requests = adder.listRequests()
        self.assertEquals( len( requests ), len( REQUESTS ) )

        for r in REQUESTS:
            self.failUnless( r in requests )

    def test_call_normal( self ):

        phb = self._makeOne()

        REQUESTS = self._makeRequests( 'foo', 'bar', 'baz' )

        for request in REQUESTS:
            phb.addRequest( request )

        result = DummyResult()

        r = phb( result )

        self.assertEquals( r, result )
        self.failIf( result.isAbend() )
        self.assertEquals( len( result.listInvocations() ), len( REQUESTS ) )

    def test_call_abend( self ):

        phb = self._makeOne()

        REQUESTS = self._makeRequests( 'foo', 'bar', 'baz' )
        REQUESTS[1].setFail()

        for request in REQUESTS:
            phb.addRequest( request )

        result = DummyResult()

        r = phb( result )

        self.assertEquals( r, result )
        self.failUnless( result.isAbend() )
        self.assertEquals( len( result.listInvocations() ), 2 )

    def test_setLoadSequence_simple( self ):

        loader = self._makeOne()

        expr = "'a', 'b', 'c'"
        loader.setLoadSequence( expr )
        self.assertEquals( loader.getLoadSequence(), expr )

        for next_name in ( 'a', 'b', 'c' ):
            self.failUnless( loader.hasLoadRequests() )
            self.assertEqual( loader.nextLoadRequest(), next_name )

        self.failIf( loader.hasLoadRequests() )
        self.assertRaises( IndexError, loader.nextLoadRequest )

    def test_setLoadSequence_loop( self ):

        loader = self._makeOne()

        loader.setLoadSequence( "( 'a', 'b', 'c' ) * 10" )

        for iter in range( 10 ):
            for next_name in ( 'a', 'b', 'c' ):
                self.failUnless( loader.hasLoadRequests() )
                self.assertEqual( loader.nextLoadRequest(), next_name )

        self.failIf( loader.hasLoadRequests() )
        self.assertRaises( IndexError, loader.nextLoadRequest )

def test_suite():
    return unittest.makeSuite( ScenarioTests )

if __name__ == '__main__':
    unittest.main()


=== Added File Packages/FunctionalTests/FunctionalTests/tests/test_all.py ===
import unittest
from FunctionalTests.tests import test_ConfigParserExt
from FunctionalTests.tests import test_Result
from FunctionalTests.tests import test_Scenario

def test_suite():
    suite = unittest.TestSuite()
    suite.addTest( test_ConfigParserExt.test_suite() )
    suite.addTest( test_Result.test_suite() )
    suite.addTest( test_Scenario.test_suite() )
    return suite

def run():
    if hasattr( unittest, 'JUnitTextTestRunner' ):
        unittest.JUnitTextTestRunner().run( test_suite() )
    else:
        unittest.TextTestRunner( verbosity=1 ).run( test_suite() )

if __name__ == '__main__':
    run()