Update of /cvs-repository/Packages/AccessControl/tests
In directory cvs.zope.org:/tmp/cvs-serv18615/lib/python/AccessControl/tests

Modified Files:
      Tag: Zope-2_7-branch
        testZopeGuards.py 
Log Message:
 - Backport test for Collector #1460 (which wasn't in play for 2.7x).


=== Packages/AccessControl/tests/testZopeGuards.py 1.1.4.7 => 1.1.4.8 ===
--- Packages/AccessControl/tests/testZopeGuards.py:1.1.4.7      Fri Jan  7 
17:03:59 2005
+++ Packages/AccessControl/tests/testZopeGuards.py      Mon Apr  4 14:28:34 2005
@@ -435,22 +435,56 @@
         code, its_globals = self._compile("actual_python.py")
         exec code in its_globals
 
-    # Compile code in fname, as restricted Python. Return the
-    # compiled code, and a safe globals dict for running it in.
-    # fname is the string name of a Python file; it must be found
-    # in the same directory as this file.
-    def _compile(self, fname):
+  
+    def test_dict_access(self):
+        from RestrictedPython.tests import verify
+
+        SIMPLE_DICT_ACCESS_SCRIPT = """
+def foo(text):
+    return text
+
+kw = {'text':'baz'}
+print foo(**kw)
+
+kw = {'text':True}
+print foo(**kw)
+"""
+        code, its_globals = self._compile_str(SIMPLE_DICT_ACCESS_SCRIPT, 'x')
+        verify.verify(code)
+
+        sm = SecurityManager()
+        old = self.setSecurityManager(sm)
+        try:
+            exec code in its_globals
+        finally:
+            self.setSecurityManager(old)
+
+        self.assertEqual(its_globals['_print'](),
+                        'baz\nTrue\n')
+
+    def _compile_str(self, text, name):
         from RestrictedPython import compile_restricted
         from AccessControl.ZopeGuards import get_safe_globals, guarded_getattr
 
-        fn = os.path.join( _HERE, fname)
-        code = compile_restricted(open(fn).read(), fn, 'exec')
+        code = compile_restricted(text, name, 'exec')
 
         g = get_safe_globals()
         g['_getattr_'] = guarded_getattr
         g['__debug__'] = 1  # so assert statements are active
         g['__name__'] = __name__ # so classes can be defined in the script
         return code, g
+
+    # Compile code in fname, as restricted Python. Return the
+    # compiled code, and a safe globals dict for running it in.
+    # fname is the string name of a Python file; it must be found
+    # in the same directory as this file.
+    def _compile(self, fname):
+        from RestrictedPython import compile_restricted
+        from AccessControl.ZopeGuards import get_safe_globals, guarded_getattr
+
+        fn = os.path.join( _HERE, fname)
+        text = open(fn).read()
+        return self._compile_str(text, fn)
 
     # d is a dict, the globals for execution or our safe builtins.
     # The callable values which aren't the same as the corresponding

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to