Split out borg doctests and test classes so they work properly with trial

This commit is contained in:
Chris Jones 2010-01-14 23:03:47 +00:00
parent 375d272ee8
commit fb0beb42f3
4 changed files with 57 additions and 53 deletions

View File

@ -3,3 +3,4 @@ terminatorlib/*.pyc
.project .project
.pydevproject .pydevproject
terminatorlib/meliae terminatorlib/meliae
_trial_temp

View File

@ -6,30 +6,6 @@
ActiveState's policy appears to be that snippets ActiveState's policy appears to be that snippets
exist to encourage re-use, but I can not find any exist to encourage re-use, but I can not find any
specific licencing terms. specific licencing terms.
>>> obj1 = TestBorg()
>>> obj2 = TestBorg()
>>> obj1.attribute
0
>>> obj2.attribute
0
>>> obj1.attribute = 12345
>>> obj1.attribute
12345
>>> obj2.attribute
12345
>>> obj2.attribute = 54321
>>> obj1.attribute
54321
>>> obj3 = TestBorg2()
>>> obj3.attribute
1
>>> obj4 = TestBorg2()
>>> obj3.attribute = 98765
>>> obj4.attribute
98765
>>>
""" """
from util import dbg from util import dbg
@ -77,31 +53,3 @@ class Borg:
"""This should be used to prepare any attributes of the borg class.""" """This should be used to prepare any attributes of the borg class."""
raise NotImplementedError('prepare_attributes') raise NotImplementedError('prepare_attributes')
if __name__ == '__main__':
class TestBorg(Borg):
attribute = None
def __init__(self):
Borg.__init__(self, self.__class__.__name__)
self.prepare_attributes()
def prepare_attributes(self):
if not self.attribute:
self.attribute = 0
class TestBorg2(Borg):
attribute = None
def __init__(self):
Borg.__init__(self, self.__class__.__name__)
self.prepare_attributes()
def prepare_attributes(self):
if not self.attribute:
self.attribute = 1
import sys
import doctest
(failed, attempted) = doctest.testmod()
print "%d/%d tests failed" % (failed, attempted)
sys.exit(failed)

55
terminatorlib/testborg.py Executable file
View File

@ -0,0 +1,55 @@
#!/usr/bin/python
# Terminator by Chris Jones <cmsj@tenshu.net>
# GPL v2 only
"""testborg.py - We are the borg. Resistance is futile.
doctests for borg.py
>>> obj1 = TestBorg()
>>> obj2 = TestBorg()
>>> obj1.attribute
0
>>> obj2.attribute
0
>>> obj1.attribute = 12345
>>> obj1.attribute
12345
>>> obj2.attribute
12345
>>> obj2.attribute = 54321
>>> obj1.attribute
54321
>>> obj3 = TestBorg2()
>>> obj3.attribute
1
>>> obj4 = TestBorg2()
>>> obj3.attribute = 98765
>>> obj4.attribute
98765
>>>
"""
from borg import Borg
class TestBorg(Borg):
attribute = None
def __init__(self):
Borg.__init__(self, self.__class__.__name__)
self.prepare_attributes()
def prepare_attributes(self):
if not self.attribute:
self.attribute = 0
class TestBorg2(Borg):
attribute = None
def __init__(self):
Borg.__init__(self, self.__class__.__name__)
self.prepare_attributes()
def prepare_attributes(self):
if not self.attribute:
self.attribute = 1

View File

@ -7,7 +7,7 @@ def test_suite():
for name in ( for name in (
'config', 'config',
'plugin', 'plugin',
'borg', 'testborg',
): ):
suite.addTest(DocTestSuite('terminatorlib.' + name)) suite.addTest(DocTestSuite('terminatorlib.' + name))
return suite return suite