[py-svn] r57309 - in py/branch/event/py/test: . testing

hpk at codespeak.net hpk at codespeak.net
Sat Aug 16 12:36:37 CEST 2008


Author: hpk
Date: Sat Aug 16 12:36:35 2008
New Revision: 57309

Modified:
   py/branch/event/py/test/pycollect.py
   py/branch/event/py/test/testing/test_collect.py
Log:
refine function equality, normalize its __init__


Modified: py/branch/event/py/test/pycollect.py
==============================================================================
--- py/branch/event/py/test/pycollect.py	(original)
+++ py/branch/event/py/test/pycollect.py	Sat Aug 16 12:36:35 2008
@@ -294,7 +294,7 @@
             if not callable(call): 
                 raise TypeError("%r yielded non callable test %r" %(self.obj, call,))
             name = "[%d]" % i  
-            d[name] = self.Function(name, self, args, callobj=call)
+            d[name] = self.Function(name, self, args=args, callobj=call)
         return d
         
     def getcallargs(self, obj):
@@ -312,8 +312,8 @@
     """ a Function Item is responsible for setting up  
         and executing a Python callable test object.
     """
-    def __init__(self, name, parent, args=(), callobj=_dummy):
-        super(Function, self).__init__(name, parent) 
+    def __init__(self, name, parent=None, config=None, args=(), callobj=_dummy):
+        super(Function, self).__init__(name, parent, config=config) 
         self._args = args
         if callobj is not _dummy: 
             self._obj = callobj 
@@ -322,6 +322,21 @@
         """ execute the given test function. """
         self.obj(*self._args)
 
+    def __eq__(self, other):
+        try:
+            return (self.name == other.name and 
+                    self._args == other._args and
+                    self.parent == other.parent and
+                    self.obj == other.obj)
+        except AttributeError:
+            pass
+        return False
+    def __ne__(self, other):
+        return not self == other
+
+    def __repr__(self):
+        return "<Function %r at %0x>"%(self.name, id(self))
+
 class DoctestFile(FSCollector): 
     def listdir(self):
         return [self.fspath.basename]

Modified: py/branch/event/py/test/testing/test_collect.py
==============================================================================
--- py/branch/event/py/test/testing/test_collect.py	(original)
+++ py/branch/event/py/test/testing/test_collect.py	Sat Aug 16 12:36:35 2008
@@ -283,6 +283,29 @@
         assert [1,2,3] != fn
         assert col != fn
 
+
+def test_function_equality():
+    config = py.test.config._reparse([tmpdir])
+    f1 = py.test.collect.Function(name="name", config=config, 
+                                  args=(1,), callobj=isinstance)
+    f2 = py.test.collect.Function(name="name", config=config, 
+                                  args=(1,), callobj=callable)
+    assert not f1 == f2
+    assert f1 != f2
+    f3 = py.test.collect.Function(name="name", config=config, 
+                                  args=(1,2), callobj=callable)
+    assert not f3 == f2
+    assert f3 != f2
+
+    assert not f3 == f1
+    assert f3 != f1
+
+    f1_b = py.test.collect.Function(name="name", config=config, 
+                                  args=(1,), callobj=isinstance)
+    assert f1 == f1_b
+    assert not f1 != f1_b
+    
+    
 class Testgenitems: 
     def setup_class(cls):
         cls.classtemp = py.test.ensuretemp(cls.__name__)



More information about the pytest-commit mailing list