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))
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")
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)
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)
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)
def save(self): """ This method save a file. Returns: * **Types** (:class:`boolean<boolean>`) """ return DiagramPersistence.save(self.diagram)
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)
def save(self, file_name=None): """ This method save a file. Returns: * **Types** (:class:`boolean<boolean>`) """ if file_name is not None: self.diagram.file_name = file_name if self.diagram.file_name is None: self.diagram.file_name = "Cadeia_" + str(time.time()) + ".mscd" if self.diagram.file_name.find(".mscd") == -1: self.diagram.file_name = self.diagram.file_name + ".mscd" return DiagramPersistence.save(self.diagram)
def save(self, file_name=None): """ This method save a file. Returns: * **Types** (:class:`boolean<boolean>`) """ if file_name is not None: self.diagram.file_name = file_name if self.diagram.file_name is None: self.diagram.file_name = "Diagram_" + \ datetime.now().strftime("%m-%d-%Y-%H:%M:%S") + ".mscd" if self.diagram.file_name.find(".mscd") == -1: self.diagram.file_name = self.diagram.file_name + ".mscd" return DiagramPersistence.save(self.diagram)
def test_save_exception(self): diagram = self.create_full_diagram() diagram.file_name = "/etc/Diagram.msc" result = DiagramPersistence.save(diagram) self.assertEquals(result, (False, 'Permission denied'))