def test_nested_functions_special_functions():
    model_src = '''
"""
output = a
"""

def step():
    def f0():
        def f1():
          return 10
        return f1()
    a = a+f0()

a = 0

'''
    model = PythonModel(code=model_src)

    result = model.init()
    assert result == 0

    result = model.init()
    result = model.step()
    assert result == 10

    result = model.run(nstep=10)
    assert result == 100
Example #2
0
def test_in_function():
    code = """
'''
output=out
'''
a=1
def f():
    return(a)

out = f()
"""
    from openalea.core.model import PythonModel
    model = PythonModel(name='func')
    model.set_code(code)
    model.init()
    model.step()
def test_step():

    model = PythonModel(code=model_src)

    result = model.init()
    assert result == 0
    result = model.step()
    assert result == 1
    result = model.step()
    assert result == 2
    result = model.step()
    assert result == 3
    result = model.step()
    assert result == 4

    result = model.init()
    assert result == 0

    result = model.animate()
    assert result == 10
def test_step_without_run():
    model_src = '''"""
output = a"""

a = 0

def step():
    a = a + 1
'''
    model = PythonModel(code=model_src)

    result = model.init()
    assert result == 0

    result = model.step()
    assert result == 1
    result = model.step()
    assert result == 2
    result = model.step()
    assert result == 3

    result = model.init()
    assert result == 0
Example #5
0
def test_in_function():
    code = """
'''
output=out
'''
a=1
def f():
    return(a)

out = f()
"""
    from openalea.core.model import PythonModel
    model = PythonModel(name='func')
    model.set_code(code)
    assert model.init() == 1
def test_nested_functions_in_init():
    model_src = '''
"""
output = a
"""

def f0():
    def f1():
      return 10
    return f1()

a = f0()

'''
    model = PythonModel(code=model_src)

    result = model.init()
    assert result == 10