def testInterfaces2(self): test1 = self.__jp.Test1() self.assertEqual('I4', test1.testInterfaces2(self._i4impl)) self.assertEqual('I2', test1.testInterfaces2( JObject(self._i4impl, 'jpype.overloads.Test1$I2'))) self.assertEqual('I3', test1.testInterfaces2( JObject(self._i4impl, 'jpype.overloads.Test1$I3')))
def testInterfaces1(self): test1 = self.__jp.Test1() self.assertRaisesRegex( TypeError, 'Ambiguous overloads found', test1.testInterfaces1, self._i4impl) self.assertEqual('I2', test1.testInterfaces1( JObject(self._i4impl, 'jpype.overloads.Test1$I2'))) self.assertEqual('I3', test1.testInterfaces1( JObject(self._i4impl, 'jpype.overloads.Test1$I3')))
def testCallOverloads(self): # build the harness h = JPackage("jpype.objectwrapper").Test1() o = java.lang.Integer(1) assert h.Method1(JObject(o, java.lang.Number)) == 1 assert h.Method1(o) == 2 assert h.Method1(JObject(java.lang.Integer(1), java.lang.Object)) == 3 assert h.Method1(JString("")) == 4
def testCallOverloads(self): # build the harness h = JPackage("jpype.objectwrapper").Test1() o = java.lang.Integer(1) self.assertEqual(h.Method1(JObject(o, java.lang.Number)), 1) self.assertEqual(h.Method1(o), 2) self.assertEqual( h.Method1(JObject(java.lang.Integer(1), java.lang.Object)), 3) self.assertEqual(h.Method1(JString("")), 4)
def testForceOverloadResolution(self): test1 = self.__jp.Test1() self.assertEqual('A', test1.testMostSpecific( JObject(self._c, self._aclass))) self.assertEqual('B', test1.testMostSpecific( JObject(self._c, self._bclass))) # JObject wrapper forces exact matches #self.assertRaisesRegex(TypeError, 'No matching overloads found', test1.testMostSpecific, JObject(self._c, self._cclass)) self.assertEqual('A', test1.testMostSpecific( JObject(self._c, 'jpype.overloads.Test1$A'))) self.assertEqual('B', test1.testMostSpecific( JObject(self._c, 'jpype.overloads.Test1$B')))
def testDefaultTypeNameJavaClass(self): o = java.lang.String self.assertEqual(JObject(o).typeName, "java.lang.Class") # def testMakeSureWeCanLoadAllClasses(self): # def get_system_jars(): # for dirpath,_,files in os.walk(jpype.java.lang.System.getProperty("java.home")): # for file in files: # if file.endswith('.jar'): # yield (os.path.join(dirpath,file)) # for jar in get_system_jars(): # classes = [x.getName() for x in jpype.java.util.jar.JarFile(jar).entries() if x.getName().endswith('.class')] # classes = [x.replace('/','.')[:-6] for x in classes] # for clazz in classes: # try: # jpype.JClass(clazz) # except jpype.JavaException as exception: # if not 'not found' in exception.message(): # print(clazz) # print (exception.message()) # #print (exception.stacktrace()) # except: # print(sys.exc_info()[0]) # pass
def buildMenuBar(menuDef): mb = __JMenuBar() for i in menuDef: jm = buildMenu(i[0], i[1]) mb.add(JObject(jm, __JMenu)) return mb
def testDefaultTypeNameJavaClass(self): o = java.lang.String self.assertEqual(JObject(o).typeName, "java.lang.Class")
def testDefaultTypeNameBoolean(self): self.assertEqual(JObject(True).typeName, "java.lang.Boolean") self.assertEqual(JObject(False).typeName, "java.lang.Boolean")
def testDefaultTypeNameString(self): self.assertEqual(JObject("123").typeName, "java.lang.String")