Example #1
0
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()")
    )
Example #2
0
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()"
        )
    )
Example #3
0
def test_function_def():
    fun = FunctionDefinition("myFun", "", [], Includes(), "void", TypeInfo(),
                             Config()).make()
    assert_multi_line_equal(
        fun,
        lines(
            "cpdef my_fun():",
            "    cpp.myFun()"
        )
    )
Example #4
0
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()"
        )
    )
Example #5
0
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])")
    )
Example #6
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"
        )
    )
Example #7
0
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",
            ""
        )
    )
Example #8
0
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())