(trunk-1565/1566) distcheck fix and improvements to tests

This commit is contained in:
Stephen Boddy 2015-06-23 02:34:24 +02:00
parent 29a412ee0f
commit fd0225893b
4 changed files with 158 additions and 0 deletions

14
run_tests Executable file
View File

@ -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

22
tests/test_doctests.py Normal file
View File

@ -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

59
tests/testborg.py Executable file
View File

@ -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

63
tests/testsignalman.py Executable file
View File

@ -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)