[Zope-CVS] CVS: Packages/FunctionalTests/FunctionalTests/tests - conformance.py:1.1 plugin_module.py:1.1 test_Request.py:1.1 test_all.py:1.2
Tres Seaver
tseaver@zope.com
Sat, 31 May 2003 15:10:08 -0400
Update of /cvs-repository/Packages/FunctionalTests/FunctionalTests/tests
In directory cvs.zope.org:/tmp/cvs-serv29153/FunctionalTests/tests
Modified Files:
test_all.py
Added Files:
conformance.py plugin_module.py test_Request.py
Log Message:
- FunctionalTests/Request.py:
o Add interface assertions, moving docstrings to interfaces.
o _buildSleepRequest: pass sleep_time to ctor.
- FunctionalTests/interfaces.py:
o Flesh out request interfaces.
- FunctionalTests/tests/test_all:
o Add request tests.
- FunctionalTests/tests/conformance.py:
o Add base classes for testing interface conformance.
- FunctionalTests/tests/plugin_module.py:
o Dummy module for testing plugin functions.
- FunctionalTests/tests/test_Request.py:
o Test request implementations.
o XXX: HTTPRequest and ZEORequest tests still need fleshing out.
=== Added File Packages/FunctionalTests/FunctionalTests/tests/conformance.py ===
""" Base classes for testing interface conformance.
$Id: conformance.py,v 1.1 2003/05/31 19:10:07 tseaver Exp $
"""
try:
from Interface.Verify import verifyClass
except ImportError:
def verifyClass( iface, klass ):
assert iface in klass.__implements__
class ConformsToIPluginFunction:
""" Test conformance to IPluginFunction.
o Derived classes must implement _getTargetClass.
"""
def test_IPluginFunction_conformance( self ):
from FunctionalTests.interfaces import IPluginFunction
verifyClass( IPluginFunction, self._getTargetClass() )
class ConformsToIRequest:
""" Test conformance to IRequest.
o Derived classes must implement _getTargetClass.
"""
def test_IRequest_conformance( self ):
from FunctionalTests.interfaces import IRequest
verifyClass( IRequest, self._getTargetClass() )
class ConformsToISleepRequest:
""" Test conformance to ISleepRequest.
o Derived classes must implement _getTargetClass.
"""
def test_ISleepRequest_conformance( self ):
from FunctionalTests.interfaces import ISleepRequest
verifyClass( ISleepRequest, self._getTargetClass() )
class ConformsToIHTTPRequest:
""" Test conformance to IHTTPRequest.
o Derived classes must implement _getTargetClass.
"""
def test_IHTTPRequest_conformance( self ):
from FunctionalTests.interfaces import IHTTPRequest
verifyClass( IHTTPRequest, self._getTargetClass() )
class ConformsToIZEORequest:
""" Test conformance to IZEORequest.
o Derived classes must implement _getTargetClass.
"""
def test_IZEORequest_conformance( self ):
from FunctionalTests.interfaces import IZEORequest
verifyClass( IZEORequest, self._getTargetClass() )
=== Added File Packages/FunctionalTests/FunctionalTests/tests/plugin_module.py ===
""" Plugin test module.
$Id: plugin_module.py,v 1.1 2003/05/31 19:10:07 tseaver Exp $
"""
def plugin_test():
return 1234
=== Added File Packages/FunctionalTests/FunctionalTests/tests/test_Request.py ===
import unittest
import os
from conformance import ConformsToIPluginFunction
from conformance import ConformsToIRequest
from conformance import ConformsToISleepRequest
from conformance import ConformsToIHTTPRequest
from conformance import ConformsToIZEORequest
class PluginFunctionTests( unittest.TestCase
, ConformsToIPluginFunction
):
_TEST_MODULE_PATH = os.path.split( __file__ )[0]
_TEST_MODULE_FILE = 'plugin_module.py'
_TEST_MODULE_FQN = os.path.join( _TEST_MODULE_PATH, _TEST_MODULE_FILE )
_TEST_FUNCTION_NAME = 'plugin_test'
def _getTargetClass( self ):
from FunctionalTests.Request import PluginFunction
return PluginFunction
def _makeOne( self, *args, **kw ):
return self._getTargetClass()( *args, **kw )
def test_ctor( self ):
plugin = self._makeOne( filename=self._TEST_MODULE_FQN
, function=self._TEST_FUNCTION_NAME
)
self.assertEquals( plugin.getFileName(), self._TEST_MODULE_FQN )
self.assertEquals( plugin.getFunctionName(), self._TEST_FUNCTION_NAME )
def test_getFunction( self ):
plugin = self._makeOne( filename=self._TEST_MODULE_FQN
, function=self._TEST_FUNCTION_NAME
)
func = plugin.getFunction()
self.assertEquals( func.__name__, self._TEST_FUNCTION_NAME )
self.assertEquals( func(), 1234 )
class _RequestBaseTests:
def test_ctor( self ):
request = self._makeOne( name='rbtest' )
self.assertEquals( request.getName(), 'rbtest' )
self.assertEquals( request.getOption( 'foo' ), None )
self.assertEquals( request.getOption( 'foo', 0 ), 0 )
self.assertEquals( len( request.listOptions() ), 0 )
def test__setOptions( self ):
request = self._makeOne()
class FauxConfigParser:
def __init__( self ):
self._sections = {}
def options( self, section ):
return self._sections[ section ].keys()
def get( self, section, option ):
return self._sections[ section ][ option ]
fcp1 = FauxConfigParser()
fcp1._sections[ 'foo' ] = { 'bar' : 0, 'baz' : 1 }
request._setOptions( fcp1, 'foo' )
self.assertEquals( request.getOption( 'foo' ), None )
self.assertEquals( request.getOption( 'foo', 0 ), 0 )
self.assertEquals( request.getOption( 'bar' ), 0 )
self.assertEquals( request.getOption( 'baz' ), 1 )
self.assertEquals( len( request.listOptions() ), 2 )
fcp2 = FauxConfigParser()
fcp2._sections[ 'bam' ] = { 'qux' : 2 }
request._setOptions( fcp2, 'bam', clear=0 )
self.assertEquals( request.getOption( 'foo' ), None )
self.assertEquals( request.getOption( 'foo', 0 ), 0 )
self.assertEquals( request.getOption( 'bar' ), 0 )
self.assertEquals( request.getOption( 'baz' ), 1 )
self.assertEquals( request.getOption( 'qux' ), 2 )
self.assertEquals( len( request.listOptions() ), 3 )
request._setOptions( fcp2, 'bam', clear=1 )
self.assertEquals( request.getOption( 'foo' ), None )
self.assertEquals( request.getOption( 'foo', 0 ), 0 )
self.assertEquals( request.getOption( 'bar' ), None )
self.assertEquals( request.getOption( 'baz' ), None )
self.assertEquals( request.getOption( 'qux' ), 2 )
self.assertEquals( len( request.listOptions() ), 1 )
class SleepRequestTests( unittest.TestCase
, _RequestBaseTests
, ConformsToIRequest
, ConformsToISleepRequest
):
def _getTargetClass( self ):
from FunctionalTests.Request import SleepRequest
return SleepRequest
def _makeOne( self, name='sleep', *args, **kw ):
return self._getTargetClass()( name=name, *args, **kw )
def test_ctor_default( self ):
sr = self._makeOne( name='sleepy' )
self.assertEquals( sr.getName(), 'sleepy' )
self.assertEquals( sr.getSleepTime(), 1.0 )
def test_ctor_explicit( self ):
sr = self._makeOne( name='sleepy', sleep_time=2.0 )
self.assertEquals( sr.getName(), 'sleepy' )
self.assertEquals( sr.getSleepTime(), 2.0 )
def test_setSleepTime( self ):
sr = self._makeOne( name='sleepy' )
sr.setSleepTime( 3.0 )
self.assertEquals( sr.getSleepTime(), 3.0 )
def test___call__( self ):
import timing
SLEEP_TIME=0.5
sr = self._makeOne( name='sleepy', sleep_time=SLEEP_TIME )
self.assertEquals( sr.getSleepTime(), SLEEP_TIME )
timing.start() # initialize timer
sr( result=None )
timing.finish()
seconds = timing.milli() / 1000.0
delta = abs( seconds - SLEEP_TIME )
self.failUnless( delta < 0.01 )
class HTTPRequestTests( unittest.TestCase
, _RequestBaseTests
, ConformsToIRequest
, ConformsToIHTTPRequest
):
def _getTargetClass( self ):
from FunctionalTests.Request import HTTPRequest
return HTTPRequest
def _makeOne( self, name='http', URL='http://example.com', *args, **kw ):
return self._getTargetClass()( name=name, URL=URL, *args, **kw )
# TODO: test actual API
class ZEORequestTests( unittest.TestCase
, _RequestBaseTests
, ConformsToIRequest
, ConformsToIZEORequest
):
def _getTargetClass( self ):
from FunctionalTests.Request import ZEORequest
return ZEORequest
def _makeOne( self, name='zeo', filename='zeo_test', function='zeo_test'
, *args, **kw ):
return self._getTargetClass()( name=name
, filename=filename
, function=function
, *args
, **kw
)
# TODO: test actual API
def test_suite():
suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite( PluginFunctionTests ) )
suite.addTest( unittest.makeSuite( SleepRequestTests ) )
suite.addTest( unittest.makeSuite( HTTPRequestTests ) )
suite.addTest( unittest.makeSuite( ZEORequestTests ) )
return suite
if __name__ == '__main__':
unittest.main()
=== Packages/FunctionalTests/FunctionalTests/tests/test_all.py 1.1 => 1.2 ===
--- Packages/FunctionalTests/FunctionalTests/tests/test_all.py:1.1 Thu Apr 24 17:39:52 2003
+++ Packages/FunctionalTests/FunctionalTests/tests/test_all.py Sat May 31 15:10:07 2003
@@ -1,11 +1,13 @@
import unittest
from FunctionalTests.tests import test_ConfigParserExt
+from FunctionalTests.tests import test_Request
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_Request.test_suite() )
suite.addTest( test_Result.test_suite() )
suite.addTest( test_Scenario.test_suite() )
return suite