]> granicus.if.org Git - yasm/commitdiff
* python-yasm: Add test framework; large portions copied from Quod Libet
authorPeter Johnson <peter@tortall.net>
Mon, 17 Apr 2006 02:04:00 +0000 (02:04 -0000)
committerPeter Johnson <peter@tortall.net>
Mon, 17 Apr 2006 02:04:00 +0000 (02:04 -0000)
framework.

svn path=/trunk/yasm/; revision=1497

tools/python-yasm/Makefile.inc
tools/python-yasm/tests/Makefile.inc [new file with mode: 0644]
tools/python-yasm/tests/__init__.py [new file with mode: 0644]
tools/python-yasm/tests/python_test.sh [new file with mode: 0755]
tools/python-yasm/tests/test_symrec.py [new file with mode: 0644]

index 76298cf8b2a02978a03560236fb3be57b32fe115..04545d03b3665abd3bdbbf6f397c1754e327ae9f 100644 (file)
@@ -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 (file)
index 0000000..440d4e1
--- /dev/null
@@ -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 (file)
index 0000000..ed76de6
--- /dev/null
@@ -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 (executable)
index 0000000..9f39782
--- /dev/null
@@ -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 (file)
index 0000000..9489d99
--- /dev/null
@@ -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")