Sfoglia il codice sorgente

Added basic testing framework files.

Taddeus Kroes 13 anni fa
commit
44d577741d
3 ha cambiato i file con 34 aggiunte e 0 eliminazioni
  1. 3 0
      .gitignore
  2. 9 0
      Makefile
  3. 22 0
      test.py

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+*.pyc
+*.swp
+*~

+ 9 - 0
Makefile

@@ -0,0 +1,9 @@
+TEST := test.py
+
+test:
+	@pyrg $(TEST)
+
+clean:
+	rm `find -name \*.pyc`
+
+.PHONY: test clean

+ 22 - 0
test.py

@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+import os
+import re
+import sys
+import unittest
+
+
+TESTS_DIR = 'tests'
+
+matches = [re.match('^(test_(\w+)).\py$', f) for f in os.listdir(TESTS_DIR)]
+suite = unittest.TestSuite()
+loader = unittest.TestLoader()
+
+for match in filter(None, matches):
+    modulename, testname = match.groups()
+    classname = re.sub('(?:^|_)([a-z])', lambda m: m.group(1).upper(),
+                        testname) + 'Test'
+    mod = __import__(TESTS_DIR + '.' + modulename, globals(), locals(),
+                     classname)
+    suite.addTests(loader.loadTestsFromTestCase(getattr(mod, classname)))
+
+unittest.TextTestRunner().run(suite)