Exemplo n.º 1
0
def test_detect_step_and_others():
    model_src = '''"""
This is the doc of my model
"""

print "result = 0"
result = 0

def step():
    result += 1
    print result

def animate():
    for i in range(10):
        result += 1
        #step()

def init():
    result = 0
    print "ini"
'''

    model_src2 = '''"""
This is the doc of my model

:use: run()
"""

print "result = 0"
result = 0

def run():
    for i in range(10):
        result += 1
        print result

'''
    has_init, has_step, has_animate, has_run = parse_functions(model_src)
    assert has_step
    assert has_animate
    assert has_init
    assert not has_run

    has_init, has_step, has_animate, has_run = parse_functions(model_src2)
    assert not has_step
    assert not has_animate
    assert not has_init
    assert has_run
Exemplo n.º 2
0
def test_detect_step_and_others():
    model_src = '''"""
This is the doc of my model
"""

print "result = 0"
result = 0

def step():
    result += 1
    print result

def animate():
    for i in range(10):
        result += 1
        #step()

def init():
    result = 0
    print "ini"
'''

    model_src2 = '''"""
This is the doc of my model

:use: run()
"""

print "result = 0"
result = 0

def run():
    for i in range(10):
        result += 1
        print result

'''
    has_init, has_step, has_animate, has_run = parse_functions(model_src)
    assert has_step
    assert has_animate
    assert has_init
    assert not has_run

    has_init, has_step, has_animate, has_run = parse_functions(model_src2)
    assert not has_step
    assert not has_animate
    assert not has_init
    assert has_run
Exemplo n.º 3
0
def test_extract_func():
    code = '''
def run():
    a = 0
    for i in range(10):
        a += 1
'''
    _, _, _, run = parse_functions(code)
    d = {}
    exec run in d
    assert d['a'] == 10
Exemplo n.º 4
0
def test_extract_func():
    code = """
def run():
    a = 0
    for i in range(10):
        a += 1
"""
    _, _, _, run = parse_functions(code)
    d = {}
    exec run in d
    assert d["a"] == 10