Example #1
0
 def test_collect_entrypoints(self):
     @export(int, float)
     def foo(x, y):
         pass
     def bar(x, y):
         pass
     mydict = dict(foo=foo, bar=bar, x=42)
     entrypoints = collect_entrypoints(mydict)
     assert entrypoints == [(foo, (int, float))]
Example #2
0
    def test_export_cliclass(self):
        from pypy.translator.cli.dotnet import CLR
        
        @export(CLR.System.Collections.ArrayList, int)
        def getitem(obj, i):
            return obj.get_Item(i)

        entrypoints = collect_entrypoints({'getitem': getitem})
        dll = DllDef('test', 'Test', entrypoints)
        dll.compile()
        res = self._csharp("""
            ArrayList obj = new ArrayList();
            obj.Add(42);
            Console.WriteLine(Test.getitem(obj, 0));
        """, ['test'])
        assert res == 42
Example #3
0
    def test_compile_class(self):
        class MyClass:
            @export(int)
            def __init__(self, x):
                self.x = x
            @export(int, int)
            def add(self, y, z):
                return self.x + y + z
        MyClass.__module__ = 'Test' # put the class in the Test namespace

        entrypoints = collect_entrypoints({'MyClass': MyClass})
        dll = DllDef('test', 'Test', entrypoints)
        dll.compile()
        res = self._csharp('test', """
            Test.MyClass obj = new Test.MyClass();
            obj.__init__(39);
            Console.WriteLine(obj.add(1, 2));
        """)
        assert res == 42
Example #4
0
    def test_compile_class(self):
        py.test.skip('This test fails every other day. No clue why :-(')
        class MyClass:
            @export(int)
            def __init__(self, x):
                self.x = x
            @export(int, int)
            def add(self, y, z):
                return self.x + y + z
        MyClass.__module__ = 'Test' # put the class in the Test namespace

        entrypoints = collect_entrypoints({'MyClass': MyClass})
        dll = DllDef('test', 'Test', entrypoints)
        dll.compile()
        res = self._csharp("""
            Test.MyClass obj = new Test.MyClass();
            obj.__init__(39);
            Console.WriteLine(obj.add(1, 2));
        """, ['test'])
        assert res == 42