RandomSec/lib/jython-2.5.1/test/test_closuregen.py
Vishal Talwar d0df704d8a added python code part of jython distribution in lib/jython-2.5.1
added python.path vm arg to startup script
fixed infinite loop in unwrap() when displaying sequences of sequences



git-svn-id: http://google-refine.googlecode.com/svn/trunk@509 7d457c2a-affb-35e4-300a-418c747d4874
2010-04-20 18:50:24 +00:00

52 lines
1.2 KiB
Python

"""Jython bug with cell variables and yield"""
from __future__ import generators
def single_closure_single_value():
value = 0
a_closure = lambda : value
yield a_closure()
yield a_closure()
def single_closure_multiple_values():
value = 0
a_closure = lambda : value
yield a_closure()
value = 1
yield a_closure()
def multiple_closures_single_value():
value = 0
a_closure = lambda : value
yield a_closure()
a_closure = lambda : value
yield a_closure()
def multiple_closures_multiple_values():
value = 0
a_closure = lambda : value
yield a_closure()
value = 1
a_closure = lambda : value
yield a_closure()
tests={}
for name in dir():
if 'closure' in name:
test = eval(name)
if name.endswith('single_value'):
expected = [0,0]
else:
expected = [0,1]
tests[test] = expected
def test_main(verbose=None):
from test.test_support import verify
import sys
for func in tests:
expected = tests[func]
result = list(func())
verify(result == expected, "%s: expected %s, got %s" % (
func.__name__, expected, result))
if __name__ == '__main__': test_main(1)