예제 #1
0
 def test_compile_netmodule(self):
     def foo(x):
         return x+1
     dll = DllDef('mymodule', 'Test', [(foo, [int])], isnetmodule=True)
     dll.compile()
     res = self._csharp('Console.WriteLine("{0}", Test.foo(41));',
                        netmodules = ['mymodule'])
예제 #2
0
 def test_simple_functions(self):
     def foo(x):
         return x+1
     def bar(x):
         return x*2
     dll = DllDef('test', 'Test', [(foo, [int]),
                                   (bar, [int])])
     dll.compile()
     res = self._csharp('Console.WriteLine("{0}, {1}", Test.foo(42), Test.bar(42));', ['test'])
     assert res == (43, 84)
예제 #3
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
예제 #4
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
예제 #5
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