

def test_scope(self):

    def func(self):

        def foo(z):
            y = 2
            stub = False
            only_here = 1
            return ((x + y) + z)
        x = 1
        y = 0
        y = 1
        z = 1
        res = foo(3)
        stub = True
        return (res + y)
    code = py2js(func)
    i = code.splitlines().index('var func;')
    assert (i >= 0)
    vars1 = code.splitlines()[(i + 2)]
    vars2 = code.splitlines()[(i + 4)]
    assert vars1.strip().startswith('var ')
    assert vars2.strip().startswith('var ')
    assert (('y' in vars1) and ('y' in vars2))
    assert (('stub' in vars1) and ('stub' in vars1))
    assert (('only_here' in vars2) and ('only_here' not in vars1))
    assert (evaljs((code + 'func()')) == '7')

dataset/ETHPy150Open zoofIO/flexx/flexx/pyscript/tests/test_parser2.py TestFunctions.test_scope/VarMisuse@194/225 `vars2`->`vars1`