tests: Make tests easier to run at a package level
Add a run_tests script. Move tests subdir to top level. Force terminatorlib into path for tests. As of this commit, all tests pass: ~/src/Terminator/terminator$ ./run_tests tests/testborg.py tests/test_doctests.py tests/testsignalman.py 0/14 tests failed
This commit is contained in:
parent
d103bb1b7b
commit
0f201ade0f
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
for t in tests/test*; do
|
||||
echo $t
|
||||
file_type=$(file -b $t)
|
||||
case ${file_type} in
|
||||
*[Pp]ython*) python ${t} ;;
|
||||
*Bourne*) bash ${t} ;;
|
||||
*bash*) bash ${t} ;;
|
||||
*perl*) perl ${t} ;;
|
||||
*) echo "Unknown" ;;
|
||||
esac
|
||||
echo
|
||||
done
|
|
@ -0,0 +1,22 @@
|
|||
"""Load up the tests."""
|
||||
|
||||
import os
|
||||
import sys, os.path
|
||||
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), "..")))
|
||||
|
||||
from unittest import TestSuite
|
||||
from doctest import DocTestSuite, ELLIPSIS
|
||||
|
||||
def test_suite():
|
||||
suite = TestSuite()
|
||||
for name in (
|
||||
'config',
|
||||
'plugin',
|
||||
'cwd',
|
||||
'factory',
|
||||
'util',
|
||||
'tests.testborg',
|
||||
'tests.testsignalman',
|
||||
):
|
||||
suite.addTest(DocTestSuite('terminatorlib.' + name))
|
||||
return suite
|
|
@ -0,0 +1,59 @@
|
|||
#!/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
|
||||
>>>
|
||||
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys, os.path
|
||||
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), "..")))
|
||||
|
||||
from terminatorlib.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
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/python
|
||||
# Terminator by Chris Jones <cmsj@tenshu.net>
|
||||
# GPL v2 only
|
||||
"""testsignalman.py - Test the signalman class
|
||||
|
||||
>>> widget = TestWidget()
|
||||
>>> signalman = Signalman()
|
||||
>>> signalman.new(widget, 'test1', handler)
|
||||
1
|
||||
>>> signalman.cnxids[widget].keys()
|
||||
['test1']
|
||||
>>> widget.signals.values()
|
||||
['test1']
|
||||
>>> signalman.remove_widget(widget)
|
||||
>>> signalman.cnxids.has_key(widget)
|
||||
False
|
||||
>>> widget.signals.values()
|
||||
[]
|
||||
>>> signalman.new(widget, 'test2', handler)
|
||||
2
|
||||
>>> signalman.new(widget, 'test3', handler)
|
||||
3
|
||||
>>> signalman.remove_signal(widget, 'test2')
|
||||
>>> signalman.cnxids[widget].keys()
|
||||
['test3']
|
||||
>>> widget.signals.values()
|
||||
['test3']
|
||||
>>> signalman.remove_widget(widget)
|
||||
>>>
|
||||
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys, os.path
|
||||
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), "..")))
|
||||
|
||||
from terminatorlib.signalman import Signalman
|
||||
|
||||
class TestWidget():
|
||||
signals = None
|
||||
count = None
|
||||
|
||||
def __init__(self):
|
||||
self.signals = {}
|
||||
self.count = 0
|
||||
|
||||
def connect(self, signal, handler, *args):
|
||||
self.count = self.count + 1
|
||||
self.signals[self.count] = signal
|
||||
return(self.count)
|
||||
|
||||
def disconnect(self, signalid):
|
||||
del(self.signals[signalid])
|
||||
|
||||
def handler():
|
||||
print "I am a test handler"
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
import doctest
|
||||
(failed, attempted) = doctest.testmod()
|
||||
print "%d/%d tests failed" % (failed, attempted)
|
||||
sys.exit(failed)
|
Loading…
Reference in New Issue