[pypy-svn] r64836 - in pypy/branch/io-lang/pypy/lang/io: . test

david at codespeak.net david at codespeak.net
Wed Apr 29 20:03:36 CEST 2009


Author: david
Date: Wed Apr 29 20:03:33 2009
New Revision: 64836

Modified:
   pypy/branch/io-lang/pypy/lang/io/object.py
   pypy/branch/io-lang/pypy/lang/io/test/test_interpreter.py
Log:
more getSlot tests and support access of non existing slots

Modified: pypy/branch/io-lang/pypy/lang/io/object.py
==============================================================================
--- pypy/branch/io-lang/pypy/lang/io/object.py	(original)
+++ pypy/branch/io-lang/pypy/lang/io/object.py	Wed Apr 29 20:03:33 2009
@@ -13,7 +13,10 @@
 def w_object_get_slot(space, w_target, w_message, w_context):
     w_name = w_message.arguments[0].eval(space, w_context, w_context)
     assert isinstance(w_name, W_ImmutableSequence)
-    return w_target.slots[w_name.value]
+    try:
+        return w_target.slots[w_name.value]
+    except KeyError:
+        return space.w_nil
 
 @register_method('Object', 'method')
 def w_object_method(space, w_target, w_message, w_context):

Modified: pypy/branch/io-lang/pypy/lang/io/test/test_interpreter.py
==============================================================================
--- pypy/branch/io-lang/pypy/lang/io/test/test_interpreter.py	(original)
+++ pypy/branch/io-lang/pypy/lang/io/test/test_interpreter.py	Wed Apr 29 20:03:33 2009
@@ -37,4 +37,13 @@
 def test_false():
     x, space = interpret('false')
     assert x == space.w_false
-    assert x.protos == [space.w_object]
\ No newline at end of file
+    assert x.protos == [space.w_object]
+    
+def test_get_slot():
+    inp1 = 'a := 1; getSlot("a")'
+    inp2 = 'getSlot("a")'
+    res, space = interpret(inp1)
+    assert res.value == 1
+    
+    res, space = interpret(inp2)
+    assert res == space.w_nil
\ No newline at end of file



More information about the Pypy-commit mailing list