[py-svn] r61723 - in py/branch/pytestplugin/py/test: . plugin testing

hpk at codespeak.net hpk at codespeak.net
Wed Feb 11 13:54:31 CET 2009


Author: hpk
Date: Wed Feb 11 13:54:28 2009
New Revision: 61723

Modified:
   py/branch/pytestplugin/py/test/collect.py
   py/branch/pytestplugin/py/test/config.py
   py/branch/pytestplugin/py/test/plugin/conftest.py
   py/branch/pytestplugin/py/test/plugin/pytest_unittest.py
   py/branch/pytestplugin/py/test/pycollect.py
   py/branch/pytestplugin/py/test/testing/test_collect.py
   py/branch/pytestplugin/py/test/testing/test_deprecated_api.py
Log:
simplify collection api by substituting the 
passing around of "usefilters" args 
with a direct check if files were specified on the cmdline


Modified: py/branch/pytestplugin/py/test/collect.py
==============================================================================
--- py/branch/pytestplugin/py/test/collect.py	(original)
+++ py/branch/pytestplugin/py/test/collect.py	Wed Feb 11 13:54:28 2009
@@ -409,40 +409,47 @@
             return l 
         l = []
         for path in self.fspath.listdir(sort=True): 
-            res = self.consider(path, usefilters=True)
+            res = self.consider(path)
             if res is not None:
                 l.append(res)
         return l
 
-    def consider(self, path, usefilters=True):
+    def consider(self, path):
         if path.check(file=1):
-            return self.consider_file(path, usefilters=usefilters)
+            return self.consider_file(path)
         elif path.check(dir=1):
-            return self.consider_dir(path, usefilters=usefilters)
+            return self.consider_dir(path)
 
-    def consider_file(self, path, usefilters=True):
+    def consider_file(self, path):
         ext = path.ext 
         pb = path.purebasename
-        if not usefilters or pb.startswith("test_") or pb.endswith("_test"):
+        if pb.startswith("test_") or pb.endswith("_test") or \
+           path in self._config.args:
             if ext == ".py":
                 return self.Module(path, parent=self) 
             elif ext == ".txt":
                 return self.DoctestFile(path, parent=self)
 
-    def consider_dir(self, path, usefilters=True):
-        if not usefilters or self.recfilter(path):
-            # not use self.Directory here as 
-            # dir/conftest.py shall be able to 
-            # define Directory(dir) already 
-            Directory = self._config.getvalue('Directory', path) 
-            return Directory(path, parent=self) 
+    def consider_dir(self, path):
+        if not self.recfilter(path):
+            # check if cmdline specified this dir or a subdir
+            for arg in self._config.args:
+                if path == arg or arg.relto(path):
+                    break
+            else:
+                return
+        # not use self.Directory here as 
+        # dir/conftest.py shall be able to 
+        # define Directory(dir) already 
+        Directory = self._config.getvalue('Directory', path) 
+        return Directory(path, parent=self) 
 
     def collect_by_name(self, name):
         """ get a child with the given name. """ 
         res = super(Directory, self).collect_by_name(name)
         if res is None:
             p = self.fspath.join(name)
-            res = self.consider(p, usefilters=False)
+            res = self.consider(p)
         return res
 
 from py.__.test.runner import basic_run_report, forked_run_report

Modified: py/branch/pytestplugin/py/test/config.py
==============================================================================
--- py/branch/pytestplugin/py/test/config.py	(original)
+++ py/branch/pytestplugin/py/test/config.py	Wed Feb 11 13:54:28 2009
@@ -55,7 +55,7 @@
         if not args:
             args.append(py.std.os.getcwd())
         self.topdir = gettopdir(args)
-        self.args = args 
+        self.args = [py.path.local(x) for x in args]
 
     # config objects are usually pickled across system
     # barriers but they contain filesystem paths. 

Modified: py/branch/pytestplugin/py/test/plugin/conftest.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/conftest.py	(original)
+++ py/branch/pytestplugin/py/test/plugin/conftest.py	Wed Feb 11 13:54:28 2009
@@ -3,6 +3,6 @@
 pytest_plugins = "pytest_pytester", "pytest_plugintester"
 
 class Directory(py.test.collect.Directory):
-    def consider_file(self, path, usefilters):
+    def consider_file(self, path):
         if path.basename.startswith("pytest_") and path.ext == ".py":
             return self.Module(path, parent=self)

