Exemple #1
0
    def test_Py_InitModule4_VarargsKwargsFunction(self):
        mapper = PythonMapper()
        deallocTypes = CreateTypes(mapper)
        args = (object(), object())
        kwargs = {'a': object(), 'b': object()}
        result = object()
        resultPtr = mapper.Store(result)
        mapper.IncRef(resultPtr)

        def func(_, argsPtr, kwargsPtr):
            self.assertEquals(_, MODULE_PTR)
            self.assertEquals(mapper.Retrieve(argsPtr), args)
            self.assertEquals(mapper.Retrieve(kwargsPtr), kwargs)
            return resultPtr

        method, deallocMethod = MakeMethodDef("func", func,
                                              METH.VARARGS | METH.KEYWORDS)

        def testModule(module, mapper):
            self.assertEquals(module.func(*args, **kwargs), result,
                              "not hooked up")

        self.assert_Py_InitModule4_withSingleMethod(mapper, method, testModule)
        deallocMethod()
        deallocTypes()
Exemple #2
0
    def test_Py_InitModule4_CreatesPopulatedModule(self):
        mapper = PythonMapper()
        method, deallocMethod = MakeMethodDef(
            "harold", lambda _, __: IntPtr.Zero, METH.VARARGS, "harold's documentation")
        
        def testModule(test_module, _):
            self.assertEquals(test_module.__doc__, 'test_docstring',
                              'module docstring not remembered')
            self.assertTrue(callable(test_module.harold),
                            'function not remembered')
            self.assertTrue(callable(test_module._dispatcher.table['harold']),
                            'delegate not remembered')
            self.assertEquals(test_module.harold.__doc__, "harold's documentation",
                              'function docstring not remembered')

        self.assert_Py_InitModule4_withSingleMethod(mapper, method, testModule)
        deallocMethod()
Exemple #3
0
 def test_Py_InitModule4_NoArgsFunction(self):
     mapper = PythonMapper()
     deallocTypes = CreateTypes(mapper)
     result = object()
     resultPtr = mapper.Store(result)
     mapper.IncRef(resultPtr)
     
     def func(_, __):
         self.assertEquals((_, __), (MODULE_PTR, IntPtr.Zero))
         return resultPtr
     method, deallocMethod = MakeMethodDef("func", func, METH.NOARGS)
     
     def testModule(module, mapper):
         self.assertEquals(module.func(), result, "not hooked up")
         
     self.assert_Py_InitModule4_withSingleMethod(mapper, method, testModule)
     deallocMethod()
     deallocTypes()
Exemple #4
0
 def test_Py_InitModule4_OldargsFunction_OneArg(self):
     mapper = PythonMapper()
     deallocTypes = CreateTypes(mapper)
     arg = object()
     result = object()
     resultPtr = mapper.Store(result)
     mapper.IncRef(resultPtr)
     
     def func(_, argPtr):
         self.assertEquals(_, MODULE_PTR)
         self.assertEquals(mapper.Retrieve(argPtr), arg)
         return resultPtr
     method, deallocMethod = MakeMethodDef("func", func, METH.OLDARGS)
     
     def testModule(module, mapper):
         self.assertEquals(module.func(arg), result, "not hooked up")
         
     self.assert_Py_InitModule4_withSingleMethod(mapper, method, testModule)
     deallocMethod()
     deallocTypes()