Пример #1
0
    def setUp(self):
        """Do the test basic setup."""
        win = MainWindow()
        self.diagram = Diagram(win)

        blockmodel = BlockModel()
        self.block = Block(self.diagram, blockmodel)
Пример #2
0
 def create_diagram(self, main_window=None):
     if main_window is None:
         main_window = self.create_main_window()
     diagram = Diagram(main_window)
     diagram.language = "Test"
     diagram.zoom = 2
     diagram.code_template = self.create_code_template()
     return diagram
Пример #3
0
 def setUp(self):
     self.main_window = self.create_main_window()
     self.diagram = Diagram(self.main_window)
     self.block1 = self.create_block()
     self.main_window.main_control.add_block(self.block1)
     self.block2 = self.create_block()
     self.main_window.main_control.add_block(self.block2)
     self.comment = self.create_comment()
     self.main_window.main_control.add_comment(self.comment)
Пример #4
0
 def open(self, file_name):
     """
     This method open a file.
     """
     diagram = Diagram(self.main_window)
     self.main_window.work_area.add_diagram(diagram)
     DiagramControl(diagram).load(file_name)
     diagram.set_modified(False)
     MainControl.add_recent_file(System.properties, file_name)
     self.main_window.menu.update_recent_file()
Пример #5
0
    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))
Пример #6
0
    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))
Пример #7
0
    def test_save(self):
        # NÃO TRABALHA COM None
        # block = None
        # self.assertTrue(self.blockpersistence.save(block))

        diagram = Diagram(MainWindow())
        block = Block(diagram, None)
        self.assertTrue(self.blockpersistence.save(block))

        diagram = Diagram(MainWindow())
        blockmodel = BlockModel(None)
        block = Block(diagram, blockmodel)
        block.type = "teste_blockpersistence"
        self.assertTrue(self.blockpersistence.save(block))
Пример #8
0
    def create_full_diagram(self, main_window=None):
        if main_window is None:
            main_window = self.create_main_window()
        diagram = Diagram(main_window)
        self.assertEquals(diagram.last_id, 0)
        diagram.language = "Test"
        diagram.zoom = 2
        diagram_control = self.create_diagram_control(diagram)

        block0 = self.create_block(diagram_control)
        result = diagram_control.add_block(block0)

        block1 = self.create_block(diagram_control)
        result = diagram_control.add_block(block1)
        assert result

        block2 = self.create_block(diagram_control)
        result = diagram_control.add_block(block2)
        assert result

        connection = ConnectionModel(diagram, block1, block1.ports[0], block2,
                                     block2.ports[0])
        result = diagram_control.add_connection(connection)
        self.assertEquals(result[0], False)

        connection = ConnectionModel(diagram, block1, block1.ports[1], block2,
                                     block2.ports[0])
        result = diagram_control.add_connection(connection)
        self.assertEquals(result[1], "Success")

        connection = ConnectionModel(diagram, block2, block2.ports[1], block1,
                                     block1.ports[1])
        result = diagram_control.add_connection(connection)
        self.assertEquals(result[0], False)

        connection = ConnectionModel(diagram, block1, block1.ports[1], block1,
                                     block1.ports[0])
        result = diagram_control.add_connection(connection)
        self.assertEquals(result[0], False)

        connection = ConnectionModel(diagram, None, None, None, None)
        result = diagram_control.add_connection(connection)
        self.assertEquals(result[0], False)

        comment = self.create_comment(diagram)
        diagram_control.add_comment(comment)
        comment = self.create_comment(diagram)
        diagram_control.add_comment(comment)
        diagram.code_template = self.create_code_template()
        return diagram
Пример #9
0
 def setUp(self):
     """Do the test basic setup."""
     win = MainWindow()
     diagram = Diagram(MainWindow())
     blockmodel = BlockModel()
     self.block = Block(diagram, blockmodel)
     self.blockmenu = BlockMenu(self.block, None)
Пример #10
0
 def setUp(self):
     """Do the test basic setup."""
     diagram = Diagram(MainWindow())
     blockmodel = BlockModel()
     block = Block(diagram, blockmodel)
     blockmodel = BlockModel(None)
     self.blockcodeeditor = BlockCodeEditor(BlockEditor(), Block())
