From: Peter Johnson Date: Mon, 17 Apr 2006 02:04:00 +0000 (-0000) Subject: * python-yasm: Add test framework; large portions copied from Quod Libet X-Git-Tag: v0.5.0~17^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=83535bec11260c03fe5a15092364dcb90edd9766;p=yasm * python-yasm: Add test framework; large portions copied from Quod Libet framework. svn path=/trunk/yasm/; revision=1497 --- diff --git a/tools/python-yasm/Makefile.inc b/tools/python-yasm/Makefile.inc index 76298cf8..04545d03 100644 --- a/tools/python-yasm/Makefile.inc +++ b/tools/python-yasm/Makefile.inc @@ -1,5 +1,4 @@ # $Id$ -if HAVE_PYTHON PYBINDING_DEPS = tools/python-yasm/bytecode.pxi PYBINDING_DEPS += tools/python-yasm/coretype.pxi @@ -13,6 +12,8 @@ EXTRA_DIST += tools/python-yasm/setup.py EXTRA_DIST += tools/python-yasm/yasm.pyx EXTRA_DIST += $(PYBINDING_DEPS) +if HAVE_PYTHON + yasm_python.c: $(srcdir)/tools/python-yasm/yasm.pyx $(PYBINDING_DEPS) $(PYTHON) -c "from Pyrex.Compiler.Main import main; main(command_line=1)" \ -o $@ `test -f tools/python-yasm/yasm.pyx || echo '$(srcdir)/'`tools/python-yasm/yasm.pyx @@ -48,3 +49,6 @@ python-install: python-uninstall: endif + +EXTRA_DIST += tools/python-yasm/tests/Makefile.inc +include tools/python-yasm/tests/Makefile.inc diff --git a/tools/python-yasm/tests/Makefile.inc b/tools/python-yasm/tests/Makefile.inc new file mode 100644 index 00000000..440d4e1c --- /dev/null +++ b/tools/python-yasm/tests/Makefile.inc @@ -0,0 +1,11 @@ +# $Id$ + +EXTRA_DIST += tools/python-yasm/tests/python_test.sh +EXTRA_DIST += tools/python-yasm/tests/__init__.py +EXTRA_DIST += tools/python-yasm/tests/test_symrec.py + +if HAVE_PYTHON + +TESTS += tools/python-yasm/tests/python_test.sh + +endif diff --git a/tools/python-yasm/tests/__init__.py b/tools/python-yasm/tests/__init__.py new file mode 100644 index 00000000..ed76de61 --- /dev/null +++ b/tools/python-yasm/tests/__init__.py @@ -0,0 +1,67 @@ +# Test wrapper from Quod Libet +# http://www.sacredchao.net/quodlibet/ +# $Id$ +import unittest, sys +suites = [] +add = registerCase = suites.append +from unittest import TestCase + +class Mock(object): + # A generic mocking object. + def __init__(self, **kwargs): self.__dict__.update(kwargs) + +import test_symrec + +class Result(unittest.TestResult): + + separator1 = '=' * 70 + separator2 = '-' * 70 + + def addSuccess(self, test): + unittest.TestResult.addSuccess(self, test) + sys.stdout.write('.') + + def addError(self, test, err): + unittest.TestResult.addError(self, test, err) + sys.stdout.write('E') + + def addFailure(self, test, err): + unittest.TestResult.addFailure(self, test, err) + sys.stdout.write('F') + + def printErrors(self): + succ = self.testsRun - (len(self.errors) + len(self.failures)) + v = "%3d" % succ + count = 50 - self.testsRun + sys.stdout.write((" " * count) + v + "\n") + self.printErrorList('ERROR', self.errors) + self.printErrorList('FAIL', self.failures) + + def printErrorList(self, flavour, errors): + for test, err in errors: + sys.stdout.write(self.separator1 + "\n") + sys.stdout.write("%s: %s\n" % (flavour, str(test))) + sys.stdout.write(self.separator2 + "\n") + sys.stdout.write("%s\n" % err) + +class Runner: + def run(self, test): + suite = unittest.makeSuite(test) + pref = '%s (%d): ' % (test.__name__, len(suite._tests)) + print pref + " " * (25 - len(pref)), + result = Result() + suite(result) + result.printErrors() + return bool(result.failures + result.errors) + +def unit(run = []): + runner = Runner() + failures = False + for test in suites: + if not run or test.__name__ in run: + failures |= runner.run(test) + return failures + +if __name__ == "__main__": + raise SystemExit(unit(sys.argv[1:])) + diff --git a/tools/python-yasm/tests/python_test.sh b/tools/python-yasm/tests/python_test.sh new file mode 100755 index 00000000..9f39782c --- /dev/null +++ b/tools/python-yasm/tests/python_test.sh @@ -0,0 +1,17 @@ +#!/bin/sh +# Based on _sanity.sh from Quod Libet +# http://www.sacredchao.net/quodlibet/ +# $Id$ + +set -e + +if test "$1" = "--help" -o "$1" = "-h"; then + echo "Usage: $0 --sanity | [TestName] ..." + exit 0 +elif [ "$1" = "--sanity" ]; then + echo "Running static sanity checks." + grep "except None:" ${srcdir}/tools/python-yasm/tests/*.py +else + python -c "import sys; import glob; sys.path.insert(0, '${srcdir}/tools/python-yasm'); sys.path.insert(0, glob.glob('build/lib.*')[0]); import tests; raise SystemExit(tests.unit('$*'.split()))" +fi + diff --git a/tools/python-yasm/tests/test_symrec.py b/tools/python-yasm/tests/test_symrec.py new file mode 100644 index 00000000..9489d999 --- /dev/null +++ b/tools/python-yasm/tests/test_symrec.py @@ -0,0 +1,12 @@ +# $Id$ +from tests import TestCase, add +from yasm import SymbolTable + +class TSymbolTable(TestCase): + def test_keys(self): + symtab = SymbolTable() + self.failUnlessEqual(len(symtab.keys()), 0) + symtab.declare("foo") + keys = symtab.keys() + self.failUnlessEqual(len(keys), 1) + self.failUnlessEqual(keys[0], "foo")