def test_simple_function_def(): method = MethodDefinition( "Testclass", "", "testfun", [], Includes(), "void", TypeInfo({}), Config()).make() assert_multi_line_equal( method, lines("cpdef testfun(Testclass self):", " self.thisptr.testfun()") )
def test_function_def_with_another_cppname(): fun = FunctionDefinition("myFunInt", "", [], Includes(), "void", TypeInfo(), Config(), cppname="myFun").make() assert_multi_line_equal( fun, lines( "cpdef my_fun_int():", " cpp.myFun()" ) )
def test_function_def(): fun = FunctionDefinition("myFun", "", [], Includes(), "void", TypeInfo(), Config()).make() assert_multi_line_equal( fun, lines( "cpdef my_fun():", " cpp.myFun()" ) )
def test_default_ctor_def(): ctor = ConstructorDefinition("MyClass", "", [], Includes(), TypeInfo(), Config(), "MyClass").make() assert_multi_line_equal( ctor, lines( "def __init__(MyClass self):", " self.thisptr = new cpp.MyClass()" ) )
def test_array_arg_function_def(): method = MethodDefinition( "Testclass", "", "testfun", [Param("a", "double *"), Param("aSize", "unsigned int")], Includes(), "void", TypeInfo({}), Config()).make() assert_multi_line_equal( method, lines("cpdef testfun(Testclass self, np.ndarray[double, ndim=1] a):", " self.thisptr.testfun(&a[0], a.shape[0])") )
def test_setter_definition(): field = Field("myField", "double", "MyClass") setter = SetterDefinition( "MyClass", field, Includes(), TypeInfo(), Config()).make() assert_multi_line_equal( setter, lines( "cpdef __set_my_field(MyClass self, double myField):", " cdef double cpp_myField = myField", " self.thisptr.myField = cpp_myField" ) )
def test_getter_definition(): field = Field("myField", "double", "MyClass") getter = GetterDefinition( "MyClass", field, Includes(), TypeInfo(), Config()).make() assert_multi_line_equal( getter, lines( "cpdef __get_my_field(MyClass self):", " cdef double result = self.thisptr.myField", " return result", "" ) )
def test_underlying_type(): assert_equal(TypeInfo().underlying_type("tdef"), "tdef") assert_equal( TypeInfo(typedefs={ "tdef": "float" }).underlying_type("tdef"), "float")
def test_converter_not_available(): assert_raises(NotImplementedError, create_type_converter, "UnknownType", "unknownType", TypeInfo([]), Config())