Commit f95470e7 authored by Evan Simpson's avatar Evan Simpson

merge to evan-script_fix-merge-3

parent 5dbc4a40
......@@ -89,10 +89,10 @@ This product provides support for Script objects containing restricted
Python code.
"""
__version__='$Revision: 1.25 $'[11:-2]
__version__='$Revision: 1.26 $'[11:-2]
import sys, os, traceback, re
from Globals import DTMLFile, MessageDialog
from Globals import DTMLFile, MessageDialog, package_home
import AccessControl, OFS, Guarded
from OFS.SimpleItem import SimpleItem
from DateTime.DateTime import DateTime
......@@ -111,6 +111,8 @@ Python_magic = imp.get_magic()
del imp
manage_addPythonScriptForm = DTMLFile('www/pyScriptAdd', globals())
_default_file = os.path.join(package_home(globals()),
'www', 'default.py')
_marker = [] # Create a new marker object
......@@ -161,7 +163,7 @@ class PythonScript(Script, Historical, Cacheable):
def __init__(self, id):
self.id = id
self.ZBindings_edit(defaultBindings)
self._makeFunction(1)
self._body = open(_default_file).read()
security = AccessControl.ClassSecurityInfo()
......
......@@ -106,13 +106,17 @@ def readf(name):
return open('tscripts/%s%s' % (name, '.ps'), 'r').read()
class TestPythonScriptNoAq(TestCase):
def _newPS(self, txt):
def _newPS(self, txt, bind=None):
ps = PythonScript('ps')
ps.ZBindings_edit({})
ps.ZBindings_edit(bind or {})
ps.write(txt)
ps._makeFunction(1)
return ps
def fail(self):
'Fail if called'
assert 0, 'Fail called'
def testEmpty(self):
empty = self._newPS('')()
assert empty is None, empty
......@@ -191,6 +195,25 @@ class TestPythonScriptNoAq(TestCase):
1346269, 2178309, 3524578, 5702887, 9227465, 14930352,
24157817, 39088169, 63245986], r
def testSimplePrint(self):
txt = self._newPS(readf('simple_print'))()
assert txt == 'a 1 []\n', txt
def testComplexPrint(self):
txt = self._newPS(readf('complex_print'))()
assert txt == 'double\ndouble\n x: 1\ny: 0 1 2\n\n', txt
def testNSBind(self):
f = self._newPS(readf('ns_bind'), bind={'name_ns': '_'})
bound = f.__render_with_namespace__({'yes': 1, 'no': self.fail})
assert bound == 1, bound
def testManyArgs(self):
f = self._newPS(readf('manyargs'))
f()
ss = f._v_f.func_code.co_stacksize
assert ss == 24, ss
test_classes = (TestPythonScriptNoAq,)
# unit test machinery
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment