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)
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)
def test_open_data(self): self.widget = ParadigmContainer() self.widget.open_data(self.data)
import random from openalea.oalab.paradigm.container import ParadigmContainer from openalea.core.service.data import DataFactory from openalea.core.path import path as Path from openalea.core.path import tempdir if __name__ == '__main__': tmp = tempdir() instance = QtGui.QApplication.instance() if instance is None: app = QtGui.QApplication([]) else: app = instance pmw = ParadigmContainer(None, None) def test(): model1 = DataFactory('data/model.py') pmw.open_data(model1) from openalea.oalab.shell import get_shell_class from openalea.core.service.ipython import interpreter as interpreter_ # Set interpreter interpreter = interpreter_() interpreter.user_ns['interp'] = interpreter interpreter.user_ns.update(locals()) interpreter.user_ns['pmw'] = pmw interpreter.user_ns['data'] = DataFactory