[pypy-svn] r55901 - in pypy/branch/2.5-features/pypy/objspace/std: . test

bgola at codespeak.net bgola at codespeak.net
Mon Jun 16 20:59:35 CEST 2008


Author: bgola
Date: Mon Jun 16 20:59:34 2008
New Revision: 55901

Modified:
   pypy/branch/2.5-features/pypy/objspace/std/ropeunicodeobject.py
   pypy/branch/2.5-features/pypy/objspace/std/test/test_ropeobject.py
   pypy/branch/2.5-features/pypy/objspace/std/test/test_ropeunicodeobject.py
   pypy/branch/2.5-features/pypy/objspace/std/test/test_unicodeobject.py
   pypy/branch/2.5-features/pypy/objspace/std/unicodeobject.py
Log:
UnicodeWarning for Rope and RopeUnicode objects

Modified: pypy/branch/2.5-features/pypy/objspace/std/ropeunicodeobject.py
==============================================================================
--- pypy/branch/2.5-features/pypy/objspace/std/ropeunicodeobject.py	(original)
+++ pypy/branch/2.5-features/pypy/objspace/std/ropeunicodeobject.py	Mon Jun 16 20:59:34 2008
@@ -177,9 +177,31 @@
 def eq__RopeUnicode_RopeUnicode(space, w_str1, w_str2):
     return space.newbool(_eq(w_str1, w_str2))
 
+def eq__RopeUnicode_Rope(space, w_str1, w_str2):
+    try:
+        w_uni = unicode_from_string(space, w_str2)
+    except OperationError, e:
+        if e.match(space, space.w_UnicodeDecodeError):
+            msg = "Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal"
+            space.warn(msg, space.w_UnicodeWarning)
+            return space.w_False
+        raise
+    return space.newbool(_eq(w_str1, w_str2))
+
 def ne__RopeUnicode_RopeUnicode(space, w_str1, w_str2):
     return space.newbool(not _eq(w_str1, w_str2))
 
+def ne__RopeUnicode_Rope(space, w_str1, w_str2):
+    try:
+        w_uni = unicode_from_string(space, w_str2)
+    except OperationError, e:
+        if e.match(space, space.w_UnicodeDecodeError):
+            msg = "Unicode unequal comparison failed to convert both arguments to Unicode - interpreting them as being unequal"
+            space.warn(msg, space.w_UnicodeWarning)
+            return space.w_True
+        raise
+    return space.newbool(not _eq(w_str1, w_str2))
+
 def gt__RopeUnicode_RopeUnicode(space, w_str1, w_str2):
     n1 = w_str1._node
     n2 = w_str2._node

Modified: pypy/branch/2.5-features/pypy/objspace/std/test/test_ropeobject.py
==============================================================================
--- pypy/branch/2.5-features/pypy/objspace/std/test/test_ropeobject.py	(original)
+++ pypy/branch/2.5-features/pypy/objspace/std/test/test_ropeobject.py	Mon Jun 16 20:59:34 2008
@@ -63,6 +63,13 @@
         d = {u'abcdefg': 2}
         assert d['abcdefg'] == 2
 
+
+class TestUnicodeRopeObject(test_unicodeobject.TestUnicodeObject):
+
+    def setup_class(cls):
+        cls.space = gettestobjspace(**{"objspace.std.withrope": True})
+
+
 class AppTestUnicodeRopeStdOnly(test_unicodeobject.AppTestUnicodeStringStdOnly):
 
     def setup_class(cls):

Modified: pypy/branch/2.5-features/pypy/objspace/std/test/test_ropeunicodeobject.py
==============================================================================
--- pypy/branch/2.5-features/pypy/objspace/std/test/test_ropeunicodeobject.py	(original)
+++ pypy/branch/2.5-features/pypy/objspace/std/test/test_ropeunicodeobject.py	Mon Jun 16 20:59:34 2008
@@ -3,6 +3,12 @@
 from pypy.objspace.std.test import test_stringobject, test_unicodeobject
 from pypy.conftest import gettestobjspace
 
+class TestRopeUnicodeObject(test_unicodeobject.TestUnicodeObject):
+
+    def setup_class(cls):
+        cls.space = gettestobjspace(**{"objspace.std.withropeunicode": True})
+
+
 class AppTestRopeObject(test_stringobject.AppTestStringObject):
 
     def setup_class(cls):

Modified: pypy/branch/2.5-features/pypy/objspace/std/test/test_unicodeobject.py
==============================================================================
--- pypy/branch/2.5-features/pypy/objspace/std/test/test_unicodeobject.py	(original)
+++ pypy/branch/2.5-features/pypy/objspace/std/test/test_unicodeobject.py	Mon Jun 16 20:59:34 2008
@@ -1,10 +1,8 @@
 import py
 import sys
 
-from pypy.objspace.std.objspace import *
-from pypy.objspace.std.stdtypedef import *
-
 class TestUnicodeObject:
+
     def test_comparison_warning(self):
         warnings = []
         def my_warn(msg, warningscls):
@@ -21,6 +19,7 @@
             """)
         finally:
             space.warn = prev_warn
+        print self.space.config.objspace.std.withrope
         assert len(warnings) == 2
 
 

Modified: pypy/branch/2.5-features/pypy/objspace/std/unicodeobject.py
==============================================================================
--- pypy/branch/2.5-features/pypy/objspace/std/unicodeobject.py	(original)
+++ pypy/branch/2.5-features/pypy/objspace/std/unicodeobject.py	Mon Jun 16 20:59:34 2008
@@ -95,6 +95,8 @@
         raise
     return space.newbool(w_left._value == w_uni._value)
 
+eq__Unicode_Rope = eq__Unicode_String
+
 def ne__Unicode_String(space, w_left, w_right):
     from pypy.objspace.std.unicodetype import unicode_from_string
     try:
@@ -107,6 +109,8 @@
         raise
     return space.newbool(w_left._value != w_uni._value)
 
+ne__Unicode_Rope = ne__Unicode_String
+
 def lt__Unicode_Unicode(space, w_left, w_right):
     left = w_left._value
     right = w_right._value



More information about the Pypy-commit mailing list