示例#1
0
文件: model.py 项目: shiva16/openalea
    def set_code(self, code):
        from openalea.oalab.model.parse import parse_docstring, get_docstring, extract_functions
        self._initial_code = code
        model, self.inputs_info, self.outputs_info = parse_docstring(code)
        funcs = extract_functions(code)
        self.set_func_code('init', code)

        for fname in ['step', 'run', 'animate']:
            if fname in funcs:
                self.set_func_code(fname, funcs[fname])

        self._doc = get_docstring(code)
示例#2
0
def test_parse_interface():
    model_src = '''"""
input = a:ISequence, b:int, c="blabla", d=3.14, e=[1,2,3]
"""
print "ok"
'''
    model, inputs, outputs = parse_docstring(model_src)
    assert str(inputs[0].interface) == "ISequence"
    assert str(inputs[1].interface) == "IInt"
    assert str(inputs[2].interface) == "IStr"
    assert str(inputs[3].interface) == "IFloat"
    assert str(inputs[4].interface) == "ISequence"
示例#3
0
文件: model.py 项目: gbaty/openalea
    def set_code(self, code):
        from openalea.oalab.model.parse import parse_docstring, get_docstring, extract_functions
        self._initial_code = code
        model, self.inputs_info, self.outputs_info = parse_docstring(code)
        funcs = extract_functions(code)
        self.set_func_code('init', code)

        for fname in ['step', 'run', 'animate']:
            if fname in funcs:
                self.set_func_code(fname, funcs[fname])

        self._doc = get_docstring(code)
def test_parse_interface():
    model_src = '''"""
input = a:ISequence, b:int, c="blabla", d=3.14, e=[1,2,3]
"""
print "ok"
'''
    model, inputs, outputs = parse_docstring(model_src)
    assert str(inputs[0].interface) == "ISequence"
    assert str(inputs[1].interface) == "IInt"
    assert str(inputs[2].interface) == "IStr"
    assert str(inputs[3].interface) == "IFloat"
    assert str(inputs[4].interface) == "ISequence"
示例#5
0
def test_docstring_char2():
    model_src = '''"""
input = x="input=True,False", y="input = output = [1,2]"

beautifull doc
"""

print "ok"
'''
    model, inputs, outputs = parse_docstring(model_src)

    assert len(inputs) == 2
    assert outputs == []
    assert inputs[0].name == "x"
    assert eval(inputs[0].default) == "input=True,False"
    assert inputs[1].name == "y"
    assert eval(inputs[1].default) == "input = output = [1,2]"
def test_docstring_char2():
    model_src = '''"""
input = x="input=True,False", y="input = output = [1,2]"

beautifull doc
"""

print "ok"
'''
    model, inputs, outputs = parse_docstring(model_src)

    assert len(inputs) == 2
    assert outputs == []
    assert inputs[0].name == "x"
    assert eval(inputs[0].default) == "input=True,False"
    assert inputs[1].name == "y"
    assert eval(inputs[1].default) == "input = output = [1,2]"
def test_docstring_char():
    model_src = '''"""
input = x="blablabla([1,2,3,4,5,6],['something'])", y="Here is a string, with brackects ( just here ) and square brackets [here]..."

beautifull doc
"""

print "ok"
'''
    model, inputs, outputs = parse_docstring(model_src)

    assert len(inputs) == 2
    assert outputs == []
    assert inputs[0].name == "x"
    assert eval(inputs[0].default) == "blablabla([1,2,3,4,5,6],['something'])"
    assert inputs[1].name == "y"
    assert eval(inputs[1].default) == "Here is a string, with brackects ( just here ) and square brackets [here]..."
示例#8
0
def test_docstring_char():
    model_src = '''"""
input = x="blablabla([1,2,3,4,5,6],['something'])", y="Here is a string, with brackects ( just here ) and square brackets [here]..."

beautifull doc
"""

print "ok"
'''
    model, inputs, outputs = parse_docstring(model_src)

    assert len(inputs) == 2
    assert outputs == []
    assert inputs[0].name == "x"
    assert eval(inputs[0].default) == "blablabla([1,2,3,4,5,6],['something'])"
    assert inputs[1].name == "y"
    assert eval(
        inputs[1].default
    ) == "Here is a string, with brackects ( just here ) and square brackets [here]..."
示例#9
0
def test_docstring_unknow():
    model_src = '''"""
model1(x,y)->r
input = x:int=4, y:float=3.14

beautifull doc
"""

print "ok"
'''
    model, inputs, outputs = parse_docstring(model_src)

    assert model == "model1"
    assert len(inputs) == 2
    assert len(outputs) == 1
    assert inputs[0].name == "x"
    assert inputs[0].default == "4"
    # assert inputs[0].interface == "IInt"
    assert inputs[1].name == "y"
    assert inputs[1].default == "3.14"
示例#10
0
def test_docstring_unknow():
    model_src = '''"""
model1(x,y)->r
input = x:int=4, y:float=3.14

beautifull doc
"""

print "ok"
'''
    model, inputs, outputs = parse_docstring(model_src)

    assert model == "model1"
    assert len(inputs) == 2
    assert len(outputs) == 1
    assert inputs[0].name == "x"
    assert inputs[0].default == "4"
    # assert inputs[0].interface == "IInt"
    assert inputs[1].name == "y"
    assert inputs[1].default == "3.14"