Example #1
0
    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)
Example #2
0
def test_magic_getdoc():
    model_src = '''"""
This is the doc of my model
"""
%pylab inline
print "ok"
'''
    d = get_docstring(model_src)
    assert d is not None

    real_d = "This is the doc of my model"
    assert len(real_d) == len(d)
Example #3
0
    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_magic_getdoc():
    model_src = '''"""
This is the doc of my model
"""
%pylab inline
print "ok"
'''
    d = get_docstring(model_src)
    assert d is not None

    real_d = "This is the doc of my model"
    assert len(real_d) == len(d)
Example #5
0
def test_ast_getdoc_not_first_line():
    model_src = '''
print "ok"
result = 42


"""
ok
"""
'''
    d = get_docstring(model_src)
    real_d = "ok"
    assert len(real_d) == len(d)
def test_ast_getdoc_not_first_line():
    model_src = '''
print "ok"
result = 42


"""
ok
"""
'''
    d = get_docstring(model_src)
    real_d = "ok"
    assert len(real_d) == len(d)
Example #7
0
def test_docstring_oneline():
    model_src = '''"""
model1(x,y)->r

beautifull doc
"""

r = x + y
'''
    d = get_docstring(model_src)
    model, inputs, outputs = parse_function(d)
    assert model == "model1"
    assert inputs == ['x', 'y']
    assert outputs == ['r']
def test_docstring_oneline():
    model_src = '''"""
model1(x,y)->r

beautifull doc
"""

r = x + y
'''
    d = get_docstring(model_src)
    model, inputs, outputs = parse_function(d)
    assert model == "model1"
    assert inputs == ['x', 'y']
    assert outputs == ['r']
Example #9
0
def test_docstring_input():
    model_src = '''"""

input = x:int=4, y:float=3.14, z, debug:bool
output = success

beautifull doc
"""

print "ok"
'''
    d = get_docstring(model_src)
    inputs, outputs = parse_input_and_output(d)
    assert inputs == ['x:int=4', 'y:float=3.14', 'z', 'debug:bool']
    assert outputs == ['success']
def test_docstring_input():
    model_src = '''"""

input = x:int=4, y:float=3.14, z, debug:bool
output = success

beautifull doc
"""

print "ok"
'''
    d = get_docstring(model_src)
    inputs, outputs = parse_input_and_output(d)
    assert inputs == ['x:int=4', 'y:float=3.14', 'z', 'debug:bool']
    assert outputs == ['success']
Example #11
0
    def set_code(self, code):
        """
        Set the content and parse it to get docstring, inputs and outputs info, some methods
        """
        self._initial_code, control = import_lpy_file(code)
        self._doc = get_docstring(code)
        docstring = parse_lpy(code)
        if docstring is not None:
            model, self.inputs_info, self.outputs_info = parse_doc(docstring)

        # Default input
        if self.inputs_info == []:
            self.inputs_info = [InputObj('lstring:IStr')]
        # Default output
        if self.outputs_info == []:
            self.outputs_info = [OutputObj("lstring:IStr")]
Example #12
0
def test_ast_getdoc():
    model_src = '''"""
This is the doc of my model
"""

print "ok"
result = 42


"""
ok
"""
'''
    d = get_docstring(model_src)

    real_d = "This is the doc of my model"
    assert len(real_d) == len(d)
def test_ast_getdoc():
    model_src = '''"""
This is the doc of my model
"""

print "ok"
result = 42


"""
ok
"""
'''
    d = get_docstring(model_src)

    real_d = "This is the doc of my model"
    assert len(real_d) == len(d)
Example #14
0
 def get_documentation(self):
     from openalea.oalab.model.parse import get_docstring
     return get_docstring(self.read())