class TestMainControl(TestCase): def setUp(self): """Do the test basic setup.""" win = MainWindow() self.main_control = MainControl(win) # ---------------------------------------------------------------------- def test_new(self): self.assertIsNone(self.main_control.new()) # ---------------------------------------------------------------------- def test_select_open(self): self.assertIsNone(self.main_control.select_open()) # ---------------------------------------------------------------------- def test_open(self): file_name = "test/files_for_test/And.mscd" self.assertIsNone(self.main_control.open(file_name)) file_name = "app_data/teste/And.mscd" self.assertIsNone(self.main_control.open(file_name)) file_name = "app_data/teste/Outro.mscd" self.assertIsNone(self.main_control.open(file_name)) file_name = "app_data/testando" self.assertIsNone(self.main_control.open(file_name)) file_name = "app_data/testando/" self.assertIsNone(self.main_control.open(file_name)) file_name = "app_data/testando/testando.mscd" self.assertIsNone(self.main_control.open(file_name)) # ---------------------------------------------------------------------- def test_close(self): self.assertIsNotNone(self.main_control.close()) # ---------------------------------------------------------------------- def test_save(self): save_as = False self.assertIsNone(self.main_control.save(save_as)) save_as = True self.assertIsNone(self.main_control.save(save_as)) # ---------------------------------------------------------------------- def test_save_as(self): self.assertIsNone(self.main_control.save_as()) # ---------------------------------------------------------------------- #def test_rename_tab(self): # self.main_control.rename_tab() # ---------------------------------------------------------------------- def test_export_diagram(self): self.assertIsNone(self.main_control.export_diagram()) # ---------------------------------------------------------------------- def test_exit(self): widget1 = None data1 = None self.assertIsNone(self.main_control.exit(widget1, data1)) #widget1 = O QUE E ESSE WIDGET? #data1 = O QUE E ESSE DATA? #self.assertTrue(self.main_control.exit(widget1, data)) # ---------------------------------------------------------------------- def test_select_all(self): self.assertIsNone(self.main_control.select_all()) # ---------------------------------------------------------------------- def test_cut(self): self.assertIsNone(self.main_control.cut()) # ---------------------------------------------------------------------- def test_copy(self): self.assertIsNone(self.main_control.copy()) # ---------------------------------------------------------------------- def test_paste(self): self.assertIsNone(self.main_control.paste()) # ---------------------------------------------------------------------- def test_get_clipboard(self): self.assertIsNotNone(self.main_control.get_clipboard()) #self.assertEqual("expected", self.main_control.get_clipboard()) # ---------------------------------------------------------------------- def test_reset_clipboard(self): self.assertIsNone(self.main_control.reset_clipboard()) # ---------------------------------------------------------------------- def test_preferences(self): self.assertIsNone(self.main_control.preferences()) # ---------------------------------------------------------------------- def test_delete(self): self.assertIsNone(self.main_control.delete()) # ---------------------------------------------------------------------- def test_run(self): code = None self.assertIsNone(self.main_control.run(code)) code = "Teste" self.assertIsNone(self.main_control.run(code)) # ---------------------------------------------------------------------- def test_save_source(self): code = None self.assertIsNone(self.main_control.save_source(code)) code = "Teste" self.assertIsNone(self.main_control.save_source(code)) # ---------------------------------------------------------------------- def test_view_source(self): self.assertIsNone(self.main_control.view_source()) # ---------------------------------------------------------------------- def test_about(self): self.assertIsNone(self.main_control.about()) # ---------------------------------------------------------------------- def test_search(self): query = None self.assertIsNone(self.main_control.search(query)) query = "Teste" self.assertIsNone(self.main_control.search(query)) # ---------------------------------------------------------------------- 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)) #block2 = None #self.assertIsNone(self.main_control.set_block(block2)) # ---------------------------------------------------------------------- def test_append_status_log(self): self.assertIsNone(self.main_control.append_status_log("TEXT")) #self.assertIsNone(self.main_control.append_status_log(None)) # ---------------------------------------------------------------------- def test_add_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.assertFalse(self.main_control.add_block(None)) #self.assertFalse(self.main_control.add_block(block)) self.assertFalse(self.main_control.add_block("TESTE")) # ---------------------------------------------------------------------- def test_get_selected_block(self): #self.assertIsNotNone(self.main_control.get_selected_block()) self.assertIsNone(self.main_control.get_selected_block()) # ---------------------------------------------------------------------- def test_zoom_in(self): self.assertIsNone(self.main_control.zoom_in()) # ---------------------------------------------------------------------- def test_zoom_out(self): self.assertIsNone(self.main_control.zoom_out()) # ---------------------------------------------------------------------- def test_zoom_normal(self): self.assertIsNone(self.main_control.zoom_normal()) # ---------------------------------------------------------------------- def test_show_block_property(self): diagram = Diagram(MainWindow()) blockmodel = BlockModel() block = Block(diagram, blockmodel) self.assertIsNone(self.main_control.show_block_property(block)) # ---------------------------------------------------------------------- def test_clear_console(self): self.assertIsNone(self.main_control.clear_console()) # ---------------------------------------------------------------------- def test_undo(self): self.assertIsNone(self.main_control.undo()) # ---------------------------------------------------------------------- def test_redo(self): self.assertIsNone(self.main_control.redo()) # ---------------------------------------------------------------------- def test_reload(self): self.assertIsNone(self.main_control.reload()) # ---- METODOS DIFERENTES ------ # ---------------------------------------------------------------------- def test_align_top(self): self.assertFalse(self.main_control.align_top()) # ---------------------------------------------------------------------- def test_align_bottom(self): self.assertFalse(self.main_control.align_bottom()) # ---------------------------------------------------------------------- def test_align_left(self): self.assertFalse(self.main_control.align_left()) # ---------------------------------------------------------------------- def test_align_right(self): self.assertFalse(self.main_control.align_right()) # ---------------------------------------------------------------------- def test_redraw(self): show_grid = None self.assertIsNone(self.main_control.redraw(show_grid)) # ---------------------------------------------------------------------- def test_show_grid(self): event = "None" self.assertIsNone(self.main_control.show_grid(event)) # ---------------------------------------------------------------------- def test_code_template_manager(self): self.assertIsNone(self.main_control.code_template_manager()) # ---------------------------------------------------------------------- def test_block_manager(self): self.assertIsNone(self.main_control.block_manager()) # ---------------------------------------------------------------------- def test_port_manager(self): self.assertIsNone(self.main_control.port_manager()) # ---------------------------------------------------------------------- def test_add_code_template(self): #code_template = None #self.assertIsNone(self.main_control.add_code_template(code_template)) from mosaicode.model.codetemplate import CodeTemplate code_template = CodeTemplate() code_template.type = "c" code_template.name = "TESTE" code_template.source = "xml" self.assertIsNone(self.main_control.add_code_template(code_template)) # ---------------------------------------------------------------------- def test_delete_code_template(self): #code_template_name = None #self.assertIsNone(self.main_control.delete_code_template(code_template_name)) #from mosaicode.model.codetemplate import CodeTemplate code_template_name = "TESTE" self.assertIsNone( self.main_control.delete_code_template(code_template_name)) # ---------------------------------------------------------------------- def test_add_port(self): from mosaicode.model.port import Port port = Port() port.type = "c" port.language = "c" port.source = "xml" port.code = "xxxx" self.assertIsNone(self.main_control.add_port(port)) # ---------------------------------------------------------------------- def test_delete_port(self): from mosaicode.model.port import Port port = Port() port.type = "c" port.language = "c" port.source = "xml" port.code = "xxxx" self.assertIsNone(self.main_control.delete_port(port)) # ---------------------------------------------------------------------- def test_add_new_block(self): diagram = Diagram(MainWindow()) blockmodel = BlockModel() block = Block(diagram, blockmodel) self.assertIsNone(self.main_control.add_new_block(block)) # NÃO TRATA None # block = None # self.assertIsNone(self.main_control.add_new_block(block)) # ---------------------------------------------------------------------- def test_delete_block(self): diagram = Diagram(MainWindow()) blockmodel = BlockModel() block = Block(diagram, blockmodel) self.assertIsNone(self.main_control.delete_block(block)) # NÃO TRATA None # block = None # self.assertIsNone(self.main_control.delete_block(block)) # ---------------------------------------------------------------------- def test_update_all(self): self.assertIsNone(self.main_control.update_all()) # ---------------------------------------------------------------------- def test_print_ports(self): self.assertIsNone(self.main_control.print_ports()) # ---------------------------------------------------------------------- def test_print_blocks(self): self.assertIsNone(self.main_control.print_blocks()) # ---------------------------------------------------------------------- def test_print_templates(self): self.assertIsNone(self.main_control.print_templates()) # ---------------------------------------------------------------------- def test_export_extensions(self): self.assertIsNone(self.main_control.export_extensions(None)) # ---------------------------------------------------------------------- def test_export_python(self): self.assertIsNone(self.main_control.export_python()) # ---------------------------------------------------------------------- def test_export_python_dialog(self): self.assertIsNone(self.main_control.export_python_dialog()) # ---------------------------------------------------------------------- def test_export_xml(self): self.assertIsNone(self.main_control.export_xml()) # ---------------------------------------------------------------------- def test_export_xml_dialog(self): self.assertIsNone(self.main_control.export_xml_dialog()) # ---------------------------------------------------------------------- def test_add_recent_file(self): #prefs = ? from mosaicode.model.preferences import Preferences prefs = Preferences() file_name = "../files_for_test/output/Untitled.mscd" self.assertIsNone(self.main_control.add_recent_file(prefs, file_name))
class TestMainControl(TestBase): def setUp(self): self.main_control = MainControl(self.create_main_window()) self.main_control.init() self.main_control.new() def test_about(self): self.main_control.about() def test_add_block(self): self.main_control.add_block(self.create_block()) def test_add_comment(self): self.main_control.add_comment() def test_add_extension(self): self.main_control.add(self.create_block()) self.main_control.add(self.create_code_template()) self.main_control.add(self.create_port()) def test_align_bottom(self): self.main_control.align_bottom() def test_align_left(self): self.main_control.align_left() def test_align_right(self): self.main_control.align_right() def test_align_top(self): self.main_control.align_top() def test_clear_console(self): self.main_control.clear_console() def test_close(self): self.main_control.close() def test_collapse_all(self): self.main_control.collapse_all() def test_copy(self): self.main_control.copy() def test_cut(self): self.main_control.cut() def test_delete(self): self.main_control.delete() def test_delete_extension(self): self.main_control.delete(self.create_block()) self.main_control.delete(self.create_code_template()) self.main_control.delete("port_key") def test_exit(self): self.main_control.exit() def test_export_diagram(self): self.main_control.export_diagram() def test_get_clipboard(self): self.main_control.get_clipboard() def test_get_selected_block(self): self.main_control.get_selected_block() def test_init(self): self.main_control.init() def test_new(self): self.main_control.new() def test_open(self): self.main_control.open("Test") def test_paste(self): self.main_control.paste() def test_preferences(self): self.main_control.preferences() def test_publish(self): self.main_control.publish() def test_redo(self): self.main_control.redo() def test_redraw(self): self.main_control.redraw(True) self.main_control.redraw(False) def test_reset_clipboard(self): self.main_control.reset_clipboard() def test_run(self): self.main_control.run() def test_save(self): self.main_control.save() self.main_control.save(save_as=True) def test_save_as(self): self.main_control.save_as() def test_save_as_example(self): self.main_control.save_as_example() def test_save_source(self): self.main_control.save_source() self.main_control.save_source(codes="Test") self.main_control.save_source(generator="Test") def test_search(self): self.main_control.search("Test") def test_select_all(self): self.main_control.select_all() def test_select_open(self): self.main_control.select_open() def test_set_block(self): self.main_control.set_block(self.create_block()) def test_set_recent_files(self): self.main_control.set_recent_files("Test") def test_show_grid(self): self.main_control.show_grid(None) def test_stop(self): self.main_control.stop(None, None) def test_uncollapse_all(self): self.main_control.uncollapse_all() def test_undo(self): self.main_control.undo() def test_update_all(self): self.main_control.update_all() def test_update_blocks(self): self.main_control.update_blocks() def test_view_source(self): self.main_control.view_source() def test_zoom_in(self): self.main_control.zoom_in() def test_zoom_normal(self): self.main_control.zoom_normal() def test_zoom_out(self): self.main_control.zoom_out()
class TestMainControl(TestBase): def setUp(self): self.main_window = self.create_main_window() self.main_control = MainControl(self.main_window) self.main_control.init() self.diagram = self.create_full_diagram(main_window=self.main_window) self.main_window.work_area.add_diagram(self.diagram) self.diagram.set_modified(False) def test_init(self): System() System.add_plugin(Plugin()) self.main_control.init() def test_select_open(self): t1 = threading.Thread(target=self.main_control.select_open, args=(None, )) t1.start() sleep(1) if self.main_control.open_dialog: self.main_control.open_dialog.response(Gtk.ResponseType.CANCEL) t1.join() diagram = self.create_full_diagram(main_window=self.main_window) diagram.file_name = "/tmp/Test.mscd" DiagramControl(diagram).save() path = "/tmp/" System.set_user_dir(path) t1 = threading.Thread(target=self.main_control.select_open, args=(path, )) t1.start() sleep(1) if self.main_control.open_dialog: self.main_control.open_dialog.set_filename("/tmp/Test.mscd") self.main_control.open_dialog.response(Gtk.ResponseType.OK) t1.join() os.remove("/tmp/Test.mscd") def test_open(self): t1 = threading.Thread(target=self.main_control.open, args=("Test", )) t1.start() sleep(1) if self.main_control.message_dialog: self.main_control.message_dialog.response(Gtk.ResponseType.CANCEL) self.refresh_gui() t1.join() def test_save(self): # diagram is null self.diagram.set_modified(False) self.main_window.work_area.close_tabs() t1 = threading.Thread(target=self.main_control.save, args=(None, )) t1.start() sleep(1) if self.main_control.save_dialog: self.main_control.save_dialog.response(Gtk.ResponseType.CANCEL) self.refresh_gui() t1.join() self.main_control.new() t1 = threading.Thread(target=self.main_control.save, args=(None, )) t1.start() sleep(1) if self.main_control.save_dialog: self.main_control.save_dialog.response(Gtk.ResponseType.OK) self.refresh_gui() t1.join() # Cancel button self.main_control.new() t1 = threading.Thread(target=self.main_control.save, args=(None, )) t1.start() sleep(1) if self.main_control.save_dialog: self.main_control.save_dialog.response(Gtk.ResponseType.CANCEL) self.refresh_gui() t1.join() def test_save_as(self): t1 = threading.Thread(target=self.main_control.save_as, args=()) t1.start() sleep(1) if self.main_control.save_dialog: self.main_control.save_dialog.response(Gtk.ResponseType.CANCEL) self.refresh_gui() t1.join() def test_exit(self): self.main_control.exit() self.main_window = self.create_main_window() self.main_control = MainControl(self.main_window) self.main_control.init() self.main_control.new() diagram = self.main_window.work_area.get_current_diagram() diagram.set_modified(True) t1 = threading.Thread(target=self.main_control.exit, args=()) t1.start() sleep(1) if self.main_window.work_area.confirm: self.main_window.work_area.confirm.response( Gtk.ResponseType.CANCEL) self.refresh_gui() t1.join() def test_add_recent_files(self): self.main_control.add_recent_files("Test") self.main_control.add_recent_files("Test") for i in range(0, 20): System.get_preferences().recent_files.append("Some File") self.main_control.add_recent_files("Test") def test_clipboard(self): self.main_control.get_clipboard() self.main_control.reset_clipboard() def test_preferences(self): t1 = threading.Thread(target=self.main_control.preferences, args=()) t1.start() sleep(1) if self.main_control.preference_window: self.main_control.preference_window.close() self.refresh_gui() t1.join() def test_save_source(self): self.main_control.save_source() self.diagram.set_modified(False) self.main_window.work_area.close_tabs() t1 = threading.Thread(target=self.main_control.save_source, args=()) t1.start() sleep(1) if self.main_control.message_dialog: self.main_control.message_dialog.close() t1.join() def test_view_source(self): t1 = threading.Thread(target=self.main_control.view_source, args=()) t1.start() sleep(2) if self.main_control.code_window: self.main_control.code_window.close() self.refresh_gui() t1.join() self.diagram.set_modified(False) self.main_window.work_area.close_tabs() t1 = threading.Thread(target=self.main_control.view_source, args=()) t1.start() sleep(1) if self.main_control.message_dialog: self.main_control.message_dialog.response(Gtk.ResponseType.CANCEL) self.refresh_gui() t1.join() def test_run_stop(self): self.main_control.run() sleep(1) self.diagram.set_modified(False) self.main_window.work_area.close_tabs() self.main_control.run() self.main_control.stop(None, None) self.main_control.update_blocks() self.main_control.close() self.main_control.new() def test_publish(self): self.main_control.publish() # Twice to start / stop self.main_control.publish() def test_about(self): t1 = threading.Thread(target=self.main_control.about, args=()) t1.start() sleep(1) if self.main_control.about_window: self.main_control.about_window.close() self.refresh_gui() t1.join() def test_search_clear(self): self.main_control.search("Test") self.main_control.set_block(self.create_block()) self.main_control.get_selected_block() self.main_control.clear_console() self.main_control.show_grid(None) self.main_window.menu.show_grid.emit("activate") def test_add_block(self): self.main_control.add_block(self.create_block()) self.diagram.set_modified(False) self.main_window.work_area.close_tabs() t1 = threading.Thread(target=self.main_control.add_block, args=(self.create_block(), )) t1.start() sleep(1) if self.main_control.message_dialog: self.main_control.message_dialog.response(Gtk.ResponseType.CANCEL) self.refresh_gui() t1.join() def test_edit(self): self.main_control.add_comment() self.main_control.select_all() self.main_control.cut() self.main_control.copy() self.main_control.paste() self.main_control.delete() self.diagram.set_modified(False) self.main_window.work_area.close_tabs() self.main_control.add_comment() self.main_control.select_all() self.main_control.cut() self.main_control.copy() self.main_control.paste() self.main_control.delete() def test_properties(self): self.main_control.zoom_in() self.main_control.zoom_out() self.main_control.zoom_normal() self.main_control.align_bottom() self.main_control.align_top() self.main_control.align_left() self.main_control.align_right() self.main_control.collapse_all() self.main_control.uncollapse_all() self.diagram.set_modified(False) self.main_window.work_area.close_tabs() self.main_control.zoom_in() self.main_control.zoom_out() self.main_control.zoom_normal() self.main_control.align_bottom() self.main_control.align_top() self.main_control.align_left() self.main_control.align_right() self.main_control.collapse_all() self.main_control.uncollapse_all() def test_undo_redo(self): self.main_control.undo() self.main_control.redo() self.diagram.set_modified(False) self.main_window.work_area.close_tabs() self.main_control.undo() self.main_control.redo() def test_redraw_update(self): self.main_control.redraw(True) self.main_control.redraw(False) self.main_control.update_all() def test_add_delete_code_template(self): self.main_control.add_code_template(self.create_code_template()) t1 = threading.Thread(target=self.main_control.delete_code_template, args=(self.create_code_template(), )) t1.start() sleep(1) if self.main_control.message_dialog: self.main_control.message_dialog.response(Gtk.ResponseType.CANCEL) self.refresh_gui() t1.join() code_template = self.create_code_template() System.add_code_template(code_template) t1 = threading.Thread(target=self.main_control.delete_code_template, args=(code_template, )) t1.start() sleep(1) if self.main_control.message_dialog: self.main_control.message_dialog.response(Gtk.ResponseType.CANCEL) self.refresh_gui() t1.join() def test_add__delete_port(self): self.main_control.add_port(self.create_port()) t1 = threading.Thread(target=self.main_control.delete_port, args=("port", )) t1.start() sleep(1) if self.main_control.message_dialog: self.main_control.message_dialog.response(Gtk.ResponseType.CANCEL) self.refresh_gui() t1.join() def test_add_delete_block(self): self.main_control.add_new_block(self.create_block()) t1 = threading.Thread(target=self.main_control.delete_block, args=(self.create_block(), )) t1.start() sleep(1) if self.main_control.message_dialog: self.main_control.message_dialog.response(Gtk.ResponseType.CANCEL) self.refresh_gui() t1.join()