[Zope-Checkins] CVS: Releases/Zope/lib/python/Products/PythonScripts/tests - testPythonScript.py:1.12.6.2

Evan Simpson evan at 4-am.com
Fri Jan 16 13:42:21 EST 2004


Update of /cvs-repository/Releases/Zope/lib/python/Products/PythonScripts/tests
In directory cvs.zope.org:/tmp/cvs-serv19185/lib/python/Products/PythonScripts/tests

Modified Files:
      Tag: Zope-2_6-branch
	testPythonScript.py 
Log Message:
Backport Script __name__ fixes.


=== Releases/Zope/lib/python/Products/PythonScripts/tests/testPythonScript.py 1.12.6.1 => 1.12.6.2 ===
--- Releases/Zope/lib/python/Products/PythonScripts/tests/testPythonScript.py:1.12.6.1	Thu Jan  8 15:12:09 2004
+++ Releases/Zope/lib/python/Products/PythonScripts/tests/testPythonScript.py	Fri Jan 16 13:41:50 2004
@@ -55,6 +55,14 @@
             raise SyntaxError, ps.errors[0]
         return ps
 
+    def _filePS(self, fname, bind=None):
+        ps = VerifiedPythonScript(fname)
+        ps.ZBindings_edit(bind or {})
+        ps.write(readf(fname))
+        ps._makeFunction()
+        if ps.errors:
+            raise SyntaxError, ps.errors[0]
+        return ps
 
 class TestPythonScriptNoAq(PythonScriptTestBase):
 
@@ -111,22 +119,22 @@
         eq(c, 'c')
 
     def testWhileLoop(self):
-        res = self._newPS(readf('while_loop'))()
+        res = self._filePS('while_loop')()
         self.assertEqual(res, 1)
 
     def testForLoop(self):
-        res = self._newPS(readf('for_loop'))()
+        res = self._filePS('for_loop')()
         self.assertEqual(res, 10)
 
     def testMutateLiterals(self):
         eq = self.assertEqual
-        l, d = self._newPS(readf('mutate_literals'))()
+        l, d = self._filePS('mutate_literals')()
         eq(l, [2])
         eq(d, {'b': 2})
 
     def testTupleUnpackAssignment(self):
         eq = self.assertEqual
-        d, x = self._newPS(readf('tuple_unpack_assignment'))()
+        d, x = self._filePS('tuple_unpack_assignment')()
         eq(d, {'a': 0, 'b': 1, 'c': 2})
         eq(x, 3)
 
@@ -136,16 +144,16 @@
 
     def testTryExcept(self):
         eq = self.assertEqual
-        a, b = self._newPS(readf('try_except'))()
+        a, b = self._filePS('try_except')()
         eq(a, 1)
         eq(b, 1)
 
     def testBigBoolean(self):
-        res = self._newPS(readf('big_boolean'))()
+        res = self._filePS('big_boolean')()
         self.failUnless(res)
 
     def testFibonacci(self):
-        res = self._newPS(readf('fibonacci'))()
+        res = self._filePS('fibonacci')()
         self.assertEqual(
             res, [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377,
                   610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657,
@@ -154,24 +162,24 @@
                   24157817, 39088169, 63245986])
 
     def testSimplePrint(self):
-        res = self._newPS(readf('simple_print'))()
+        res = self._filePS('simple_print')()
         self.assertEqual(res, 'a 1 []\n')
 
     def testComplexPrint(self):
-        res = self._newPS(readf('complex_print'))()
+        res = self._filePS('complex_print')()
         self.assertEqual(res, 'double\ndouble\nx: 1\ny: 0 1 2\n\n')
 
     def testNSBind(self):
-        f = self._newPS(readf('ns_bind'), bind={'name_ns': '_'})
+        f = self._filePS('ns_bind', bind={'name_ns': '_'})
         bound = f.__render_with_namespace__({'yes': 1, 'no': self.fail})
         self.assertEqual(bound, 1)
 
     def testBooleanMap(self):
-        res = self._newPS(readf('boolean_map'))()
+        res = self._filePS('boolean_map')()
         self.failUnless(res)
 
     def testGetSize(self):
-        f = self._newPS(readf('complex_print'))
+        f = self._filePS('complex_print')
         self.assertEqual(f.get_size(), len(f.read()))
 
 
@@ -219,8 +227,13 @@
         if kws is None:
             kws = {}
         bindings = {'name_container': 'container'}
-        f = self._newPS(readf(script), bindings)
+        f = self._filePS(script, bindings)
         return f._exec(bound_names, args, kws)
+
+    def test__name__(self):
+        fname = 'class.__name__'
+        f = self._filePS(fname)
+        self.assertEqual(f(), ('?.foo', "'string'"))
 
     # XXX: This test can't work on 2.6;  it relies on behavior added by
     #      Evan, # 2003/11/04, to address Collector #445.  This code




More information about the Zope-Checkins mailing list