Update of /cvsroot/modeling/ProjectModeling/Modeling/tests
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1181/Modeling/tests
Modified Files:
run.py
Added Files:
test_delegation.py
Log Message:
* delegation.py: private methods and fields now begins w/ a simple
underscore, not two of them (+doc. updated)
* tests/test_delegation.py: added
Index: run.py
===================================================================
RCS file: /cvsroot/modeling/ProjectModeling/Modeling/tests/run.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** run.py 20 Jul 2004 06:21:57 -0000 1.10
--- run.py 2 Aug 2004 20:54:47 -0000 1.11
***************
*** 30,33 ****
--- 30,35 ----
+ #
+ import test_delegation
# Modeling Layer
import test_Model
***************
*** 81,84 ****
--- 83,87 ----
import test_CooperatingObjectStoreNeededNotification
suite.addTest(test_CooperatingObjectStoreNeededNotification.test_suite())
+ suite.addTest(test_delegation.test_suite())
suite.addTest(test_Model.test_suite())
suite.addTest(test_Entity.test_suite())
--- NEW FILE: test_delegation.py ---
#! /usr/bin/env python
# -*- coding: iso-8859-1 -*-
#-----------------------------------------------------------------------------
# Modeling Framework: an Object-Relational Bridge for python
#
# Copyright (c) 2001-2004 Sébastien Bigaret <sbi...@us...>
# All rights reserved.
#
# This file is part of the Modeling Framework.
#
# This code is distributed under a "3-clause BSD"-style license;
# see the LICENSE file for details.
#-----------------------------------------------------------------------------
"""
Tests for module delegation
CVS Information
$Id: test_delegation.py,v 1.1 2004/08/02 20:54:47 sbigaret Exp $
"""
__version__= '$Revision: 1.1 $'[11:-2]
import unittest
if __name__ == "__main__":
import utils, sys
utils.fixpath()
from Modeling.delegation import DelegateWrapper
# Classes for tests
class DelegateInterface:
"""
"""
def canTheWorldBeChanged(self):
"Indicates whether the world can be changed"
def shouldBeReset(self):
"-"
def willBeReset(self):
"-"
# def respondsTo(self):
# "-"
class Delegate:
def __init__(self):
self.resetCounter=0
def canTheWorldBeChanged(self, isElvisAlive=1):
"This method does NOT conform to the DelegateInterface"
return isElvisAlive and 'Ouaip' or 'Nope!'
def willBeReset(self):
"Side-effect: Increments self.resetCounter by one"
self.resetCounter+=1
def shouldBeReset(self):
"Always return true"
return 1
## Tests begin here
class TestDelegate(unittest.TestCase):
"Tests for module delegate"
def setUp(self):
"setUp"
self.delegateObject=Delegate()
self.delegate=DelegateWrapper(DelegateInterface, self.delegateObject)
def test_01_respondsTo(self):
"[delegate] respondsTo"
self.failUnless(self.delegate.respondsTo('shouldBeReset'))
self.failUnless(self.delegate.respondsTo('willBeReset'))
self.failIf(self.delegate.respondsTo('canTheWorldBeChanged'))
self.failIf(self.delegate.respondsTo('MinistryOfSillyWalksPostalAddress'))
def test_01_proxyForDelegateInterfaceMethods(self):
"[delegate] checks the DelegateWrapper's proxying mechanism"
self.failUnless(self.delegate.shouldBeReset()==1)
self.failIf(self.delegate.willBeReset()) # return None
self.failUnless(self.delegate.delegateObject().resetCounter==1)
try:
self.delegate.canTheWorldBeChanged(1)
except AttributeError:
pass
else:
self.fail('self.delegate.canTheWorldBeChanged should have raised')
# No automatic access to variable
self.assertRaises(AttributeError, getattr, self.delegate, 'resetCounter')
# Build the test suite
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestDelegate, "test_"))
return suite
if __name__ == "__main__":
errs = utils.run_suite(test_suite())
sys.exit(errs and 1 or 0)
|