コード例 #1
0
        self.assertEquals(resultPtr, mapper._Py_NotImplementedStruct, "wrong")
        self.assertEquals(mapper.RefCount(resultPtr), 2, "did not incref")
        self.assertEquals(mapper.Retrieve(resultPtr), NotImplemented,
                          "not mapped properly")


class PythonMapper_Py_OptimizeFlag_Test(TestCase):
    @WithMapper
    def testFills(self, mapper, addToCleanUp):
        # TODO: if we set a lower value, numpy will crash inside arr_add_docstring
        # I consider docstrings to be low-priority-enough that it's OK to fudge this
        # for now. also, fixing it would be hard ;).
        flagPtr = Marshal.AllocHGlobal(Marshal.SizeOf(Int32))
        addToCleanUp(lambda: Marshal.FreeHGlobal(flagPtr))
        mapper.RegisterData("Py_OptimizeFlag", flagPtr)

        self.assertEquals(CPyMarshal.ReadInt(flagPtr), 2)


suite = makesuite(
    PythonMapper_CreateDestroy_Test,
    PythonMapper_References_Test,
    PythonMapper_GetFuncPtr_NonApi_Test,
    PythonMapper_NoneTest,
    PythonMapper_NotImplementedTest,
    PythonMapper_Py_OptimizeFlag_Test,
)

if __name__ == '__main__':
    run(suite)
コード例 #2
0
ファイル: itertest.py プロジェクト: netcharm/ironclad
        self.assertEquals(mapper.PyIter_Next(notIterPtr), IntPtr.Zero, "bad return")
        self.assertMapperHasError(mapper, TypeError)


    @WithMapper
    def testPyIter_Next_ExplodingIterator(self, mapper, _):
        class BorkedException(Exception):
            pass
        def GetNext():
            raise BorkedException("Release the hounds!")
        explodingIterator = (GetNext() for _ in range(3))
        
        iterPtr = mapper.Store(explodingIterator)
        self.assertEquals(mapper.PyIter_Next(iterPtr), IntPtr.Zero, "bad return")
        self.assertNotEquals(mapper.LastException, None, "failed to set exception")
        
        def Raise():
            raise mapper.LastException
        try:
            Raise()
        except BorkedException, e:
            self.assertEquals(str(e), "Release the hounds!", "unexpected message")
        else:
            self.fail("wrong exception")

suite = makesuite(
    IterationTest,
)
if __name__ == '__main__':
    run(suite)
コード例 #3
0
ファイル: runtests.py プロジェクト: fdanny/ironclad
import os
import unittest
from tests.utils.runtest import makesuite, run


def GetFailedImportTestSuite(name, e):
    class FailedImportTest(unittest.TestCase):
        def testFailedImport(self):
            raise Exception("could not import %s:\n%s" % (name, e))
    return makesuite(FailedImportTest)

suite = unittest.TestSuite()
for f in os.listdir("tests"):
    if f.endswith("test.py"):
        name = f[:-3]
        try:
            print "adding: tests.%s" % name
            m = __import__("tests.%s" % name)
            suite.addTest(getattr(m, name).suite)
        except Exception, e:
            suite.addTest(GetFailedImportTestSuite(name, e))

if __name__ == '__main__':
    run(suite, verbosity=2)