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

Evan Simpson evan at 4-am.com
Thu Jan 15 14:44:00 EST 2004


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

Modified Files:
      Tag: Zope-2_7-branch
	testPythonScript.py 
Log Message:
Collector #1074: Change Scripts' __name__ to None, added unit tests for the effect of __name__ on class definitions and imports.


=== Releases/Zope/lib/python/Products/PythonScripts/tests/testPythonScript.py 1.12.68.2 => 1.12.68.3 ===
--- Releases/Zope/lib/python/Products/PythonScripts/tests/testPythonScript.py:1.12.68.2	Thu Jan  8 18:33:52 2004
+++ Releases/Zope/lib/python/Products/PythonScripts/tests/testPythonScript.py	Thu Jan 15 14:43:29 2004
@@ -54,6 +54,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):
 
@@ -110,22 +118,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)
 
@@ -135,16 +143,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,
@@ -153,24 +161,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()))
 
 
@@ -218,13 +226,18 @@
         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 testGlobalIsDeclaration(self):
         bindings = {'container': 7}
         results = self._exec('global_is_declaration', bindings)
         self.assertEqual(results, 8)
+
+    def test__name__(self):
+        fname = 'class.__name__'
+        f = self._filePS(fname)
+        self.assertEqual(f(), ('?.foo', "'string'"))
 
 
 def test_suite():




More information about the Zope-Checkins mailing list