Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |