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

antocuni at codespeak.net antocuni at codespeak.net
Mon May 19 17:55:27 CEST 2008


Author: antocuni
Date: Mon May 19 17:55:25 2008
New Revision: 54950

Modified:
   pypy/django/tests/conftest.py
Log:
(antocuni, fijal) (IN-PROGRESS) more conftest



Modified: pypy/django/tests/conftest.py
==============================================================================
--- pypy/django/tests/conftest.py	(original)
+++ pypy/django/tests/conftest.py	Mon May 19 17:55:25 2008
@@ -47,25 +47,42 @@
 
 loaded_apps = {}
 
-class Directory(py.test.collect.Directory):
-    
+class Module(py.test.collect.Module):
     def run(self):
-        rel = self.fspath.relto(rootdir)
-        if not rel:
-            self.level = 0
-            return self.run0()
-        lgt = rel.count(os.path.sep)
-        if lgt == 0:
-            self.level = 1
-            return self.run1()
+        from django.conf import settings
+        mod = self._get_mod()
+        result = self._tests_from_mod(mod)
+        modpath = py.path.local(mod.__file__)
+        for name in ['tests', 'tests.py']:
+            path = modpath.join('..', name)
+            if path.check():
+                testmod = path.pyimport()
+                mod.tests = testmod
+                result += ['tests.' + i for i in self._tests_from_mod(testmod)]
+        return result
+
+    def _tests_from_mod(self, mod):
+        result = []
+        if hasattr(mod, 'suite'):
+            import pdb
+            pdb.set_trace()
         else:
-            self.level = 2
-            return self.run2()
+            items = [k for k, v in
+                     mod.__dict__.iteritems()
+                     if isinstance(v, type) and
+                     issubclass(v, unittest.TestCase)]
+            result += items
+        result += self._find_doctests(mod)
+        return result
 
-    def run2(self):
-        from django.conf import settings
+    def _find_doctests(self, mod):
+        if hasattr(mod, '__test__') and mod.__test__.get('API_TESTS'):
+            return ['%docstring%']
+            #return [)]
+        return []
+
+    def _get_mod(self):
         from django.db.models.loading import load_app
-        from django.test.simple import build_suite
         rel = self.fspath.relto(rootdir)
         app_name = rel.replace(os.path.sep, '.')
         if app_name in loaded_apps:
@@ -76,16 +93,36 @@
             if mod:
                 if app_name not in settings.INSTALLED_APPS:
                     settings.INSTALLED_APPS.append(app_name)
+        return mod
 
-        if hasattr(mod, '__test__') and mod.__test__.get('API_TESTS'):
-            return [DocTestItem(self.fspath.basename + '.docstring', mod, mod.__test__['API_TESTS'])]
-        return []
-        #suite = build_suite(mod)
-        #x = suite._tests[1]._tests[0]
-        #return [x]
-        #return suite._tests
-        # modify the global settings
+    def join(self, name):
+        mod = self._get_mod()
+        if name == '%docstring%':
+            return DocTestItem(self.fspath.basename + '.%docstring%', mod, mod.__test__['API_TESTS'])
+        elif name == 'tests.%docstring%':
+            mod = mod.tests
+            return DocTestItem(self.fspath.basename + '.%docstring%', mod, mod.__test__['API_TESTS'])
+        elif name.startswith('tests'):
+            return getattr(mod.tests, name[len('tests.'):])
+        else:
+            return getattr(mod, name)
 
+class Directory(py.test.collect.Directory):
+    def _level(self):
+        rel = self.fspath.relto(rootdir)
+        if not rel:
+            return 0
+        lgt = rel.count(os.path.sep)
+        if lgt == 0:
+            return 1
+        else:
+            assert 0
+    
+    def run(self):
+        level = self._level()
+        meth = getattr(self, 'run%d' % level)
+        return meth()
+    
     def run1(self):
         models = []
         for model in self.fspath.listdir():
@@ -100,12 +137,11 @@
     def run0(self):
         return DIRNAMES
 
-    def join(self, name_or_item):
-        if isinstance(name_or_item, py.test.collect.Item):
-            return name_or_item
-        name = name_or_item
+    def join(self, name):
         path = self.fspath.join(name)
         if path.check(dir=1):
+            if self._level() == 1:
+                return Module(self.fspath.join(name))
             return Directory(self.fspath.join(name))
         else:
             raise NotImplementedError



More information about the Pypy-commit mailing list