def makeBlob(value): f = open("test273p/com/Blob.java", "w") f.write(src % value); f.close(); support.compileJava(r"test273p/com/Blob.java") support.compileJava(r"test273p/com/BlobWriter.java", classpath="test273p")
def mkjar(): jarfile = File(jardir, jarfn) # create a .jar file containing a .class file if not jarfile.exists(): support.compileJava("%s/%s/%s.java" % (jardir, package, clazz)) jarPacker = support.JarPacker(jarfile, bufsize=128) jarPacker.addFile(clazzfile, parentDirName=package) jarPacker.close() return jardir + '/' + jarfn, package, clazz
def mkspam(a): f = open("test081j.java", "w") f.write(""" public class test081j { public static String spam() { return "%s"; } public static void %s() {} } """ % (a, a)) f.close() support.compileJava("test081j.java")
def mkjavaclass(): mkdir(PACKAGE) f = open("%s/%s.java" % (PACKAGE, GOOD_CLAZZ), "w") f.write(""" package %s; public class %s { } """ % (PACKAGE, GOOD_CLAZZ)) f.close() support.compileJava("%s/%s.java" % (PACKAGE, GOOD_CLAZZ))
import support support.compileJava("test247j.java") import java try: import test247j except java.lang.ExceptionInInitializerError: pass else: raise support.TestWarning, "Should raise an ExceptionInInitializerError" #print dir(test247j) #t = test247j()
""" """ import support import java, jarray support.compileJava("test129j.java") arr = jarray.zeros(10, java.lang.Class.forName('[I')) for x in range(10): arr[x] = jarray.zeros(10, 'i') import test129j test129j.chk(arr) if arr[0][0] != 47: raise support.TestError("Array[0][0] should be 47: %d" % arr[0][0])
""" [ #416871 ] proxy fails to have all needed methods """ import support support.compileJava('test294j.java') import test294j class PyTestA(test294j): def __init__(self): output.append( "inited") def doStart(self): output.append( "started") def doEnd(self): output.append( "completed") def finalize(self): pass def clone(self): return self.__class__() class PyTestB(test294j): def __init__(self): output.append( "inited") def doStart(self): output.append( "started") def doEnd(self): output.append( "completed")
""" """ import support support.compileJava("test157j.java") import test157j from jarray import * f = zeros(2, 'd') support.compare(test157j.test(f), "double") if f[0] == 0: raise support.TestError("array not changed") f = zeros(2, 'f') support.compare(test157j.test(f), "float") if f[0] == 0: raise support.TestError("array not changed")
""" """ import support support.compileJava("classes/test205j2.java") import test205j1 support.compare(test205j1.classID, "2051") import test205j2 support.compare(test205j2.classID, "2052") support.compare(test205j1.classID, "2051") support.compare(test205j1().classID, "20510") support.compare(test205j2().classID, "20520") support.compare(test205j1().classID, "20510")
""" """ import support support.compileJava("classes/test206j1.java") import java #import test206j0 import test206j1 x = test206j1() support.compare(x.getInt2(), "4") support.compare(x.getInt(), "3")
import support support.compileJava("test284j2.java", classpath=".") import test284j1 assert test284j1().foo() == 'test284j1.foo' import test284j2 assert test284j2().foo() == 'test284j2.foo'
""" [ 610576 ] Impl of abstract method not found """ import support support.compileJava("test366i.java") support.compileJava("test366j.java") import test366i, test366j class MyCls(test366j, test366i): def __init__(self): self.foo() MyCls()
import support support.compileJava("test270p/test270j2.java", classpath=".") from test270p import * test270j2.printX(test270j1()) from java import net, lang clu = net.URL(r'file:%s/' % lang.System.getProperty("user.dir")) ld1 = net.URLClassLoader([clu]) X = ld1.loadClass("test270p.test270j1") Y = ld1.loadClass("test270p.test270j2") Y.printX(X()) #import org #org.python.core.PyJavaClass.dumpDebug()
""" """ import support support.compileJava("classes/test182j.java") support.compileJPythonc("test182c.py", core=1, jar="test182c.jar", output="test182.err") support.runJava("test182c", classpath="test182c.jar") #raise support.TestError("" + `x`)
""" [ #480390 ] main() does not throw exceptions """ import support support.compileJPythonc("test340c.py", core=1, jar="test340.jar", output="test340.err") support.compileJava("test340j.java") rc = support.runJava("test340j", classpath=".", expectError=1) if rc != 42: support.TestError("Did not catch exception correctly %d" % rc)
import support support.compileJava("test241p/test241i.java") import test241p class A(test241p.test241i): def foo(self, i): return i a = A() v = a.foo(44) if v != 44: raise support.TestError, "Wrong return value %d" % v
""" Bug #222847 - Can't access public member of package private base class """ import support support.compileJava("classes/test232p/Foo.java") from test232p import Foo try: Foo().hi() except IllegalAccessException: raise support.TestError( 'Should be able to call public method on package protected superclass')
""" Test class identity for inner classes [ #452947 ] Class of innerclass inst <> innerclas """ import support support.compileJava('test319j.java') import test319j id1 = id(test319j.inner) id2 = id(test319j.mkinner().__class__) if id1 != id2: print "innerclass different", test319j.inner, test319j.mkinner().__class__ raise support.TestWarning("innerclass different %s %s" % (test319j.inner, test319j.mkinner().__class__))
""" [ #480017 ] Proxy supers are loaded from syspath Running test338j will throw a ClassCastException if a proxy's superclass is loaded by the syspath classloader. """ import support support.compileJava("test338cl.java", classpath=".") support.compileJava("test338j1.java", classpath=".") support.compileJava("test338j.java", classpath=".") support.runJava("test338j", classpath=".")
""" Coercion of Integer and Number. """ import support support.compileJava("test091j.java") import test091j r = test091j.takeInt(12) support.compare(r, "takeInt") r = test091j.takeInteger(12) support.compare(r, "takeInteger") r = test091j.takeNumber(12) support.compare(r, "takeNumber")
""" Check nonpublic constructor. """ import support support.compileJava("classes/test121p/test121j.java") from test121p import test121j try: test121j() except TypeError, e: support.compare(e, "no public constructor") else: raise support.TestError("Should fail (access)")
import support, os support.compileJava("classes/test236j1.java", force=1) os.remove("classes/test236j2.class") onimport = 1 import java try: import test236j1 onimport = 0 test236j1() except ImportError: raise support.TestError, "Should not raise a simple ImportError" except java.lang.NoClassDefFoundError: if not onimport: raise support.TestWarning, "import itself does not imply class initialization" else: raise support.TestError, "Should raise some exception"
""" [ 610576 ] Impl of abstract method not found """ import support support.compileJava("test366i.java"); support.compileJava("test366j.java"); import test366i, test366j class MyCls(test366j, test366i): def __init__(self): self.foo(); MyCls()
""" """ import support support.compileJava("classes/test204j2.java") support.compileJava("classes/test204j3.java") import test204j1 support.compare(test204j1.classID, "2041") import test204j2 support.compare(test204j2.classID, "2042") import test204j3 support.compare(test204j3.classID, "2043") support.compare(test204j1.classID, "2041")
""" """ import support support.compileJava("classes/test139j2.java") support.compileJava("classes/test139j3.java") import test139j1, test139j2 class myclass(test139j1, test139j2): def fooMethod(self): pass import test139j3 if not test139j3.baz(myclass()): raise support.TestError("myclass should implement test139j2")
""" [ #451552 ] case insensitivity on import causes prob """ import support import java support.compileJava("classes/test336p/Data.java") support.compileJava("classes/test336p/data/MyData.java") from test336p.data import MyData
import support support.compileJava("test244p/A.java") import test244p.A a=test244p.A()
''' Confirms the correct bevahior of Python int to Java byte coercion. Even though a Python int can be expressed in a byte like format such as 0xFF, Java bytes only range from -128 to 127 so any int greater than 0x80 should throw a TypeError if it's passed to something expecting a Java byte. ''' import support support.compileJava("classes/test399j.java") import test399j test399j.takesByteArray([0x7E, 0x12]) try: test399j.takesByteArray([0xFF, 0x00]) raise support.TestError('0xFF should not be acceptable as a Java byte') except TypeError: pass#expected since 0xFF can't be coerced to a Java byte
import support support.compileJava("test250j.java") import test250j t = test250j() v = t[3] if v != 6: raise support.TestError, "wrong return value %d" % v try: print t.a except AttributeError: # Do not support __getattr__ on java classes. (for now at least) pass
def mkj1(v): f = open("classes/test092m/test092j1.java", "w") f.write(j1file % v) f.close() support.compileJava("classes/test092m/test092j1.java")
""" [ 531256 ] Constructor problem using newInstance() """ import support support.compileJava("test364p/X.java") support.compileJava("test364p/Y.java") from test364p import X,Y class PyX(X): pass class PyY(Y): pass PyX.useClass(PyY) X() # OK try: PyX() # Not OK prints 'TypeError: Proxy instance reused' except TypeError: raise support.TestWarning('Class ctor should mix with newInstance()')
""" """ import support support.compileJava("test278p/bug.java", classpath=".") from test278p import bug b = bug() assert b.getName() == "name" assert b.name == "name" #raise support.TestError("" + `x`)
""" """ import support support.compileJava("test277p/Test.java") from test277p import Test cnt = 0 class pytest(Test): def initialize(self): global cnt Test.initialize(self) cnt += 1 pt = pytest() support.compare(cnt, "2") cnt = 0 import java pt = java.lang.Class.newInstance(pytest) support.compare(cnt, "2")
import support support.compileJava("classes/test219j.java") import test219i, test219e, test219j class test219(test219i): def foo(self): raise test219e("raised in foo()") def foo2(self, i): if i == 0: raise test219e("test219e raised in foo()") else: raise java.lang.Throwable("Throwable raised in foo()") a = test219() test219j.checkFoo(a) test219j.checkFoo2(a, 0) test219j.checkFoo2(a, 1)
""" Test proxy maker from sys.path. CLASSPATH must *not* include "." in this test. """ import support support.compileJava("test083j1.java") import test083j1 class A(test083j1): pass
def mkj2(v): f = open("classes/test092m/test092j2.java", "w") f.write(j2file % v); f.close(); support.compileJava("classes/test092m/test092j2.java")
""" Calling static methods in subclass. """ import support support.compileJava("classes/test084j3.java") import test084j3 r = test084j3.main(["xxx"]) support.compare(r, "test084j3") r = test084j3.ohMy() support.compare(r, "test084j3")
""" """ import support support.compileJava("classes/test288j.java") import test288j, test288i class t: def __init__(self, s): self.s = s def __getattr__(self, name): return getattr(self.s, name) class u(test288i): def __init__(self, s): self.s = s def get(self, i=None): if i: return self.s.get(i) else: return self.s.get() class v(test288i):
""" BigDecimal return coerced into integer """ import support support.compileJava("test066j.java") import java import test066j x = java.math.BigDecimal("123.4321") y = test066j.asBigDecimal() if type(x) != type(y): raise support.TestError("BigDecimal coerced") if x != y: raise support.TestError("BigDecimal coerced")
""" """ import support support.compileJava("classes/test160j1.java") import test160j1 a = test160j1() a.go() #raise support.TestError("" + `x`)
def mkJavaClass(): support.compileJava("%s/%s.java" % (TESTDIR, CLAZZ))
""" Bug #222847 - Can't access public member of package private base class """ import support support.compileJava("classes/test232p/Foo.java") from test232p import Foo try: Foo().hi() except IllegalAccessException: raise support.TestError("Should be able to call public method on package protected superclass")
""" """ import support support.compileJava("test157j.java") import test157j from jarray import * f = zeros(2,'d'); support.compare(test157j.test(f), "double"); if f[0] == 0: raise support.TestError("array not changed") f = zeros(2,'f'); support.compare(test157j.test(f), "float"); if f[0] == 0: raise support.TestError("array not changed")
import support support.compileJava("test172j.java") import test172j support.compare(test172j.foo(1,2,3,4), "foo called with 4 arguments") support.compare(test172j().bar(1,2,3,4), "bar called with 4 arguments")