class TestPythonParser(TestCase): def setUp(self): """Do the test basic setup.""" file_name = "Teste" self.python_parser = PythonParser(file_name) file_name = None self.python_parser = PythonParser(file_name) # ---------------------------------------------------------------------- def test_setAttribute(self): self.assertIsNone( self.python_parser.setAttribute(self.python_parser.class_name, 10)) # ---------------------------------------------------------------------- def test_getAttributeValue(self): self.assertIsNone( self.python_parser.getAttributeValue( self.python_parser.class_name)) teste = None self.assertIsNone(self.python_parser.getAttributeValue(teste)) # ---------------------------------------------------------------------- def test_getDependencies(self): self.assertIsNotNone(self.python_parser.getDependencies()) # ---------------------------------------------------------------------- def test_getInheritedClasses(self): self.assertIsNotNone(self.python_parser.getInheritedClasses()) # ---------------------------------------------------------------------- def test_clear_string(self): string = '\n' self.assertIsNotNone(self.python_parser.clear_string(string)) string = ' ' self.assertIsNotNone(self.python_parser.clear_string(string)) string = "TESTE_TESTES TESTE" self.assertIsNotNone(self.python_parser.clear_string(string)) # ---------------------------------------------------------------------- def test_save(self): file_name = "Testando.txt" self.python_parser.class_name = "Testando_save" self.assertIsNone(self.python_parser.save(file_name))
def save_python(cls, block, path): """ This method save the port in user space in python extension. Returns: * **Types** (:class:`boolean<boolean>`) """ parser = PythonParser() parser.class_name = block.label.replace(' ', '') parser.dependencies = [{'from':'mosaicode.model.blockmodel', 'import':'BlockModel'}] parser.inherited_classes = ['BlockModel'] parser.setAttribute('id', block.id) parser.setAttribute('type', block.type) parser.setAttribute('language', block.language) parser.setAttribute('framework', 'python') parser.setAttribute('help', block.help) parser.setAttribute('label', block.label) parser.setAttribute('color', block.color) parser.setAttribute('group', block.group) parser.setAttribute('help', block.help) parser.setAttribute('ports', block.ports) parser.setAttribute('properties', block.properties) parser.setAttribute('codes', block.codes) if not Persistence.create_dir(path): return False try: file_name = path + block.label.lower().replace(' ', '_') + ".py" parser.save(file_name) except IOError as e: return False return True
def save_python(cls, code_template, path): """ This method save the codetemplate in user space in python extension. Returns: * **Types** (:class:`boolean<boolean>`) """ parser = PythonParser() parser.class_name = code_template.name.replace(' ', '') parser.dependencies = [{ 'from': 'mosaicode.model.codetemplate', 'import': 'CodeTemplate' }] parser.inherited_classes = ['CodeTemplate'] parser.setAttribute('name', code_template.name) parser.setAttribute('description', code_template.description) parser.setAttribute('language', code_template.language) parser.setAttribute('command', code_template.command) # parser.setAttribute('extension', code_template.extension) # parser.setAttribute('code', code_template.code) parser.setAttribute('code_parts', code_template.code_parts) if not Persistence.create_dir(path): return False file_name = path + code_template.name.lower().replace(' ', '_') + ".py" try: parser.save(file_name) except IOError as e: return False return True
def save_python(cls, code_template): """ This method save the codetemplate in user space in python extension. Returns: * **Types** (:class:`boolean<boolean>`) """ from mosaicode.system import System parser = PythonParser() parser.class_name = code_template.name.replace(' ', '') parser.dependencies = [{ 'from': 'mosaicode.model.codetemplate', 'import': 'CodeTemplate' }] parser.inherited_classes = ['CodeTemplate'] parser.setAttribute('type', code_template.type) parser.setAttribute('name', code_template.name) parser.setAttribute('description', code_template.description) parser.setAttribute('language', code_template.language) parser.setAttribute('command', code_template.command) parser.setAttribute('extension', code_template.extension) parser.setAttribute('code', code_template.code) parser.setAttribute('source', 'python') try: data_dir = System.get_user_dir() + "/extensions/" data_dir = data_dir + code_template.language + "/" if not os.path.isdir(data_dir): try: os.makedirs(data_dir) except: pass file_name = data_dir + code_template.name.lower().replace( ' ', '_') + ".py" parser.save(file_name) except IOError as e: return False return True
def save_python(cls, plugin): """ This method save the port in user space in python extension. Returns: * **Types** (:class:`boolean<boolean>`) """ from mosaicode.system import System parser = PythonParser() parser.class_name = plugin.label.replace(' ', '') parser.dependencies = [{'from':'mosaicode.model.plugin', 'import':'Plugin'}] parser.inherited_classes = ['Plugin'] parser.setAttribute('id', plugin.id) parser.setAttribute('type', plugin.type) parser.setAttribute('language', plugin.language) parser.setAttribute('framework', 'python') parser.setAttribute('source', plugin.source) parser.setAttribute('help', plugin.help) parser.setAttribute('label', plugin.label) parser.setAttribute('color', plugin.color) parser.setAttribute('group', plugin.group) parser.setAttribute('help', plugin.help) parser.setAttribute('in_ports', plugin.in_ports) parser.setAttribute('out_ports', plugin.out_ports) parser.setAttribute('properties', plugin.properties) parser.setAttribute('codes', plugin.codes) try: data_dir = System.get_user_dir() + "/extensions/" data_dir = data_dir + plugin.language + "/" + plugin.framework + "/" if not os.path.isdir(data_dir): try: os.makedirs(data_dir) except: pass file_name = data_dir + plugin.label.lower().replace(' ', '_') + ".py" parser.save(file_name) except IOError as e: return False return True
def save_python(cls, port): """ This method save the port in user space in python extension. Returns: * **Types** (:class:`boolean<boolean>`) """ from mosaicode.system import System parser = PythonParser() parser.class_name = port.label.replace(' ', '') parser.dependencies = [{'from':'mosaicode.model.port', 'import':'Port'}] parser.inherited_classes = ['Port'] parser.setAttribute('type', port.type) parser.setAttribute('language', port.language) parser.setAttribute('label', port.label) parser.setAttribute('color', port.color) parser.setAttribute('multiple', port.multiple) parser.setAttribute('code', str(port.code)) try: data_dir = System.get_user_dir() + "/extensions/" data_dir = data_dir + port.language + "/ports/" if not os.path.isdir(data_dir): try: os.makedirs(data_dir) except: pass file_name = data_dir + port.label.lower().replace(' ', '_') + ".py" parser.save(file_name) except IOError as e: return False return True
def save_python(cls, port, path): """ This method save the port in user space in python extension. Returns: * **Types** (:class:`boolean<boolean>`) """ parser = PythonParser() parser.class_name = port.label.replace(' ', '') parser.dependencies = [{ 'from': 'mosaicode.model.port', 'import': 'Port' }] parser.inherited_classes = ['Port'] parser.setAttribute('type', port.type) parser.setAttribute('language', port.language) parser.setAttribute('label', port.label) parser.setAttribute('color', port.color) parser.setAttribute('multiple', port.multiple) parser.setAttribute('code', str(port.code)) if not Persistence.create_dir(path): return False try: file_name = path + port.label.lower().replace(' ', '_') + ".py" parser.save(file_name) except IOError as e: return False return True
def setUp(self): """Do the test basic setup.""" file_name = "Teste" self.python_parser = PythonParser(file_name) file_name = None self.python_parser = PythonParser(file_name)