Ejemplo n.º 1
0
def test_parse_code():
    code = '''
"""
input = a,b
output = c
"""
c = a+b
'''
    from openalea.core.model import PythonModel

    m1 = PythonModel(name='m1', code=code)
    m2 = PythonModel(name='m2')

    m2.code = code

    m3 = PythonModel(name='m3')
    m3.set_code(code)

    assert m1.run(a=1, b=2) == 3
    assert m2.run(a=2, b=3) == 5
    assert m3.run(a=3, b=4) == 7

    m1 = PythonModel(name='ModelWithoutDoc')
    assert m1.get_documentation() == ''

    m1 = PythonModel(name='ModelWithDoc', code=code)
    assert m1.get_documentation()
Ejemplo n.º 2
0
def test_parse_code():
    code = '''
"""
input = a,b
output = c
"""
c = a+b
'''
    from openalea.core.model import PythonModel

    m1 = PythonModel(name='m1', code=code)
    m2 = PythonModel(name='m2')

    m2.code = code

    m3 = PythonModel(name='m3')
    m3.set_code(code)

    assert m1.run(a=1, b=2) == 3
    assert m2.run(a=2, b=3) == 5
    assert m3.run(a=3, b=4) == 7

    m1 = PythonModel(name='ModelWithoutDoc')
    assert m1.get_documentation() == ''

    m1 = PythonModel(name='ModelWithDoc', code=code)
    assert m1.get_documentation()
Ejemplo n.º 3
0
def load_data():
    model = PythonModel(name='func')
    model.set_code(code)

    tmpdir = tempdir()

    data = PythonFile(content=code, path=tmpdir / "test.py")

    # ns is provided by tester
    editor = ns['editor_manager']
    editor.open_data(data)
Ejemplo n.º 4
0
def load_data():
    model = PythonModel(name='func')
    model.set_code(code)

    tmpdir = tempdir()

    data = PythonFile(content=code, path=tmpdir / "test.py")

    # ns is provided by tester
    editor = ns['editor_manager']
    editor.open_data(data)
Ejemplo n.º 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
Ejemplo n.º 6
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
Ejemplo n.º 7
0
class TestCaseParadigmEditor(QtTestCase):
    def setUp(self):
        self.init()
        self.tmpdir = tempdir()

        self.model = PythonModel(name='func')
        self.model.set_code(SAMPLE_CODE)
        self.data = PythonFile(content=SAMPLE_CODE,
                               path=self.tmpdir / "test.py")

    def tearDown(self):
        self.tmpdir.rmtree()
        self.finalize()

    def test_open_data(self):
        self.widget = ParadigmContainer()
        self.widget.open_data(self.data)

    def test_apply_and_save(self):
        self.widget = ParadigmContainer()
        self.widget.open_data(self.data)

        memory_code = "# How are you ?"
        hdd_code = "# Fine!"

        pyqode = self.widget.currentWidget()

        pyqode.setPlainText(memory_code)

        # Unchanged because data has not been saved
        self.assertEquals(self.data.content, SAMPLE_CODE)

        # APPLY: change data object but do not save on disk
        self.widget.apply()
        # Changed in memory but not on disk
        self.assertFalse(self.data.path.exists())
        self.assertEquals(self.data.content, memory_code)

        pyqode.setPlainText(hdd_code)
        self.widget.save()
        # SAVE: change data object and save to disk
        with open(self.data.path, 'r') as f:
            disk_code = f.read()
        self.assertEquals(self.data.content, hdd_code)
        self.assertEquals(disk_code, hdd_code)
Ejemplo n.º 8
0
class TestCaseParadigmEditor(QtTestCase):

    def setUp(self):
        self.init()
        self.tmpdir = tempdir()

        self.model = PythonModel(name='func')
        self.model.set_code(SAMPLE_CODE)
        self.data = PythonFile(content=SAMPLE_CODE, path=self.tmpdir / "test.py")

    def tearDown(self):
        self.tmpdir.rmtree()
        self.finalize()

    def test_open_data(self):
        self.widget = ParadigmContainer()
        self.widget.open_data(self.data)

    def test_apply_and_save(self):
        self.widget = ParadigmContainer()
        self.widget.open_data(self.data)

        memory_code = "# How are you ?"
        hdd_code = "# Fine!"

        pyqode = self.widget.currentWidget()

        pyqode.setPlainText(memory_code)

        # Unchanged because data has not been saved
        self.assertEquals(self.data.content, SAMPLE_CODE)

        # APPLY: change data object but do not save on disk
        self.widget.apply()
        # Changed in memory but not on disk
        self.assertFalse(self.data.path.exists())
        self.assertEquals(self.data.content, memory_code)

        pyqode.setPlainText(hdd_code)
        self.widget.save()
        # SAVE: change data object and save to disk
        with open(self.data.path, 'r') as f:
            disk_code = f.read()
        self.assertEquals(self.data.content, hdd_code)
        self.assertEquals(disk_code, hdd_code)