Пример #11
0
    def create_full_diagram(self):
        main_window = self.create_main_window()
        diagram = Diagram(main_window)
        diagram_control = self.create_diagram_control()
        diagram = diagram_control.diagram

        block1 = self.create_block()
        diagram_control.add_block(block1)

        block2 = self.create_block()
        diagram_control.add_block(block2)

        connection = ConnectionModel(diagram, block1, block1.ports[0], block2,
                                     block2.ports[1])
        diagram_control.add_connection(connection)

        connection = ConnectionModel(diagram, block1, block1.ports[1], block2,
                                     block2.ports[0])
        diagram_control.add_connection(connection)

        connection = ConnectionModel(diagram, None, None, None, None)
        diagram_control.add_connection(connection)

        comment = self.create_comment()
        main_window.main_control.add_comment(comment)
        diagram_control.add_comment(comment)
        return diagram
Пример #12
0
    def setUp(self):
        """Do the test basic setup."""
        win = MainWindow()
        self.blockmanager = BlockManager(win)

        diagram = Diagram(MainWindow())
        blockmodel = BlockModel()
        self.block = Block(diagram, blockmodel)
Пример #13
0
    def setUp(self):
        """Do the test basic setup."""
        win = MainWindow()

        diagram = Diagram(win)
        blockmodel = BlockModel()
        block = Block(diagram, blockmodel)

        block_manager = BlockManager(win)
        self.blockporteditor = BlockPortEditor (block_manager, block)
Пример #14
0
    def test_set_block(self):
        # from mosaicode.GUI.block import Block
        # from mosaicode.GUI.diagram import Diagram as Diagram
        # from mosaicode.model.blockmodel import BlockModel as BlockModel
        #
        # block = Block(Diagram, BlockModel)
        # self.assertIsNone(self.main_control.set_block(block))

        diagram = Diagram(MainWindow())
        blockmodel = BlockModel()
        block = Block(diagram, blockmodel)
        self.assertIsNone(self.main_control.set_block(block))
    def setUp(self):
        """Do the test basic setup."""
        win = MainWindow
        diagram = Diagram(win)
        blockmodel = BlockModel()

        block = Block(diagram, blockmodel)

        block_manager = BlockManager(win)
        block_editor = BlockEditor(block_manager, block)

        self.block_property_editor = BlockPropertyEditor(block_editor, block)
Пример #16
0
 def open(self, file_name):
     """
     This method open a file.
     """
     diagram = Diagram(self.main_window)
     result = DiagramControl(diagram).load(file_name)
     if result[0] is None:
         self.message_dialog = MessageDialog("Error", result[1],
                                             self.main_window)
         self.message_dialog.run()
         return
     diagram = result[0]
     System.add_recent_files(file_name)
Пример #17
0
    def setUp(self):
        """Do the test basic setup."""
        win = MainWindow()
        diagram = Diagram(win)

        blockmodel = BlockModel()
        source = Block(diagram, blockmodel)

        # NAO TRATA NONE
        # source = None
        source_port = 0
        conn_type = None
        self.connector = Connector(diagram, source, source_port, conn_type)
Пример #18
0
    def test_add_block(self):
        # QUALQUER UMA DAS FORMAS ABAIXO APRESENTARÁ NONE
        # self.assertIsNone(self.blockmanager.add_block(self.block))
        # self.assertIsNone(self.blockmanager.add_block(None))

        # self.block.label = "Teste"
        # self.assertIsNone(self.blockmanager.add_block(self.block))

        diagram = Diagram(MainWindow())
        blockmodel = BlockModel()
        block = Block(diagram, blockmodel)

        block.label = "Teste Block manager"

        self.assertIsNone(self.blockmanager.add_block(block))
Пример #19
0
    def open(self, file_name):
        """
        This method open a file.
        """
        diagram = Diagram(self.main_window)
        self.main_window.work_area.add_diagram(diagram)
        DiagramControl(diagram).load(file_name)
        diagram.redraw()
        diagram.set_modified(False)

        self.set_recent_files(file_name)
Пример #20
0
    def open(self, file_name):
        """
        This method open a file.
        """
        diagram = Diagram(self.main_window)
        self.main_window.work_area.add_diagram(diagram)
        if not DiagramControl(diagram).load(file_name):
            System.log("Problem Loading the Diagram")
        diagram.redraw()
        diagram.set_modified(False)

        self.set_recent_files(file_name)
Пример #21
0
    def open(self, file_name):
        """
        This method open a file.
        """
        diagram = Diagram(self.main_window)
        self.main_window.work_area.add_diagram(diagram)
        DiagramControl(diagram).load(file_name)
        diagram.redraw()
        diagram.set_modified(False)

        if file_name in System.properties.recent_files:
            System.properties.recent_files.remove(file_name)
        System.properties.recent_files.insert(0, file_name)
        if len(System.properties.recent_files) > 10:
            System.properties.recent_files.pop()
        self.main_window.menu.update_recent_files(
            System.properties.recent_files)
