def test_load_save(self):
        port = Port()
        port.label = "test"
        port.hint = "test"

        result = PortPersistence.load_xml("/this file does not exist")
        self.assertEquals(result, None)

        result = PortPersistence.save_xml(port, "/etc/")
        self.assertEquals(result, False)

        result = PortPersistence.save_xml(port, "/impossible to create")
        self.assertEquals(result, False)

        result = PortPersistence.save_xml(port, "/tmp/")
        self.assertEquals(result, True)

        file_name = "/tmp/" + port.hint + ".xml"
        result = PortPersistence.load_xml(file_name)
        os.remove(file_name)

        port.type = ""
        result = PortPersistence.save_xml(port, "/tmp/")
        file_name = "/tmp/" + port.hint + ".xml"
        result = PortPersistence.load_xml(file_name)
        self.assertEquals(result, None)
        os.remove(file_name)

        code_template = self.create_code_template()
        CodeTemplatePersistence.save_xml(code_template, "/tmp/")
        file_name = "/tmp/" + code_template.name + ".xml"
        result = PortPersistence.load_xml(file_name)
        os.remove(file_name)
    def test_save_xml(self):

        # Second condition
        file_name = "/tmp/" + self.code_template.type + ".xml"
        result = CodeTemplatePersistence.save_xml(self.code_template,
                                                  file_name)
        #        self.assertEquals(result, False)

        # Second condition
        port = Port()
        port.label = "test"
        PortPersistence.save_xml(port, "/tmp/")
        file_name = "/tmp/" + port.type + ".xml"
        result = CodeTemplatePersistence.load_xml(file_name)
        #        self.assertNotEquals(result, True)
        #        os.remove(file_name)

        CodeTemplatePersistence.save_xml(self.code_template, "/tmp/")
        file_name = "/tmp/" + self.code_template.type + ".xml"
        result = CodeTemplatePersistence.load_xml(file_name)
        self.assertEquals(result, None)
        #        os.remove(file_name)

        self.code_template.name = "Test"
        CodeTemplatePersistence.save_xml(self.code_template, "/tmp/")
        file_name = "/tmp/" + self.code_template.type + ".xml"
        result = CodeTemplatePersistence.load_xml(file_name)
Пример #3
0
    def test_load(self):
        # First condition
        result = CodeTemplatePersistence.load_xml("This file does not exist")
        self.assertEquals(result, None)

        # Second condition
        port = Port()
        port.label = "test"
        PortPersistence.save_xml(port, "/tmp/")
        file_name = "/tmp/" + port.type + ".xml"
        result = CodeTemplatePersistence.load_xml(file_name)
        self.assertNotEquals(result, True)
        os.remove(file_name)

        CodeTemplatePersistence.save_xml(self.code_template, "/tmp/")
        file_name = "/tmp/" + self.code_template.type + ".xml"
        result = CodeTemplatePersistence.load_xml(file_name)
        self.assertEquals(result, None)
        os.remove(file_name)

        self.code_template.name = "Test"
        CodeTemplatePersistence.save_xml(self.code_template, "/tmp/")
        file_name = "/tmp/" + self.code_template.type + ".xml"
        result = CodeTemplatePersistence.load_xml(file_name)
        self.assertEquals(result.equals(self.code_template), True)
        os.remove(file_name)
Пример #4
0
    def load(cls, file_name):
        """
        This method loads the port from XML file.

        Returns:

            * **Types** (:class:`boolean<boolean>`)
        """
        # load the port
        if os.path.exists(file_name) is False:
            return
        parser = XMLParser(file_name)
        if parser.getTag(tag_name) is None:
            return None

        port = Port()
        port.type = parser.getTagAttr(tag_name, "type")
        port.language = parser.getTagAttr(tag_name, "language")
        port.label = parser.getTagAttr(tag_name, "label")
        port.color = parser.getTagAttr(tag_name, "color")
        port.multiple = parser.getTagAttr(tag_name, "multiple")
        port.source = parser.getTagAttr(tag_name, "source")
        port.code = parser.getTag(tag_name).getTag("code").getText()

        count = 0
        for code in port.input_codes:
            port.input_codes[count] = parser.getTag(tag_name).getTag('input_code' + str(count)).getText()
            port.output_codes[count] = parser.getTag(tag_name).getTag('output_code' + str(count)).getText()
            count = count + 1

        if port.type == "":
            return None
        return port
Пример #5
0
    def create_block(self, diagram_control=None):
        if diagram_control is None:
            diagram_control = self.create_diagram_control()

        block_model = BlockModel()

        port0 = Port()
        port0.label = "Test0"
        port0.conn_type = Port.OUTPUT
        port0.name = "Test0"
        port0.type = "Test"

        port1 = Port()
        port1.label = "Test1"
        port1.conn_type = Port.INPUT
        port1.name = "Test1"
        port1.type = "Test"

        block_model.ports = [port0, port1]

        block_model.help = "Test"
        block_model.label = "Test"
        block_model.color = "200:200:25:150"
        block_model.group = "Test"
        block_model.codes = {"code0":"Test",
                       "Code1":"Test",
                       "Code2":"Test"}
        block_model.type = "Test"
        block_model.maxIO = 2
        block_model.language = "language"
        block_model.properties = [{"name": "test",
                             "label": "Test",
                             "type": MOSAICODE_FLOAT
                             }]

        block_model.extension = "Test"
        block_model.file = None

        block = Block(diagram_control.diagram, block_model)


        return block
    def test_load_save(self):
        port = Port()
        port.label = "test"

        PortPersistence.save_python(port, "/tmp/")
        file_name = "/tmp/" + port.label.lower().replace(' ', '_') + ".py"
        os.remove(file_name)

        PortPersistence.save_xml(port, "/tmp/")
        file_name = "/tmp/" + port.type + ".xml"

        result = PortPersistence.load_xml(file_name)
Пример #7
0
    def __save(self):
        port = Port()
        port.type = self.type.get_value()
        port.language = self.language.get_value()
        port.label = self.label.get_value()
        port.color = self.color.get_value()
        port.multiple = self.multiple.get_value()
        port.code = self.code.get_value()

        count = 0
        for code_widget in self.input_code_widgets:
            port.input_codes[count] = self.input_code_widgets[count].get_value(
            )
            port.output_codes[count] = self.output_code_widgets[
                count].get_value()
            count = count + 1

        self.port_manager.add_port(port)