Skip to content

Commit

Permalink
Do some InterfaceBaseTest attributes to be able to write less code
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Groszer committed Feb 17, 2010
1 parent 10000fd commit eb8dda5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
6 changes: 5 additions & 1 deletion CHANGES.txt
Expand Up @@ -5,7 +5,11 @@ CHANGES
0.3.2 (unreleased)
------------------

- Nothing changed yet.
- Do some ``InterfaceBaseTest`` attributes to be able to write less code:
- ``iface`` provide the interface here
- ``klass`` provide the class here
- ``pos`` provide the positional arguments here
- ``kws`` provide the keyword arguments here


0.3.1 (2009-12-26)
Expand Down
38 changes: 25 additions & 13 deletions src/z3c/testing/app.py
Expand Up @@ -28,35 +28,47 @@

class TestCase(unittest.TestCase):

iface = None
klass = None
pos = marker_pos
kws = marker_kws

def getTestInterface(self):
if self.iface is not None:
return self.iface

msg = 'Subclasses has to implement getTestInterface()'
raise NotImplementedError, msg

def getTestClass(self):
if self.klass is not None:
return self.klass

raise NotImplementedError, 'Subclasses has to implement getTestClass()'

def getTestPos(self):
return marker_pos
return self.pos

def getTestKws(self):
return marker_kws
return self.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()
ourpos = self.getTestPos()
if ourpos is not marker_pos and not pos:
pos = ourpos

ourkws = self.getTestKws()
if ourkws is not marker_kws and not kws:
kws = ourkws

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.
# a class instance itself is the object to be tested.
return testclass(*pos, **kws)

else:
# an adapted instance is the object to be tested.
# an adapted instance is the object to be tested.
return testclass(object, *pos, **kws)


Expand All @@ -74,11 +86,11 @@ class InterfaceBaseTest(TestCase):

def test_verifyClass(self):
# class test
self.assert_(verifyClass(self.getTestInterface(), self.getTestClass()))
self.assert_(verifyClass(self.getTestInterface(), self.getTestClass()))

def test_verifyObject(self):
# object test
self.assert_(verifyObject(self.getTestInterface(),
self.assert_(verifyObject(self.getTestInterface(),
self.makeTestObject()))


Expand Down

0 comments on commit eb8dda5

Please sign in to comment.