Пример #22
0
    def test_delete_block(self):

        diagram = Diagram(MainWindow())
        blockmodel = BlockModel()
        block = Block(diagram, blockmodel)
        self.assertIsNone(self.main_control.delete_block(block))
Пример #23
0
class TestDiagram(TestBase):
    def setUp(self):
        self.main_window = self.create_main_window()
        self.diagram = Diagram(self.main_window)
        self.block1 = self.create_block()
        self.main_window.main_control.add_block(self.block1)
        self.block2 = self.create_block()
        self.main_window.main_control.add_block(self.block2)
        self.comment = self.create_comment()
        self.main_window.main_control.add_comment(self.comment)

    def test_redraw(self):
        self.diagram.redraw()

    def test_resize(self):
        self.diagram.resize(None)

    def test_show_block_menu(self):
        event = Gdk.Event().new(Gdk.EventType.BUTTON_PRESS)
        event.button = 3
        self.diagram.show_block_menu(self.block1, event)

    def test_change_zoom(self):
        DiagramControl(self.diagram).change_zoom(System.ZOOM_IN)
        DiagramControl(self.diagram).change_zoom(System.ZOOM_OUT)
        DiagramControl(self.diagram).change_zoom(System.ZOOM_ORIGINAL)

    def test_show_elements(self):
        self.diagram.show_comment_property(self.comment)
        self.diagram.show_block_property(self.block1)

    def test_connection(self):
        self.diagram.start_connection(self.block1, self.block1.ports[0])
        self.diagram.end_connection(self.block2, self.block2.ports[1])

    def test_button_press_event(self):
        event = Gdk.Event().new(Gdk.EventType.BUTTON_PRESS)
        event.button = 1
        event.state = Gdk.ModifierType.SHIFT_MASK | Gdk.ModifierType.MOD2_MASK
        self.diagram.emit("button_press_event", event)
        self.refresh_gui()
        event.state = Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.MOD2_MASK
        self.diagram.emit("button_press_event", event)
        self.refresh_gui()

        event.button = 2
        self.diagram.emit("button_press_event", event)
        self.refresh_gui()
        event.button = 3
        self.diagram.emit("button_press_event", event)
        self.refresh_gui()

    def test_check_limit(self):
        self.diagram.check_limit(0, 0, 800, 600)

    def test_collapse(self):
        self.diagram.collapse(True)
        self.diagram.collapse(False)

    def test_button_release_event(self):
        event = Gdk.Event().new(Gdk.EventType.BUTTON_PRESS)
        event.button = 1
        event.state = Gdk.ModifierType.BUTTON1_MASK
        self.diagram.emit("button_press_event", event)
        self.refresh_gui()
        self.diagram.emit("button_release_event", event)
        self.refresh_gui()

    def test_motion_notify_event(self):
        self.test_connection()
        event = Gdk.Event().new(Gdk.EventType.BUTTON_PRESS)
        event.button = 1
        event.state = Gdk.ModifierType.BUTTON1_MASK
        self.diagram.emit("button_press_event", event)
        self.refresh_gui()
        self.diagram.emit("motion_notify_event", event)
        self.refresh_gui()
        self.diagram.emit("button_release_event", event)
        self.refresh_gui()

        self.diagram.emit("motion_notify_event", event)
        self.refresh_gui()

        self.diagram.start_connection(self.block1, self.block1.ports[0])
        self.diagram.emit("motion_notify_event", event)
        self.refresh_gui()

    def test_key_press_event(self):
        event = Gdk.Event()
        event.key.type = Gdk.EventType.KEY_PRESS
        event.keyval = Gdk.KEY_Up
        self.diagram.emit("key-press-event", event)
        self.refresh_gui()
        event.keyval = Gdk.KEY_Down
        self.diagram.emit("key-press-event", event)
        self.refresh_gui()
        event.keyval = Gdk.KEY_Left
        self.diagram.emit("key-press-event", event)
        self.refresh_gui()
        event.keyval = Gdk.KEY_Right
        self.diagram.emit("key-press-event", event)
        self.refresh_gui()

        event.state = Gdk.ModifierType.CONTROL_MASK
        event.keyval = Gdk.KEY_Up
        self.diagram.emit("key-press-event", event)
        self.refresh_gui()
        event.keyval = Gdk.KEY_Down
        self.diagram.emit("key-press-event", event)
        self.refresh_gui()
        event.keyval = Gdk.KEY_Left
        self.diagram.emit("key-press-event", event)
        self.refresh_gui()
        event.keyval = Gdk.KEY_Right
        self.diagram.emit("key-press-event", event)
        self.refresh_gui()

        event.state = 0
        self.diagram.focus = True
        event.keyval = Gdk.KEY_Delete
        self.diagram.emit("key-press-event", event)
        self.refresh_gui()
