diff options
author | Barry Warsaw <barry@python.org> | 2001-03-23 16:13:30 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2001-03-23 16:13:30 (GMT) |
commit | dfdac1af4d323f4f69775794777197ea31d804ef (patch) | |
tree | e67c36bbf7862539804f324f864b02bbf4285f8e /Lib | |
parent | 101651c128825a05a7ba7c1c556c90e22bfb86c2 (diff) | |
download | cpython-dfdac1af4d323f4f69775794777197ea31d804ef.zip cpython-dfdac1af4d323f4f69775794777197ea31d804ef.tar.gz cpython-dfdac1af4d323f4f69775794777197ea31d804ef.tar.bz2 |
Several changes for Jython portability. This closes SF patch
#403666. Specifically,
In codestr, force `c' to be global. It's unclear what the semantics
should be for a code object compiled at module scope, but bound and
run in a function. In CPython, `c' is global (by accident?) while in
Jython, `c' is local. The intent of the test clearly is to make `c'
global, so let's be explicit about it.
Jython also does not have a __builtins__ name in the module's
namespace, so we use a more portable alternative (though I'm not sure
why the test requires "__builtins__" in the g namespace).
Finally, skip the new.code() test if the new module doesn't have a
`code' attribute. Jython will never have this.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_new.py | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/Lib/test/test_new.py b/Lib/test/test_new.py index 8a7b9a6..ab5eede 100644 --- a/Lib/test/test_new.py +++ b/Lib/test/test_new.py @@ -47,14 +47,21 @@ im() verify(c.get_yolks() == 1 and c.get_more_yolks() == 4, 'Broken call of hand-crafted instance method') +# It's unclear what the semantics should be for a code object compiled at +# module scope, but bound and run in a function. In CPython, `c' is global +# (by accident?) while in Jython, `c' is local. The intent of the test +# clearly is to make `c' global, so let's be explicit about it. codestr = ''' +global c a = 1 b = 2 c = a + b ''' ccode = compile(codestr, '<string>', 'exec') -g = {'c': 0, '__builtins__': __builtins__} +# Jython doesn't have a __builtins__, so use a portable alternative +import __builtin__ +g = {'c': 0, '__builtins__': __builtin__} # this test could be more robust print 'new.function()' func = new.function(ccode, g) @@ -65,11 +72,13 @@ verify(g['c'] == 3, 'Could not create a proper function object') # bogus test of new.code() -print 'new.code()' -d = new.code(3, 3, 3, 3, codestr, (), (), (), - "<string>", "<name>", 1, "", (), ()) -# test backwards-compatibility version with no freevars or cellvars -d = new.code(3, 3, 3, 3, codestr, (), (), (), - "<string>", "<name>", 1, "") -if verbose: - print d +# Note: Jython will never have new.code() +if hasattr(new, 'code'): + print 'new.code()' + d = new.code(3, 3, 3, 3, codestr, (), (), (), + "<string>", "<name>", 1, "", (), ()) + # test backwards-compatibility version with no freevars or cellvars + d = new.code(3, 3, 3, 3, codestr, (), (), (), + "<string>", "<name>", 1, "") + if verbose: + print d |