Commits

Philip Jenvey committed 52c9fda

ease the W_TypeObject assertion to accomodate Dummy/FakeObjSpaces

Comments (0)

Files changed (2)

pypy/interpreter/error.py

                 self.xstrings = strings
                 for i, _, attr in entries:
                     setattr(self, attr, args[i])
-                assert _is_type(w_type)
+                assert w_type is not None
+                # space may be None during tests
+                self.space = w_type.space if _is_type(w_type) else None
 
             def _compute_value(self):
+                space = self.space
                 lst = [None] * (len(formats) + len(formats) + 1)
                 for i, fmt, attr in entries:
                     string = self.xstrings[i]
                     value = getattr(self, attr)
                     lst[i+i] = string
-                    if fmt in 'NT':
-                        space = self.w_type.space
-                        if fmt == 'T':
-                            value = space.type(value)
+                    if fmt == 'T':
+                        type_ = type if space is None else space.type
+                        value = type_(value)
+                    if fmt in 'NT' and space is not None:
                         lst[i+i+1] = value.getname(space)
                     else:
                         lst[i+i+1] = str(value)

pypy/interpreter/test/test_error.py

     assert (decompose_valuefmt("%s%d%%%s") ==
             (("", "", "%", ""), ('s', 'd', 's')))
 
-def test_get_operrcls2(space):
+def test_get_operrcls2():
     cls, strings = get_operrcls2('abc %s def %d')
     assert strings == ("abc ", " def ", "")
     assert issubclass(cls, OperationError)
-    inst = cls(space.w_OSError, strings, "hello", 42)
+    inst = cls("w_type", strings, "hello", 42)
     assert inst._compute_value() == "abc hello def 42"
     cls2, strings2 = get_operrcls2('a %s b %d c')
     assert cls2 is cls     # caching
     assert strings2 == ("a ", " b ", " c")
 
-def test_operationerrfmt(space):
-    w_exc = space.w_IOError
-    operr = operationerrfmt(w_exc, "abc %s def %d", "foo", 42)
+def test_operationerrfmt():
+    operr = operationerrfmt("w_type", "abc %s def %d", "foo", 42)
     assert isinstance(operr, OperationError)
-    assert operr.w_type == w_exc
+    assert operr.w_type == "w_type"
     assert operr._w_value is None
     assert operr._compute_value() == "abc foo def 42"
-    operr2 = operationerrfmt(w_exc, "a %s b %d c", "bar", 43)
+    operr2 = operationerrfmt("w_type2", "a %s b %d c", "bar", 43)
     assert operr2.__class__ is operr.__class__
-    operr3 = operationerrfmt(w_exc, "a %s b %s c", "bar", "4b")
+    operr3 = operationerrfmt("w_type2", "a %s b %s c", "bar", "4b")
     assert operr3.__class__ is not operr.__class__
 
 def test_operationerrfmt_T(space):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.