File: JavaMakerSmokeTest.java

package info (click to toggle)
jython 2.7.1%2Brepack1-4~deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 63,416 kB
  • sloc: python: 639,274; java: 296,480; xml: 1,743; sh: 396; ansic: 126; makefile: 72
file content (69 lines) | stat: -rw-r--r-- 2,214 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package org.python.compiler;

/**
 * Some JavaMaker smoke tests 
 */

import java.lang.reflect.Array;
import java.util.Properties;

import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

import org.python.core.PySystemState;
import org.python.util.PythonInterpreter;


public class JavaMakerSmokeTest {
	
    public PythonInterpreter interp;
    public Class<?> proxyClass;
    
    @Before
    public void setUp() throws Exception {
        Properties props = new Properties(System.getProperties());
        props.setProperty(PySystemState.PYTHON_CACHEDIR_SKIP, "true");
        PySystemState.initialize(props, null);
        interp = new PythonInterpreter();
        
        String input = new String();
        input += "import java.io.ByteArrayInputStream\n";
        input += "import java.lang.String\n";
        input += "import org.python.core.Options\n";
        input += "org.python.core.Options.proxyDebugDirectory = 'build/classes'\n";
        input += "class ProxyTest(java.io.ByteArrayInputStream):\n";
        input += "    def somemethod(self): pass\n";
        input += "ProxyTest(java.lang.String('teststr').getBytes())\n";
        interp.exec(input);
        
        proxyClass = Class.forName("org.python.proxies.__main__$ProxyTest$0");
    }
    
    @Test
    public void constructors() throws Exception {
        proxyClass.getConstructor(Array.newInstance(Byte.TYPE, 0).getClass());
        proxyClass.getConstructor(Array.newInstance(Byte.TYPE, 0).getClass(), Integer.TYPE, Integer.TYPE);
    }
    
    @Test

    public void methods() throws Exception {
        proxyClass.getMethod("classDictInit", org.python.core.PyObject.class);
        proxyClass.getMethod("close");
    }
    
    @Test

    public void annotations() throws Exception {
        proxyClass.getAnnotation(org.python.compiler.APIVersion.class);
        proxyClass.getAnnotation(org.python.compiler.MTime.class);
    }
    
    @Test
    public void interfaces() throws Exception {
        Class<?>[] interfaces = new Class<?>[]{org.python.core.PyProxy.class,
                org.python.core.ClassDictInit.class};
        assertArrayEquals(interfaces, proxyClass.getInterfaces());
    }
}