Пример #24
0
 def create_diagram(self):
     return Diagram(self.create_main_window())
Пример #25
0
 def test_rename_diagram(self):
     diagram = Diagram(MainWindow())
     self.assertIsNone(self.work_area.rename_diagram(diagram))
Пример #26
0
 def test_add_diagram(self):
     # NÃO TRABALHA COM None
     # diagram = None
     # self.assertIsNone(self.work_area.add_diagram(diagram))
     diagram = Diagram(MainWindow())
     self.assertIsNone(self.work_area.add_diagram(diagram))
Пример #27
0
 def new(self):
     """
     This method create a new the diagram file.
     """
     Diagram(self.main_window)
Пример #28
0
 def test_show_block_property(self):
     diagram = Diagram(MainWindow())
     blockmodel = BlockModel()
     block = Block(diagram, blockmodel)
     self.assertIsNone(self.main_control.show_block_property(block))
Пример #29
0
class TestDiagram(TestCase):

    def setUp(self):
        """Do the test basic setup."""
        win = MainWindow()
        self.diagram = Diagram(win)

        blockmodel = BlockModel()
        self.block = Block(self.diagram, blockmodel)

    # ----------------------------------------------------------------------x
    def test_set_scrolled_window(self):
        frame = None
        self.assertIsNone(self.diagram.set_scrolled_window(frame))
        frame = None
        self.assertIsNone(self.diagram.set_scrolled_window(frame))

    # ----------------------------------------------------------------------x
    def test_update_scrolling(self):
        self.assertIsNone(self.diagram.update_scrolling())

    # ----------------------------------------------------------------------x
    def test_insert_block(self):
        self.assertTrue(self.diagram.insert_block(self.block))

        self.block.language = None
        self.assertFalse(self.diagram.insert_block(self.block))

        self.block.language = "test_diagram"
        self.assertFalse(self.diagram.insert_block(self.block))

        self.block.language = "c"
        self.assertFalse(self.diagram.insert_block(self.block))

        self.block.language = ""
        self.assertTrue(self.diagram.insert_block(self.block))

        # NÃO TRATA None
        #block = None
        #self.assertTrue(self.diagram.insert_block(block))

    # ----------------------------------------------------------------------x
    def test_add_block(self):
        #self.assertFalse(self.diagram.add_block(self.block))
        self.assertTrue(self.diagram.add_block(None))
        self.assertTrue(self.diagram.add_block(None))


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

        output = 0
        block = self.block
        self.assertIsNone(self.diagram.start_connection(block, output))

        output = 1
        block = self.block
        self.assertIsNone(self.diagram.start_connection(block, output))

        output = 2
        block = self.block
        self.assertIsNone(self.diagram.start_connection(block, output))

        # OUTPUT NEGATIVA NÃO PODE
        # output = -1
        # block = self.block
        # self.assertIsNone(self.diagram.start_connection(block, output))

        # NÃO TRATA None
        # output = None
        # block = self.block
        # self.assertIsNone(self.diagram.start_connection(block, output))

    # ----------------------------------------------------------------------x
    def test_end_connection(self):
        block = None
        block_input = None
        self.assertFalse(self.diagram.end_connection(block, block_input))
        #self.assertTrue(self.diagram.end_connection(block, block_input))

    # ----------------------------------------------------------------------x
    def test_set_show_grid(self):
        booleano = None
        self.assertIsNone(self.diagram.set_show_grid(booleano))
        booleano = True
        self.assertIsNone(self.diagram.set_show_grid(booleano))
        booleano = False
        self.assertIsNone(self.diagram.set_show_grid(booleano))

    # ----------------------------------------------------------------------x
    def test_update_flows(self):
        self.assertIsNone(self.diagram.update_flows())

    # ----------------------------------------------------------------------x
    def test_set_file_name(self):
        file_name = "Testando.txt"
        self.assertIsNone(self.diagram.set_file_name(file_name))

        # COLOCAR ARQUIVO DA PASTA TEST
        file_name = "/home/lucas/Faculdade/2017-1/Iniciacao/Mosaicode/mosaicode/test/files_for_test/input/And.mscd"
        self.assertIsNone(self.diagram.set_file_name(file_name))

    # ----------------------------------------------------------------------x
    def test_set_zoom(self):
        zoom = 0
        self.assertIsNone(self.diagram.set_zoom(zoom))
        zoom = -1
        self.assertIsNone(self.diagram.set_zoom(zoom))
        zoom = -23445
        self.assertIsNone(self.diagram.set_zoom(zoom))

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

        from mosaicode.system import System as System
        value = 0
        self.assertIsNone(self.diagram.change_zoom(value))
        value = System.ZOOM_IN
        self.assertIsNone(self.diagram.change_zoom(value))
        value = System.ZOOM_OUT
        self.assertIsNone(self.diagram.change_zoom(value))
        value = System.ZOOM_ORIGINAL
        self.assertIsNone(self.diagram.change_zoom(value))

    # ----------------------------------------------------------------------x
    def test_show_block_property(self):
        block = self.block
        self.assertIsNone(self.diagram.show_block_property(block))

    # ----------------------------------------------------------------------x
    def test_resize(self):
        data = {"label": "teste"}
        self.assertIsNone(self.diagram.resize(data))

    # ----------------------------------------------------------------------x
    def test_select_all(self):
        self.assertIsNone(self.diagram.select_all())

    # ----------------------------------------------------------------------x
    def test_move_selected_blocks(self):
        x = 0
        y = 0
        self.assertIsNone(self.diagram.move_selected_blocks(x, y))
        x = 50
        y = 100
        self.assertIsNone(self.diagram.move_selected_blocks(x, y))

    # ----------------------------------------------------------------------x
    def test_check_limit(self):
        x = 0
        y = 0
        block_pos_x = 10
        block_pos_y = 10
        self.assertIsNotNone(self.diagram.check_limit(x, y, block_pos_x, block_pos_y))

    # ----------------------------------------------------------------------x
    def test_get_selected_blocks_id(self):
        self.assertIsNotNone(self.diagram.get_selected_blocks_id())
        self.assertEqual([], self.diagram.get_selected_blocks_id())

    # ----------------------------------------------------------------------x
    def test_delete(self):
        self.assertIsNone(self.diagram.delete())

    # ----------------------------------------------------------------------x
    def test_paste(self):
        self.assertIsNone(self.diagram.paste())

    # ----------------------------------------------------------------------x
    def test_copy(self):
        self.assertIsNone(self.diagram.copy())

    # ----------------------------------------------------------------------x
    def test_cut(self):
        self.assertIsNone(self.diagram.cut())

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

        from mosaicode.GUI.connector import Connector

        blockmodel = BlockModel()

        source = Block(self.diagram, blockmodel)
        # NOTE: NAO TRATA None
        # source = None

        source_port = 0
        conn_type = None
        connection = Connector(self.diagram, source, source_port, conn_type)

        self.assertIsNone(self.diagram.delete_connection(connection))

        # NOTE: NAO TRATA None
        # connection = None
        # self.assertIsNone(self.diagram.delete_connection(connection))

    # ----------------------------------------------------------------------x
    def test_delete_block(self):
        block = self.block
        self.assertIsNone(self.diagram.delete_block(block))

    # ----------------------------------------------------------------------x
    def test_set_modified(self):
        state = True
        self.assertIsNone(self.diagram.set_modified(state))
        state = False
        self.assertIsNone(self.diagram.set_modified(state))
        state = None
        self.assertIsNone(self.diagram.set_modified(state))

    # ----------------------------------------------------------------------x
    def test_grab_focus(self):
        self.assertIsNone(self.diagram.grab_focus())

    # ----------------------------------------------------------------------x
    def test_redraw(self):
        self.assertIsNone(self.diagram.redraw())

    # ----------------------------------------------------------------------x
    def test_do(self):
        new_msg = "Testando Mensagens"
        self.assertIsNone(self.diagram.do(new_msg))
        #new_msg = 12
        #self.assertIsNone(self.diagram.do(new_msg))

    # ----------------------------------------------------------------------x
    def test_undo(self):
        self.assertIsNone(self.diagram.undo())

    # ----------------------------------------------------------------------x
    def test_redo(self):
        self.assertIsNone(self.diagram.redo())

    # ----------------------------------------------------------------------x
    def test_get_min_max(self):
        self.assertIsNotNone(self.diagram.get_min_max())

    # ----------------------------------------------------------------------x
    def test_align_top(self):
        self.assertIsNone(self.diagram.align_top())

    # ----------------------------------------------------------------------x
    def test_align_bottom(self):
        self.assertIsNone(self.diagram.align_bottom())

    # ----------------------------------------------------------------------x
    def test_align_left(self):
        self.assertIsNone(self.diagram.align_left())

    # ----------------------------------------------------------------------x
    def test_align_right(self):
        self.assertIsNone(self.diagram.align_right())
Пример #30
0
 def new(self):
     """
     This method create a new the diagram file.
     """
     self.main_window.work_area.add_diagram(Diagram(self.main_window))