[Zope-Checkins] CVS: Zope3/lib/python/Zope/ContextWrapper - test_wrapper.py:1.6.2.6
Fred Drake Jr
fdrake@acm.org
Fri, 30 Nov 2001 16:54:02 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/ContextWrapper
In directory cvs.zope.org:/tmp/cvs-serv21511
Modified Files:
Tag: Zope-3x-branch
test_wrapper.py
Log Message:
More tests to make sure we really have rich comparisons working right.
=== Zope3/lib/python/Zope/ContextWrapper/test_wrapper.py 1.6.2.5 => 1.6.2.6 ===
pass
+class Comparable:
+ def __init__(self, value):
+ self.value = value
+
+ def __eq__(self, other):
+ if hasattr(other, "value"):
+ other = other.value
+ return self.value == other
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __lt__(self, other):
+ if hasattr(other, "value"):
+ other = other.value
+ return self.value < other
+
+ def __ge__(self, other):
+ return not self.__lt__(other)
+
+ def __le__(self, other):
+ if hasattr(other, "value"):
+ other = other.value
+ return self.value <= other
+
+ def __gt__(self, other):
+ return not self.__le__(other)
+
+ def __repr__(self):
+ return "<Comparable: %r>" % self.value
+
class WrapperTestCase(unittest.TestCase):
def test_wrapper_basics(self):
@@ -146,9 +177,43 @@
w = wrapper.Wrapper('foo')
self.assertEquals(w, 'foo')
+ o1 = Comparable(1)
+ o2 = Comparable(1.0)
+ o3 = Comparable("splat!")
+
+ w1 = wrapper.Wrapper(o1)
+ w2 = wrapper.Wrapper(o2)
+ w3 = wrapper.Wrapper(o3)
+
+ self.assertEquals(o1, w1)
+ self.assertEquals(o1, w2)
+ self.assertEquals(o2, w1)
+ self.assertEquals(w1, o2)
+ self.assertEquals(w2, o1)
+
+ self.assertNotEquals(o3, w1)
+ self.assertNotEquals(w1, o3)
+ self.assertNotEquals(w3, o1)
+ self.assertNotEquals(o1, w3)
+
+ def test_proxy_ordering_lt(self):
+ o1 = Comparable(1)
+ o2 = Comparable(2.0)
+
+ w1 = wrapper.Wrapper(o1)
+ w2 = wrapper.Wrapper(o2)
+
+ self.assert_(w1 < w2)
+ self.assert_(w1 <= w2)
+ self.assert_(o1 < w2)
+ self.assert_(o1 <= w2)
+ self.assert_(w1 < o2)
+ self.assert_(w2 <= o2)
+
def test_proxy_callable(self):
w = wrapper.Wrapper({}.get)
self.assert_(callable(w))
+
def test_suite():
suite = unittest.TestSuite()