def scaffold_starting_snipet( self, language: LanguageEnum) -> FunctionScaffoldingDto: func = Function(id=None, name="myFunc", return_type=ArgumentType.STRING, arguments=[], testing_input=None) return self.scaffold_function(func, language, ScaffoldingType.FULL_TEMPLATE)
def test_no_arg_function(self): function_ = Function("test_param_conversion", ArgumentType.STRING) snippet = CodeSnippet(LanguageEnum.PYTHON, [ 'param = FunctionArgument(ArgumentType.STRING, "param1")', 'self.assertEquals(self.runner.translate_parameter(param), "param1")' ], function_) res = self.runner.translate_code(function_, snippet) expected = """def test_param_conversion(): param = FunctionArgument(ArgumentType.STRING, "param1") self.assertEquals(self.runner.translate_parameter(param), "param1")""" self.assertEquals(res, expected)
def test_indented_code(self): function_ = Function("test_param_conversion", ArgumentType.STRING) snippet = CodeSnippet(LanguageEnum.PYTHON, [ 'if a is b:', ' self.assertEquals(self.runner.translate_parameter(param), "param1")' ], function_) res = self.runner.translate_code(function_, snippet) print res expected = """def test_param_conversion(): if a is b: self.assertEquals(self.runner.translate_parameter(param), "param1")""" print expected self.assertEquals(res, expected)
def test_two_arg_function(self): param1 = FunctionArgument(ArgumentType.VOID, "self") param2 = FunctionArgument(ArgumentType.VOID, "param2") function_ = Function("test_param_conversion", ArgumentType.STRING, [param1, param2]) snippet = CodeSnippet(LanguageEnum.PYTHON, [ 'param = FunctionArgument(ArgumentType.STRING, "param1")', 'self.assertEquals(self.runner.translate_parameter(param), "param1")' ], function_) res = self.runner.translate_code(function_, snippet) print res expected = """def test_param_conversion(self, param2): param = FunctionArgument(ArgumentType.STRING, "param1") self.assertEquals(self.runner.translate_parameter(param), "param1")""" self.assertEquals(res, expected)
def clone_code_snippet(code_snippet: CodeSnippet) -> CodeSnippet: if isinstance(code_snippet.function.testing_input, DeclarativeFunctionInput): testing_input_clone = DeclarativeFunctionInput( items=code_snippet.function.testing_input.items) else: raise BusinessException("Only DeclarativeFunctionInput is supported") func_clone = Function(id=None, name=code_snippet.function.name, return_type=code_snippet.function.return_type, arguments=[ FunctionArgument(type=x.type, name=x.name) for x in code_snippet.function.arguments ], testing_input=testing_input_clone) snippet_clone = CodeSnippet(language=code_snippet.language, code=code_snippet.code, function=func_clone) return snippet_clone
def to_entity(self): res = Function( self.id, self.name, self.return_type, [x.to_entity() for x in self.arguments], self.testing_input.to_entity() if self.testing_input else None) return res