Skip to content

Commit

Permalink
Added testing package
Browse files Browse the repository at this point in the history
  • Loading branch information
projekt01 committed Aug 21, 2006
1 parent 81c9a7a commit 9f11b01
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/z3c/testing/__init__.py
@@ -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
83 changes: 83 additions & 0 deletions src/z3c/testing/app.py
@@ -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()))
47 changes: 47 additions & 0 deletions src/z3c/testing/directive.py
@@ -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)()
48 changes: 48 additions & 0 deletions src/z3c/testing/tests.py
@@ -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')

0 comments on commit 9f11b01

Please sign in to comment.