[pypy-svn] r55011 - pypy/django/tests

hpk at codespeak.net hpk at codespeak.net
Tue May 20 16:49:25 CEST 2008


Author: hpk
Date: Tue May 20 16:49:24 2008
New Revision: 55011

Modified:
   pypy/django/tests/conftest.py
Log:
find plain docstrings in test modules, try to improve support for "invalid model test cases"


Modified: pypy/django/tests/conftest.py
==============================================================================
--- pypy/django/tests/conftest.py	(original)
+++ pypy/django/tests/conftest.py	Tue May 20 16:49:24 2008
@@ -1,14 +1,21 @@
 
 import py
 import os
+import sys
 
-# XXX ignores invalid models path
+# XXX after invalid model tests the testing process bails out! 
 # XXX no django/contrib
 
 rootdir = py.path.local(__file__).dirpath()
 pkgroot = rootdir.dirpath()
-if str(pkgroot) not in py.std.sys.path: 
-    py.std.sys.path.append(str(pkgroot))
+if str(pkgroot) not in sys.path: 
+    sys.path.append(str(pkgroot))
+
+# allows us to import from runtests 
+if str(rootdir) not in sys.path:
+    sys.path.append(str(rootdir))
+from runtests import InvalidModelTestCase 
+        
 
 DIRNAMES = ['modeltests', 'regressiontests']#, 'django/contrib']
 
@@ -63,7 +70,10 @@
 
     def _tests_from_mod(self, mod):
         result = []
-        if hasattr(mod, 'suite'):
+        # "invalid" test case 
+        if self.name.startswith("invalid"):
+            return ["%invalidtestcase%"]
+        elif hasattr(mod, 'suite'):
             s = mod.suite()
             namemethods = getmethods2(s) 
             meth = []
@@ -85,6 +95,8 @@
     def _find_doctests(self, mod):
         if hasattr(mod, '__test__') and mod.__test__.get('API_TESTS'):
             return ['%docstring%']
+        if os.path.basename(mod.__file__).startswith("tests") and mod.__doc__:
+            return ['%docmodulestring%']
             #return [)]
         return []
 
@@ -110,11 +122,22 @@
         elif name == 'tests.%docstring%':
             mod = mod.tests
             return DocTestItem(self.fspath.basename + '.%docstring%', mod, mod.__test__['API_TESTS'])
+        elif name == '%docmodulestring%':
+            return DocTestItem(self.fspath.basename + '.%docstring%', mod, mod.__doc__)
+        elif name == 'tests.%docmodulestring%':
+            return DocTestItem(self.fspath.basename + '.test.%docstring%', mod, mod.__doc__)
+        elif name == '%invalidtestcase%':
+            return DjangoInvalidModelTestCase(name, self) 
         elif name.startswith('tests'):
             return DjangoUnitTest(name, self) 
         else:
             return DjangoUnitTest(name, self) 
 
+class DjangoInvalidModelTestCase(py.test.collect.Item):
+    def run(self):
+        testcase = InvalidModelTestCase(self.parent.name)
+        run_testcase_method(testcase) 
+        
 class DjangoUnitTest(py.test.collect.Item):
     def run(self):
         names = self.name.split(".")
@@ -151,7 +174,7 @@
         models = []
         for model in self.fspath.listdir():
             f = str(model.basename)
-            if f.startswith('__init__') or f.startswith('.') or f.startswith('sql') or f.startswith('invalid'):
+            if f.startswith('__init__') or f.startswith('.') or f.startswith('sql'): # or f.startswith("invalid"):
                 pass
             else:
                 models.append(f)
@@ -216,8 +239,6 @@
 Directory = DjangoTestDirectory
 Module = DjangoTestModule
 
-# the below taken from pypy/lib-python/conftest.py 
-
 def getmethodnames(cls):
     l = []
     for name, obj in vars(cls).items():
@@ -241,8 +262,6 @@
         raise TypeError, "expected TestSuite or TestClass, got %r"  %(suite_or_class) 
     return res 
 
-
-
 def run_testcase_method(method): 
     result = method.defaultTestResult() 
     method.run(result)



More information about the Pypy-commit mailing list