[Checkins] SVN: z3c.testing/trunk/src/z3c/testing/ Added testing
package
Roger Ineichen
roger at projekt01.ch
Mon Aug 21 07:13:51 EDT 2006
Log message for revision 69714:
Added testing package
Changed:
A z3c.testing/trunk/src/z3c/testing/
A z3c.testing/trunk/src/z3c/testing/__init__.py
A z3c.testing/trunk/src/z3c/testing/app.py
A z3c.testing/trunk/src/z3c/testing/directive.py
A z3c.testing/trunk/src/z3c/testing/tests.py
-=-
Added: z3c.testing/trunk/src/z3c/testing/__init__.py
===================================================================
--- z3c.testing/trunk/src/z3c/testing/__init__.py 2006-08-21 11:11:24 UTC (rev 69713)
+++ z3c.testing/trunk/src/z3c/testing/__init__.py 2006-08-21 11:13:50 UTC (rev 69714)
@@ -0,0 +1,23 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+$Id$
+"""
+
+from z3c.testing.app import TestCase
+from z3c.testing.app import InterfaceBaseTest
+from z3c.testing.app import marker_pos
+from z3c.testing.app import marker_kws
+from z3c.testing.directive import registerDirective
+from z3c.testing.directive import setUpContentMetaDirectives
Property changes on: z3c.testing/trunk/src/z3c/testing/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: z3c.testing/trunk/src/z3c/testing/app.py
===================================================================
--- z3c.testing/trunk/src/z3c/testing/app.py 2006-08-21 11:11:24 UTC (rev 69713)
+++ z3c.testing/trunk/src/z3c/testing/app.py 2006-08-21 11:13:50 UTC (rev 69714)
@@ -0,0 +1,83 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+$Id$
+"""
+
+import sys
+import unittest
+
+
+###############################################################################
+#
+# TestCase
+#
+###############################################################################
+marker_pos = object()
+marker_kws = object()
+
+class TestCase(unittest.TestCase):
+
+ def getTestInterface(self):
+ msg = 'Subclasses has to implement getTestInterface()'
+ raise NotImplementedError, msg
+
+ def getTestClass(self):
+ raise NotImplementedError, 'Subclasses has to implement getTestClass()'
+
+ def getTestPos(self):
+ return marker_pos
+
+ def getTestKws(self):
+ return marker_kws
+
+ def makeTestObject(self, object=None, *pos, **kws):
+ # provide default positional or keyword arguments
+ if self.getTestPos() is not marker_pos and not pos:
+ pos = self.getTestPos()
+
+ if self.getTestKws() is not marker_kws and not kws:
+ kws = self.getTestKws()
+
+ testclass = self.getTestClass()
+
+ if object is None:
+ # a class instance itself is the object to be tested.
+ return testclass(*pos, **kws)
+
+ else:
+ # an adapted instance is the object to be tested.
+ return testclass(object, *pos, **kws)
+
+
+###############################################################################
+#
+# Public Base Tests
+#
+###############################################################################
+from zope.interface.verify import verifyClass
+from zope.interface.verify import verifyObject
+
+
+class InterfaceBaseTest(TestCase):
+ """Base test for IContainer including interface test."""
+
+ def test_verifyClass(self):
+ # class test
+ self.assert_(verifyClass(self.getTestInterface(), self.getTestClass()))
+
+ def test_verifyObject(self):
+ # object test
+ self.assert_(verifyObject(self.getTestInterface(),
+ self.makeTestObject()))
Property changes on: z3c.testing/trunk/src/z3c/testing/app.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: z3c.testing/trunk/src/z3c/testing/directive.py
===================================================================
--- z3c.testing/trunk/src/z3c/testing/directive.py 2006-08-21 11:11:24 UTC (rev 69713)
+++ z3c.testing/trunk/src/z3c/testing/directive.py 2006-08-21 11:13:50 UTC (rev 69714)
@@ -0,0 +1,47 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+$Id$
+"""
+
+from cStringIO import StringIO
+
+from zope.configuration.xmlconfig import xmlconfig
+from zope.configuration.xmlconfig import XMLConfig
+
+
+
+# helper for directive testing
+template = """<configure
+ xmlns='http://namespaces.zope.org/zope'
+ xmlns:browser='http://namespaces.zope.org/browser'
+ xmlns:test='http://www.zope.org/NS/Zope3/test'
+ i18n_domain='z3c'>
+ %s
+ </configure>"""
+
+
+def registerDirective(directive, template=template):
+ xmlconfig(StringIO(template % directive))
+
+
+
+# Zope (content) Meta Directives
+#-----------------------------------------------------------------------------
+import zope.component
+import zope.app.security
+
+def setUpContentMetaDirectives():
+ XMLConfig('meta.zcml', zope.component)()
+ XMLConfig('meta.zcml', zope.app.security)()
Property changes on: z3c.testing/trunk/src/z3c/testing/directive.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: z3c.testing/trunk/src/z3c/testing/tests.py
===================================================================
--- z3c.testing/trunk/src/z3c/testing/tests.py 2006-08-21 11:11:24 UTC (rev 69713)
+++ z3c.testing/trunk/src/z3c/testing/tests.py 2006-08-21 11:13:50 UTC (rev 69714)
@@ -0,0 +1,48 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+$Id$
+"""
+
+import unittest
+import zope.interface
+
+from z3c import testing
+
+
+class ISample(zope.interface.Interface):
+ """Sample interface."""
+
+class Sample(object):
+ """Sample object."""
+
+ zope.interface.implements(ISample)
+
+
+class TestTestCase(testing.InterfaceBaseTest):
+
+ def getTestClass(self):
+ return Sample
+
+ def getTestInterface(self):
+ return ISample
+
+
+def test_suite():
+ return unittest.TestSuite((
+ unittest.makeSuite(TestTestCase),
+ ))
+
+if __name__=='__main__':
+ unittest.main(defaultTest='test_suite')
Property changes on: z3c.testing/trunk/src/z3c/testing/tests.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the Checkins
mailing list