Modified: py/branch/pytestplugin/py/test/plugin/pytest_unittest.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/pytest_unittest.py	(original)
+++ py/branch/pytestplugin/py/test/plugin/pytest_unittest.py	Wed Feb 11 13:54:28 2009
@@ -74,7 +74,7 @@
     plugintester.apicheck()
 
 def test_simple_unittest(fstester):
-    test_one = fstester.makepyfile(test_one="""
+    testpath = fstester.makepyfile(test_simple_unittest="""
         import unittest
         pytest_plugins = "pytest_unittest" # XXX 
         class MyTestCase(unittest.TestCase):
@@ -83,12 +83,12 @@
             def test_failing(self):
                 self.assertEquals('foo', 'bar')
     """)
-    sorter = fstester.parse_and_run(test_one)
+    sorter = fstester.parse_and_run(testpath)
     assert sorter.getreport("testpassing").passed
     assert sorter.getreport("test_failing").failed 
 
 def test_setup(fstester):
-    test_one = fstester.makepyfile(test_two="""
+    testpath = fstester.makepyfile(test_two="""
         import unittest
         pytest_plugins = "pytest_unittest" # XXX 
         class MyTestCase(unittest.TestCase):
@@ -97,7 +97,7 @@
             def test_setUp(self):
                 self.assertEquals(1, self.foo)
     """)
-    sorter = fstester.parse_and_run(test_one)
+    sorter = fstester.parse_and_run(testpath)
     rep = sorter.getreport("test_setUp")
     assert rep.passed
 

Modified: py/branch/pytestplugin/py/test/pycollect.py
==============================================================================
--- py/branch/pytestplugin/py/test/pycollect.py	(original)
+++ py/branch/pytestplugin/py/test/pycollect.py	Wed Feb 11 13:54:28 2009
@@ -136,18 +136,18 @@
             warnoldcollect()
             return self.join(name)
 
-    def makeitem(self, name, obj, usefilters=True):
+    def makeitem(self, name, obj):
         res = self._config.pluginmanager.callfirst(
             "pytest_pymodule_makeitem", modcol=self, name=name, obj=obj)
         if res is not None:
             return res
-        if (not usefilters or self.classnamefilter(name)) and \
+        if (self.classnamefilter(name)) and \
             py.std.inspect.isclass(obj):
             res = self._deprecated_join(name)
             if res is not None:
                 return res 
             return self.Class(name, parent=self)
-        elif (not usefilters or self.funcnamefilter(name)) and callable(obj): 
+        elif self.funcnamefilter(name) and callable(obj): 
             res = self._deprecated_join(name)
             if res is not None:
                 return res 

Modified: py/branch/pytestplugin/py/test/testing/test_collect.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_collect.py	(original)
+++ py/branch/pytestplugin/py/test/testing/test_collect.py	Wed Feb 11 13:54:28 2009
@@ -12,6 +12,7 @@
     def __init__(self):
         self._conftest = Conftest()
         self._setupstate = SetupState()
+        self.args = []
         class dummyoption:
             nomagic = False
         self.option = dummyoption
@@ -290,10 +291,10 @@
             class MyFunction(py.test.collect.Function):
                 pass
             class Directory(py.test.collect.Directory):
-                def consider_file(self, path, usefilters=True):
+                def consider_file(self, path):
                     if path.check(fnmatch="check_*.py"):
                         return self.Module(path, parent=self)
-                    return super(Directory, self).consider_file(path, usefilters=usefilters)
+                    return super(Directory, self).consider_file(path)
             class myfuncmixin: 
                 Function = MyFunction
                 def funcnamefilter(self, name): 
@@ -340,7 +341,7 @@
                 def run(self):
                     pass
             class Directory(py.test.collect.Directory):
-                def consider_file(self, fspath, usefilters=True):
+                def consider_file(self, fspath):
                     if fspath.ext == ".xxx":
                         return CustomItem(fspath.basename, parent=self)
         """)

Modified: py/branch/pytestplugin/py/test/testing/test_deprecated_api.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_deprecated_api.py	(original)
+++ py/branch/pytestplugin/py/test/testing/test_deprecated_api.py	Wed Feb 11 13:54:28 2009
@@ -143,10 +143,10 @@
                 def run(self):
                     return []
             class Directory(py.test.collect.Directory):
-                def consider_file(self, path, usefilters=True):
+                def consider_file(self, path):
                     if path.basename == "testme.xxx":
                         return Module(path, parent=self)
-                    return super(Directory, self).consider_file(path, usefilters=usefilters)
+                    return super(Directory, self).consider_file(path)
         """)
         testme = self._makefile('xxx', testme="hello")
         config = self.parseconfig(testme)



More information about the pytest-commit mailing list