Skip to content

Commit

Permalink
merge to evan-script_fix-merge-3
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Simpson committed Apr 11, 2001
1 parent d363a16 commit ea4d1c7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
8 changes: 5 additions & 3 deletions PythonScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@
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
Expand All @@ -111,6 +111,8 @@
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

Expand Down Expand Up @@ -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()

Expand Down
27 changes: 25 additions & 2 deletions tests/testPythonScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -191,6 +195,25 @@ def testFibonacci(self):
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
Expand Down

0 comments on commit ea4d1c7

Please sign in to comment.