[py-svn] r51667 - in py/branch/event/py/test2: . testing

hpk at codespeak.net hpk at codespeak.net
Wed Feb 20 09:24:13 CET 2008


Author: hpk
Date: Wed Feb 20 09:24:13 2008
New Revision: 51667

Modified:
   py/branch/event/py/test2/collect.py
   py/branch/event/py/test2/item.py
   py/branch/event/py/test2/testing/test_collect.py
Log:
* remove redundant reprs
* fix XXX and streamline eq/ne/cmp operators



Modified: py/branch/event/py/test2/collect.py
==============================================================================
--- py/branch/event/py/test2/collect.py	(original)
+++ py/branch/event/py/test2/collect.py	Wed Feb 20 09:24:13 2008
@@ -52,9 +52,9 @@
         return "<%s %r>" %(self.__class__.__name__, self.name) 
 
     def __eq__(self, other): 
-        # XXX a rather strict check for now to not confuse
-        #     the SetupState.prepare() logic
-        return self is other
+        if not isinstance(other, Base):
+            return False 
+        return self.name == other.name and self.parent == other.parent 
     
     def __hash__(self):
         return hash((self.name, self.parent))
@@ -63,9 +63,10 @@
         return not self == other
 
     def __cmp__(self, other): 
+        if not isinstance(other, Base):
+            return -1
         s1 = self._getsortvalue()
         s2 = other._getsortvalue()
-        #print "cmp", s1, s2
         return cmp(s1, s2) 
   
     def multijoin(self, namelist): 
@@ -353,9 +354,6 @@
     def finishcapture(self): 
         self._config._finishcapture(self)
 
-    def __repr__(self): 
-        return "<%s %r>" % (self.__class__.__name__, self.name)
-
     def _getobj(self):
         failure = self._stickyfailure
         if failure is not None: 

Modified: py/branch/event/py/test2/item.py
==============================================================================
--- py/branch/event/py/test2/item.py	(original)
+++ py/branch/event/py/test2/item.py	Wed Feb 20 09:24:13 2008
@@ -1,7 +1,7 @@
 import py
 
 from py.__.test2.collect import FunctionMixin, Base
-import present
+from py.__.test2 import present
 
 _dummy = object()
 
@@ -48,9 +48,6 @@
         if obj is not _dummy: 
             self._obj = obj 
         self._sort_value = sort_value
-        
-    def __repr__(self): 
-        return "<%s %r>" %(self.__class__.__name__, self.name)
 
     def run(self):
         """ setup and execute the underlying test function. """

Modified: py/branch/event/py/test2/testing/test_collect.py
==============================================================================
--- py/branch/event/py/test2/testing/test_collect.py	(original)
+++ py/branch/event/py/test2/testing/test_collect.py	Wed Feb 20 09:24:13 2008
@@ -230,15 +230,34 @@
     names = col.listdir()
     assert names == fnames 
 
-def test_check_random_inequality():
+def test_check_equality_and_cmp_basic():
     path = setupdata.getexamplefile("funcexamples.py")
     col = py.test2.collect.Module(path, config=dummyconfig)
-    fn = col.join("funcpass")
-    assert fn != 3
-    assert fn != col
-    assert fn != [1,2,3]
-    assert [1,2,3] != fn
-    assert col != fn
+    fn1 = col.join("funcpassed")
+    assert isinstance(fn1, py.test2.collect.Function)
+    fn2 = col.join("funcpassed") 
+    assert isinstance(fn2, py.test2.collect.Function)
+
+    assert fn1 == fn2
+    assert fn1 != col 
+    assert cmp(fn1, fn2) == 0
+    assert hash(fn1) == hash(fn2) 
+
+    fn3 = col.join("funcfailed")
+    assert isinstance(fn3, py.test2.collect.Function)
+    assert not (fn1 == fn3) 
+    assert fn1 != fn3
+    assert cmp(fn1, fn3) == -1
+
+    assert cmp(fn1, 10) == -1 
+    assert cmp(fn2, 10) == -1 
+    assert cmp(fn3, 10) == -1 
+    for fn in fn1,fn2,fn3:
+        assert fn != 3
+        assert fn != col
+        assert fn != [1,2,3]
+        assert [1,2,3] != fn
+        assert col != fn
 
 class Testgenitems: 
     def setup_class(cls):



More information about the pytest-commit mailing list