コード例 #1
0
    def load(self, file_name=None):
        """
        This method load a file.

        Returns:
            * **Types** (:class:`boolean<boolean>`)
        """
        if self.diagram is None:
            return None, "It is necessary to create a diagram and load on it."

        if file_name is None and self.diagram.file_name is None:
            return None, "Cannot Load without filename"

        if file_name is not None:
            self.diagram.file_name = file_name

        if not os.path.exists(self.diagram.file_name):
            return None, "File '" + self.diagram.file_name + "' does not exist!"

        DiagramPersistence.load(self.diagram)
        self.diagram.redo_stack = []
        self.diagram.undo_stack = []
        self.diagram.redraw()
        self.diagram.set_modified(False)

        return self.diagram, "Success"
コード例 #2
0
    def test_load_wrong_diagram(self):
        port = Port()
        port.hint = "test"
        PortPersistence.save_xml(port, path="/tmp/")
        file_name = "/tmp/" + port.hint + ".xml"
        result = DiagramPersistence.load(file_name)
        self.assertNotEquals(result, True)

        diagram = self.create_full_diagram()
        diagram.file_name = file_name
        result = DiagramPersistence.load(diagram)
        self.assertNotEquals(result, True)
        os.remove(file_name)
コード例 #3
0
    def test_load_save(self):
        diagram = self.create_full_diagram()
        diagram.file_name = "/tmp/Diagram.msc"
        result = DiagramPersistence.save(diagram)
        assert result
        result = DiagramPersistence.load(diagram)
        assert result
        os.remove(diagram.file_name)

        diagram = self.create_diagram()
        diagram.file_name = "/tmp/Diagram.msc"
        result = DiagramPersistence.save(diagram)
        assert result
        result = DiagramPersistence.load(diagram)
        assert result
        os.remove(diagram.file_name)
コード例 #4
0
class TestDiagramPersistence(TestCase):

    def setUp(self):
        """Do the test basic setup."""
        self.diagrampersistence = DiagramPersistence()

    # ----------------------------------------------------------------------x
    def test_load(self):

        diagram = Diagram(MainWindow())
        # NOTE: TESTANDO COM DIAGRAM = None
        # BUG: NÃO TRATA None
        # diagram = None
        # self.assertIsNone(self.diagrampersistence.load(diagram))

        # NOTE: TESTANDO COM NOME DE ARQUIVO VERDADEIRO
        diagram.file_name = "/home/lucas/mosaicode/teste/Untitled.mscd"
        self.assertTrue(self.diagrampersistence.load(diagram))

        # NOTE: TESTANDO COM NOME DE ARQUIVO INEXISTENTE
        # BUG: NÃO TRATA DIAGRAM INEXISTENTE
        # diagram.file_name = "/home/lucas/mosaicode/extensions/teste.py"
        # self.assertIsNone(self.diagrampersistence.load(diagram))

    # ----------------------------------------------------------------------x
    def test_save(self):
        # NÃO TRABALHA COM None
        # diagram = None
        # self.assertTrue(self.diagrampersistence.save(diagram))

        diagram = Diagram(MainWindow())
        self.assertTrue(self.diagrampersistence.save(diagram))

        diagram.file_name = "Template de teste"
        self.assertTrue(self.diagrampersistence.save(diagram))
コード例 #5
0
 def test_load_wrong_code_template(self):
     diagram = self.create_full_diagram()
     diagram.code_template = "Fail"
     result = DiagramPersistence.save(diagram)
     assert result
     result = DiagramPersistence.load(diagram)
     assert result
     os.remove(diagram.file_name)
コード例 #6
0
    def load(self, file_name=None):
        """
        This method load a file.

        Returns:
            * **Types** (:class:`boolean<boolean>`)
        """
        if file_name is not None:
            self.diagram.file_name = file_name
        else:
            if self.diagram.file_name is None:
                System.log("Cannot Load without filename")
                return False
        if not os.path.exists(self.diagram.file_name):
            System.log("File '" + self.diagram.file_name + "' does not exist!")
            return False

        DiagramPersistence.load(self.diagram)
        self.diagram.redo_stack = []
        self.diagram.undo_stack = []
コード例 #7
0
 def test_load_wrong_block(self):
     diagram = self.create_full_diagram()
     diagram_control = self.create_diagram_control()
     diagram = diagram_control.diagram
     block1 = self.create_block()
     block1.type = "Worng Block Type"
     diagram_control.add_block(block1)
     result = DiagramPersistence.save(diagram)
     assert result
     result = DiagramPersistence.load(diagram)
     assert result
     os.remove(diagram.file_name)
コード例 #8
0
    def test_load(self):
        file_name = get_temp_file() + ".mscd"
        diagram_control = self.create_diagram_control()

        comment = Comment(diagram_control.diagram)
        comment.diagram.file_name = file_name
        DiagramControl.add_comment(comment.diagram, comment)

        DiagramPersistence.save(comment.diagram)
        result = DiagramPersistence.load(comment.diagram)

        os.remove(file_name)

        self.assertTrue(result, "Failed to load preferences")
コード例 #9
0
    def test_load_save(self):
        file_name = get_temp_file() + ".mscd"
        diagram_control = self.create_diagram_control()
        diagram = diagram_control.diagram

        diagram.file_name = "."
        DiagramPersistence.save(diagram)

        comment = Comment(diagram)
        diagram.file_name = file_name
        DiagramControl.add_comment(diagram, comment)

        System()
        blocks = System.get_blocks()
        for key in blocks:
            block1 = Block(diagram, blocks[key])
            DiagramControl.add_block(diagram, block1)

        source = None
        source_port = None
        for key in diagram.blocks:
            for port in diagram.blocks[key].ports:
                if not port.is_input():
                    source = diagram.blocks[key]
                    source_port = port
                    break

        sink = None
        sink_port = None
        for key in diagram.blocks:
            for port in diagram.blocks[key].ports:
                if port.is_input():
                    sink = diagram.blocks[key]
                    sink_port = port
                    break

        connection = ConnectionModel(diagram, source, source_port, sink,
                                     sink_port)
        DiagramControl.add_connection(diagram, connection)

        block0 = self.create_block(diagram_control)

        DiagramPersistence.save(diagram)

        System.remove_block(blocks.values()[0])
        result = DiagramPersistence.load(diagram)

        os.remove(file_name)