diff --git a/jpype/__init__.py b/jpype/__init__.py index 9922a6635..aa7071ae9 100644 --- a/jpype/__init__.py +++ b/jpype/__init__.py @@ -20,6 +20,7 @@ from ._jpackage import * from ._jproxy import * from ._core import * +from . import _core from ._gui import * from ._classpath import * from ._jclass import * @@ -41,15 +42,15 @@ from . import _jthread # lgtm [py/import-own-module] __all__ = ['java', 'javax'] -__all__.extend(_jinit.__all__) +__all__.extend(_jinit.__all__) # type: ignore[name-defined] __all__.extend(_core.__all__) -__all__.extend(_classpath.__all__) -__all__.extend(types.__all__) -__all__.extend(_jproxy.__all__) -__all__.extend(_jpackage.__all__) -__all__.extend(_jclass.__all__) -__all__.extend(_jcustomizer.__all__) -__all__.extend(_gui.__all__) +__all__.extend(_classpath.__all__) # type: ignore[name-defined] +__all__.extend(types.__all__) # type: ignore[name-defined] +__all__.extend(_jproxy.__all__) # type: ignore[name-defined] +__all__.extend(_jpackage.__all__) # type: ignore[name-defined] +__all__.extend(_jclass.__all__) # type: ignore[name-defined] +__all__.extend(_jcustomizer.__all__) # type: ignore[name-defined] +__all__.extend(_gui.__all__) # type: ignore[name-defined] __version__ = "1.5.0_dev0" __version_info__ = __version__.split('.') diff --git a/jpype/_core.pyi b/jpype/_core.pyi deleted file mode 100644 index f4eb32c79..000000000 --- a/jpype/_core.pyi +++ /dev/null @@ -1,2 +0,0 @@ -class _JRuntime: - pass diff --git a/jpype/_gui.py b/jpype/_gui.py index ca5f96b39..245c1b5bd 100644 --- a/jpype/_gui.py +++ b/jpype/_gui.py @@ -28,7 +28,7 @@ def setupGuiEnvironment(cb): if _sys.platform == 'darwin': - from PyObjCTools import AppHelper + from PyObjCTools import AppHelper # type: ignore m = {'run': cb} proxy = _jproxy.JProxy('java.lang.Runnable', m) cbthread = _jclass.JClass("java.lang.Thread")(proxy) @@ -40,5 +40,5 @@ def setupGuiEnvironment(cb): def shutdownGuiEnvironment(): if _sys.platform == 'darwin': - from PyObjCTools import AppHelper + from PyObjCTools import AppHelper # type: ignore AppHelper.stopEventLoop() diff --git a/jpype/_jarray.py b/jpype/_jarray.py index 082aba204..34ce2bd86 100644 --- a/jpype/_jarray.py +++ b/jpype/_jarray.py @@ -22,7 +22,7 @@ __all__ = ['JArray'] -class JArray(_jpype._JObject, internal=True): +class JArray(_jpype._JObject, internal=True): # type: ignore[call-arg] """ Creates a Java array class for a Java type of a given dimension. This serves as a base type and factory for all Java array classes. diff --git a/jpype/_jclass.py b/jpype/_jclass.py index 9c33622d0..faa905f24 100644 --- a/jpype/_jclass.py +++ b/jpype/_jclass.py @@ -99,7 +99,7 @@ def __new__(cls, jc, loader=None, initialize=True): return _jpype._getClass(jc) -class JInterface(_jpype._JObject, internal=True): +class JInterface(_jpype._JObject, internal=True): # type: ignore[call-arg] """A meta class for all Java Interfaces. ``JInterface`` is serves as the base class for any Java class that is diff --git a/jpype/_jcollection.py b/jpype/_jcollection.py index 7f7270c3f..a31a6e53c 100644 --- a/jpype/_jcollection.py +++ b/jpype/_jcollection.py @@ -41,7 +41,7 @@ class _JCollection(object): """ Customizer for ``java.util.Collection`` This customizer adds the Python functions ``len()`` and ``del`` to - Java Collions to allow for Python syntax. + Java Collisions to allow for Python syntax. """ def __len__(self): diff --git a/jpype/_jcollection.pyi b/jpype/_jcollection.pyi index 7e811332f..07417b58b 100644 --- a/jpype/_jcollection.pyi +++ b/jpype/_jcollection.pyi @@ -1,4 +1,4 @@ -from typing import Iterable, Collection, List, Set, Mapping, Tuple, TypeVar, Iterator, Generator, Union, overload +from typing import Any, Iterable, Collection, List, Set, Mapping, Tuple, TypeVar, Iterator, Generator, Union, overload, Dict E = TypeVar('E') K = TypeVar('K') @@ -14,80 +14,34 @@ class _JCollection(Collection[E]): def __delitem__(self, i: E) -> None: ... - def __contains__(self, i: E) -> bool: ... + def __contains__(self, i: Any) -> bool: ... + def __iter__(self) -> Iterator[E]: ... -class _JList(List[E]): - @overload - def __getitem__(self, ndx: int) -> E: ... - - @overload - def __getitem__(self, ndx: slice) -> E: ... - - def __setitem__(self, ndx: int, v: E) -> None: ... - - def __delitem__(self, ndx: int) -> E: ... - - def __reversed__(self) -> Generator[E, None, None]: ... - - def index(self, obj: E) -> int: ... - - def count(self, obj: E) -> int: ... - - def insert(self, idx: int, obj: E) -> '_JList'[E]: ... - - def append(self, obj: E) -> '_JList'[E]: ... - - def reverse(self) -> None: ... - - def extend(self, lst: Iterable[E]) -> None: ... - - def pop(self, idx: int = ...) -> E: ... - - def __iadd__(self, obj: List[E]) -> '_JList'[E]: ... - - def __add__(self, obj: List[E]) -> '_JList'[E]: ... - def remove(self, obj: E) -> None: ... +class _JList(List[E]): + pass -class _JMap(Mapping[K, V]): +class _JMap(Dict[K, V]): def __len__(self) -> int: ... def __iter__(self) -> Iterator[K]: ... - def __delitem__(self, i: K) -> V: ... - def __getitem__(self, ndx: K) -> V: ... - def __setitem__(self, ndx: K, v: V) -> None: ... - - def items(self) -> Set['_JMapEntry'[K, V]]: ... - - def keys(self) -> Set[K]: ... - - def __contains__(self, item: V) -> bool: ... - class _JSet(Set[E]): - def __delitem__(self, i: E): ... + pass class _JMapEntry(Tuple[K, V]): - def __len__(self) -> int: ... - - def __getitem__(self, x: int) -> Union[K, V]: ... + pass class _JIterator(Iterator[E]): def __next__(self) -> E: ... - def __iter__(self) -> Iterator[E]: ... - class _JEnumeration(Iterator[E]): def __next__(self) -> E: ... - - def __iter__(self) -> Iterator[E]: ... - - def next(self) -> E: ... diff --git a/jpype/_jexception.py b/jpype/_jexception.py index 7f179446e..f6280c8b7 100644 --- a/jpype/_jexception.py +++ b/jpype/_jexception.py @@ -22,7 +22,7 @@ @_jcustomizer.JImplementationFor("java.lang.Throwable", base=True) -class JException(_jpype._JException, internal=True): +class JException(_jpype._JException, internal=True): # type: ignore[call-arg] """ Base class for all ``java.lang.Throwable`` objects. Use ``issubclass(cls, JException)`` to test if a class is derived diff --git a/jpype/_jmethod.py b/jpype/_jmethod.py index 35a71622b..366a2287f 100644 --- a/jpype/_jmethod.py +++ b/jpype/_jmethod.py @@ -15,11 +15,12 @@ # See NOTICE file for details. # # ***************************************************************************** -import _jpype -__all__ = [] + import _jpype from . import _jclass +__all__ = [] # type: ignore[var-annotated] + def _jmethodGetDoc(method, cls, overloads): """Generator for _JMethod.__doc__ property diff --git a/jpype/_jobject.py b/jpype/_jobject.py index 6917561de..e199300b4 100644 --- a/jpype/_jobject.py +++ b/jpype/_jobject.py @@ -20,7 +20,7 @@ __all__ = ['JObject'] -class JObject(_jpype._JObject, internal=True): +class JObject(_jpype._JObject, internal=True): # type: ignore[call-arg] """ Base class for all object instances. It can be used to test if an object is a Java object instance with diff --git a/jpype/_jstring.py b/jpype/_jstring.py index 0f8d8cfa2..2785576a3 100644 --- a/jpype/_jstring.py +++ b/jpype/_jstring.py @@ -15,13 +15,15 @@ # See NOTICE file for details. # # ***************************************************************************** +import typing + import _jpype from . import _jcustomizer __all__ = ['JString'] -class JString(_jpype._JObject, internal=True): +class JString(_jpype._JObject, internal=True): # type: ignore[call-arg] """ Base class for ``java.lang.String`` objects When called as a function, this class will produce a ``java.lang.String`` @@ -37,14 +39,14 @@ def __new__(cls, *args, **kwargs): @_jcustomizer.JImplementationFor("java.lang.String") -class _JStringProto(object): - def __add__(self, other): - return self.concat(other) +class _JStringProto: + def __add__(self, other: str) -> str: + return self.concat(other) # type: ignore[attr-defined] - def __len__(self): - return self.length() + def __len__(self) -> int: + return self.length() # type: ignore[attr-defined] - def __getitem__(self, i): + def __getitem__(self, i: typing.Union[slice, int]): if isinstance(i, slice): return str(self)[i] @@ -54,10 +56,10 @@ def __getitem__(self, i): raise IndexError("Array index is negative") if i >= len(self): raise IndexError("Array index exceeds length") - return self.charAt(i) + return self.charAt(i) # type: ignore[attr-defined] - def __contains__(self, other): - return self.contains(other) + def __contains__(self, other: str) -> bool: + return self.contains(other) # type: ignore[attr-defined] def __hash__(self): if self == None: # lgtm [py/test-equals-none] diff --git a/jpype/_jstring.pyi b/jpype/_jstring.pyi deleted file mode 100644 index bd2d5160a..000000000 --- a/jpype/_jstring.pyi +++ /dev/null @@ -1,13 +0,0 @@ -from typing import Any, Text - - -class _JStringProto(Text): - def __add__(self, other: Text) -> Text: ... - - def __len__(self) -> int: ... - - def __getitem__(self, i: int) -> Text: ... - - def __contains__(self, other: Text) -> bool: ... - - def __hash__(self) -> Any: ... diff --git a/jpype/_jthread.py b/jpype/_jthread.py index 4c329ffec..a52089589 100644 --- a/jpype/_jthread.py +++ b/jpype/_jthread.py @@ -20,7 +20,7 @@ @_jcustomizer.JImplementationFor('java.lang.Thread') -class _JThread(object): +class _JThread: """ Customizer for ``java.land.Thread`` This adds addition JPype methods to java.lang.Thread to support @@ -28,7 +28,7 @@ class _JThread(object): """ @staticmethod - def isAttached(): + def isAttached() -> bool: """ Checks if a thread is attached to the JVM. Python automatically attaches as daemon threads when a Java method is @@ -44,7 +44,7 @@ def isAttached(): return _jpype.isThreadAttachedToJVM() @staticmethod - def attach(): + def attach() -> None: """ Attaches the current thread to the JVM as a user thread. User threads that are attached to the JVM will prevent the JVM from @@ -57,7 +57,7 @@ def attach(): return _jpype.attachThreadToJVM() @staticmethod - def attachAsDaemon(): + def attachAsDaemon() -> None: """ Attaches the current thread to the JVM as a daemon. Daemon threads act as background tasks and do not prevent the JVM from @@ -71,7 +71,7 @@ def attachAsDaemon(): return _jpype.attachThreadAsDaemon() @staticmethod - def detach(): + def detach() -> None: """ Detaches a thread from the JVM. This function detaches the thread and frees the associated resource in diff --git a/jpype/_jthread.pyi b/jpype/_jthread.pyi deleted file mode 100644 index fbb828d3f..000000000 --- a/jpype/_jthread.pyi +++ /dev/null @@ -1,12 +0,0 @@ -class _JThread: - @staticmethod - def isAttached() -> bool: ... - - @staticmethod - def attach() -> None: ... - - @staticmethod - def attachAsDaemon() -> None: ... - - @staticmethod - def detach() -> None: ... diff --git a/jpype/_jvmfinder.py b/jpype/_jvmfinder.py index 64b656c2b..299d76f32 100644 --- a/jpype/_jvmfinder.py +++ b/jpype/_jvmfinder.py @@ -26,7 +26,7 @@ try: import winreg except ImportError: - winreg = None + winreg = None # type: ignore[assignment] class JVMNotFoundException(ValueError): @@ -45,7 +45,7 @@ class JVMNotSupportedException(ValueError): This exception is raised after a search found a valid Java home directory was found, but the JVM shared library found is not supported. Typically - this occures when the JVM does not match the architecture of Python + this occurs when the JVM does not match the architecture of Python 32 vs 64 bit, or the JVM is older than the version used to compile JPype. """ diff --git a/jpype/dbapi2.py b/jpype/dbapi2.py index 0541fe02d..e391e3af8 100644 --- a/jpype/dbapi2.py +++ b/jpype/dbapi2.py @@ -232,11 +232,11 @@ def _asPython(x): LONGNVARCHAR: STRING, DOUBLE: DOUBLE, OTHER: OBJECT } -_default_setters = {} +_default_setters = {} # type: ignore[var-annotated] -_default_converters = {} +_default_converters = {} # type: ignore[var-annotated] -_default_adapters = {} +_default_adapters = {} # type: ignore[var-annotated] # Setters take (connection, meta, col, type) -> JDBCTYPE @@ -251,7 +251,7 @@ def SETTERS_BY_META(cx, meta, col, ptype): return _default_map[_registry[meta.getParameterType(col + 1)]] -SETTERS_BY_META._cachable = True +SETTERS_BY_META._cachable = True # type: ignore[attr-defined] def SETTERS_BY_TYPE(cx, meta, col, ptype): diff --git a/jpype/types.py b/jpype/types.py index 0d42f773f..bcebce92d 100644 --- a/jpype/types.py +++ b/jpype/types.py @@ -56,35 +56,35 @@ ] -class JBoolean(_jpype._JBoolean, internal=True): +class JBoolean(_jpype._JBoolean, internal=True): # type: ignore[call-arg] pass -class JByte(_jpype._JNumberLong, internal=True): +class JByte(_jpype._JNumberLong, internal=True): # type: ignore[call-arg] pass -class JChar(_jpype._JChar, internal=True): +class JChar(_jpype._JChar, internal=True): # type: ignore[call-arg] pass -class JInt(_jpype._JNumberLong, internal=True): +class JInt(_jpype._JNumberLong, internal=True): # type: ignore[call-arg] pass -class JShort(_jpype._JNumberLong, internal=True): +class JShort(_jpype._JNumberLong, internal=True): # type: ignore[call-arg] pass -class JLong(_jpype._JNumberLong, internal=True): +class JLong(_jpype._JNumberLong, internal=True): # type: ignore[call-arg] pass -class JFloat(_jpype._JNumberFloat, internal=True): +class JFloat(_jpype._JNumberFloat, internal=True): # type: ignore[call-arg] pass -class JDouble(_jpype._JNumberFloat, internal=True): +class JDouble(_jpype._JNumberFloat, internal=True): # type: ignore[call-arg] pass diff --git a/test/jpypetest/common.py b/test/jpypetest/common.py index 1177eaeb2..757c81d9c 100644 --- a/test/jpypetest/common.py +++ b/test/jpypetest/common.py @@ -22,7 +22,7 @@ import logging from os import path import sys -import unittest +import unittest # Extensively used as common.unittest. CLASSPATH = None fast = False diff --git a/test/jpypetest/importstar.py b/test/jpypetest/importstar.py index 5c257c02e..1b112bcfc 100644 --- a/test/jpypetest/importstar.py +++ b/test/jpypetest/importstar.py @@ -8,11 +8,11 @@ import jpype # import with star the first time -from org.jpype import * +from org.jpype import * # type: ignore try: # This should not be found - late2.Test() + late2.Test() # type: ignore[name-defined] raise ImportError("late was already found") except NameError: pass @@ -22,7 +22,7 @@ # Second import if True: - from org.jpype import * + from org.jpype import * # type: ignore[name-defined] # This time it should work -t = late2.Test() +t = late2.Test() # type: ignore[name-defined] diff --git a/test/jpypetest/subrun.py b/test/jpypetest/subrun.py index a07508d3d..f0a24f787 100644 --- a/test/jpypetest/subrun.py +++ b/test/jpypetest/subrun.py @@ -24,7 +24,7 @@ import unittest import common -_modules = {} +_modules = {} # type: ignore[var-annotated] def _import(filename): diff --git a/test/jpypetest/test_boxed.py b/test/jpypetest/test_boxed.py index ba1035eb7..a55b7aae8 100644 --- a/test/jpypetest/test_boxed.py +++ b/test/jpypetest/test_boxed.py @@ -289,12 +289,12 @@ def testLongBoxOps(self): self.assertIsInstance(u, jpype.java.lang.Long) self.compareTest(u, 81) - def testIntBoxOps(self): + def testIntBoxOps_2(self): u = JObject(81, JFloat) self.assertIsInstance(u, jpype.java.lang.Float) self.compareTest(u, 81) - def testLongBoxOps(self): + def testLongBoxOps_2(self): u = JObject(81, JDouble) self.assertIsInstance(u, jpype.java.lang.Double) self.compareTest(u, 81) diff --git a/test/jpypetest/test_coverage.py b/test/jpypetest/test_coverage.py index 78f6322ce..f981caa95 100644 --- a/test/jpypetest/test_coverage.py +++ b/test/jpypetest/test_coverage.py @@ -76,9 +76,8 @@ def testJArrayLength(self): self.assertEqual(ja.length, len(ja)) def testJArrayGetItemSlice(self): - with self.assertRaises(NotImplementedError): - ja = jpype.JArray(jpype.JInt)([1, 2, 3, 4]) - ja[0:2:-1] + ja = jpype.JArray(jpype.JInt)([1, 2, 3, 4]) + assert list(ja[0:2:-1]) == [1, 2, 3, 4][0:2:-1] def testJArraySetItemSlice(self): ja = jpype.JArray(jpype.JInt)([1, 2, 3, 4, 5, 6]) @@ -87,22 +86,27 @@ def testJArraySetItemSlice(self): # FIXME ja[0:-1:2] = [-1] works but should not # FIXME ja[0:-1:2] = 1 gives wierd error - def testJArrayGetItemSlice(self): + def testJArrayGetItemSlice_2(self): ja = jpype.JArray(jpype.JInt)([1, 2, 3, 4]) - ja[1:] + assert list(ja[1:]) == [2, 3, 4] - def testJArraySetItemSlice(self): + def testJArraySetItemSlice_2(self): ja = jpype.JArray(jpype.JInt)([1, 2, 3, 4]) ja[1:] = [3, 4, 5] self.assertEqual(list(ja[:]), [1, 3, 4, 5]) def testJArrayEQ(self): - ja = jpype.JArray(jpype.JInt)([1, 2, 3, 4]) - ja == [1, 2] + ja1 = jpype.JArray(jpype.JInt)([1, 2, 3, 4]) + ja2 = jpype.JArray(jpype.JInt)([1, 2, 3, 4]) + ja1 == ja2 + # FIXME: This test is failing, but shouldn't be. + # assert ja1 == ja2 + assert (ja1 == [1, 2]) is False def testJArrayNE(self): ja = jpype.JArray(jpype.JInt)([1, 2, 3, 4]) - ja != [1, 2] + assert ja != [1, 2] + assert (ja != ja) is False def testJArrayIter(self): ja = jpype.JArray(jpype.JInt)([1, 2, 3, 4]) @@ -257,14 +261,14 @@ def foo(): pass # this is executed in a thread which may start later magic = mock.MagicMock() with mock.patch("sys.platform", "other"), mock.patch.dict('sys.modules', {'PyObjCTools': magic}): - from PyObjCTools import AppHelper + from PyObjCTools import AppHelper # type: ignore self.assertEqual(sys.platform, "other") jpype.setupGuiEnvironment(foo) self.assertFalse(magic.AppHelper.runConsoleEventLoop.called) jpype.shutdownGuiEnvironment() self.assertFalse(magic.AppHelper.stopEventLoop.called) with mock.patch("sys.platform", "darwin"), mock.patch.dict('sys.modules', {'PyObjCTools': magic}): - from PyObjCTools import AppHelper + from PyObjCTools import AppHelper # type: ignore self.assertEqual(sys.platform, "darwin") jpype.setupGuiEnvironment(foo) self.assertTrue(magic.AppHelper.runConsoleEventLoop.called) @@ -281,4 +285,4 @@ def testImportNotStarted(self): with mock.patch('_jpype.isStarted') as func: func.return_value = False with self.assertRaisesRegex(ImportError, "jvm"): - import mil.spec + import mil.spec # type: ignore diff --git a/test/jpypetest/test_exc.py b/test/jpypetest/test_exc.py index f1c68a645..02700d690 100644 --- a/test/jpypetest/test_exc.py +++ b/test/jpypetest/test_exc.py @@ -16,9 +16,8 @@ # # ***************************************************************************** import jpype -from jpype import JException, java, JProxy, JClass +from jpype import java, JProxy from jpype.types import * -import traceback import common @@ -133,7 +132,7 @@ def testExcCtor(self): def testExcCauseChained1(self): import jpype.imports try: - from org.jpype.fail import BadInitializer + from org.jpype.fail import BadInitializer # type: ignore except Exception as ex: ex1 = ex self.assertIsInstance(ex1, ImportError) diff --git a/test/jpypetest/test_fault.py b/test/jpypetest/test_fault.py index 5713fd2ae..441aa5466 100644 --- a/test/jpypetest/test_fault.py +++ b/test/jpypetest/test_fault.py @@ -15,6 +15,8 @@ # See NOTICE file for details. # # ***************************************************************************** +import unittest + import _jpype import jpype from jpype import * @@ -66,7 +68,7 @@ def testJPArray_new(self): # FIXME investigate why the release is not happening # may indicate a leak. Disabling for now - @common.unittest.SkipTest + @common.unittest.SkipTest # type: ignore def testJPArray_releaseBuffer(self): _jpype.fault("PyJPArray_releaseBuffer") @@ -363,7 +365,7 @@ def testJPProxy_new(self): # FIXME this needs special treatment. It should call __str__() # if toString is not defined. Disable for now. - @common.unittest.SkipTest + @common.unittest.SkipTest # type: ignore[arg-type] def testJPProxy_str(self): # Java has a hidden requirement that toString be available @JImplements("java.util.function.DoubleUnaryOperator") @@ -408,7 +410,7 @@ def accept(self, d): jo.accept(None) @common.requireInstrumentation - def testJPProxy_void(self): + def testJPProxy_void_2(self): @JImplements("java.util.function.Consumer") class f(object): @JOverride @@ -550,7 +552,7 @@ def testJPObject(self): # indicates a problem in the exception handling path. # AssertionError: "fault" does not match "NULL context in JPRef() # Disabling for now. - @common.unittest.SkipTest + @common.unittest.SkipTest # type: ignore[arg-type] @common.requireInstrumentation def testJPTypeManagerFindClass(self): ja = JArray(JInt, 2)([[1, 1], [1, 1]]) @@ -930,15 +932,15 @@ def testJPJavaFrameMonitor(self): jo = JClass("java.lang.Object")() _jpype.fault("JPJavaFrame::MonitorEnter") with self.assertRaisesRegex(SystemError, "fault"): - with syncronized(jo): + with jpype.synchronized(jo): pass _jpype.fault("JPJavaFrame::MonitorExit") with self.assertRaisesRegex(SystemError, "fault"): - with syncronized(jo): + with jpype.synchronized(jo): pass @common.requireInstrumentation - def testJPJavaFrameMonitor(self): + def testJPJavaFrameMonitor_2(self): _jpype.fault("JPJavaFrame::FromReflectedMethod") with self.assertRaisesRegex(SystemError, "fault"): raise SystemError("fault") diff --git a/test/jpypetest/test_imports.py b/test/jpypetest/test_imports.py index a6d5974f3..e0828be71 100644 --- a/test/jpypetest/test_imports.py +++ b/test/jpypetest/test_imports.py @@ -88,18 +88,18 @@ def testImportFail(self): def testAlias1(self): jpype.imports.registerDomain("jpypex", alias="jpype") - from jpypex.common import Fixture + from jpypex.common import Fixture # type: ignore self.assertEqual(Fixture, jpype.JClass("jpype.common.Fixture")) def testAlias2(self): jpype.imports.registerDomain("commonx", alias="jpype.common") - from commonx import Fixture as Fixture2 + from commonx import Fixture as Fixture2 # type: ignore self.assertEqual(Fixture2, jpype.JClass("jpype.common.Fixture")) def testAliasBad(self): jpype.imports.registerDomain("brokenx", alias="jpype.broken") with self.assertRaises(ImportError): - from brokenx import Fixture as Fixture2 + from brokenx import Fixture as Fixture2 # type: ignore def testIsPackage(self): import java.lang @@ -109,7 +109,7 @@ def testIsPackage(self): self.assertTrue(issubclass(type(java.lang), jpype.JPackage)) def testMRJar(self): - import org.jpype.mrjar as mrjar + import org.jpype.mrjar as mrjar # type: ignore u = dir(mrjar) self.assertTrue("A" in u) self.assertTrue("B" in u) @@ -120,7 +120,7 @@ def testAddClassPath(self): import org.jpype as ojp self.assertFalse("late" in dir(ojp)) with self.assertRaises(ImportError): - import org.jpype.late as late + import org.jpype.late as late # type: ignore jpype.addClassPath(pathlib.Path("test/jar/late/late.jar").absolute()) import org.jpype.late as late diff --git a/test/jpypetest/test_javacoverage.py b/test/jpypetest/test_javacoverage.py index 477830b0b..fbffb9c90 100644 --- a/test/jpypetest/test_javacoverage.py +++ b/test/jpypetest/test_javacoverage.py @@ -54,7 +54,7 @@ def testModifiers(self): cls = JClass('org.jpype.manager.ModifierCode') self.assertEqual(cls.get(cls.decode(1171)), 1171) - def testTypeFactory(self): + def testTypeFactory_2(self): TypeFactory = JClass("org.jpype.manager.TypeFactory") TypeManager = JClass("org.jpype.manager.TypeManager") @JImplements(TypeFactory) diff --git a/test/jpypetest/test_jchar.py b/test/jpypetest/test_jchar.py index 410dbc7a5..32dc9bdfa 100644 --- a/test/jpypetest/test_jchar.py +++ b/test/jpypetest/test_jchar.py @@ -474,7 +474,7 @@ def testPass(self): self.assertEqual(fixture.callObject(self.nc), None) -class JCharTestCase(common.JPypeTestCase): +class JCharTestCase_2(common.JPypeTestCase): def testOps(self): self.assertEqual(JChar("x") + "test", "xtest") diff --git a/test/jpypetest/test_jclass.py b/test/jpypetest/test_jclass.py index 107a19b4e..9907062cd 100644 --- a/test/jpypetest/test_jclass.py +++ b/test/jpypetest/test_jclass.py @@ -85,12 +85,12 @@ def testSetAttrProperty(self): with self.assertRaises(AttributeError): cls.args = 1 - def testGetAttrStaticField(self): + def testGetAttrStaticField_2(self): cls = JClass('jpype.common.Fixture') cls.static_object_field = "fred" self.assertEqual(cls.static_object_field, "fred") - def testSetAttrStaticField(self): + def testSetAttrStaticField_3(self): cls = JClass('jpype.common.Fixture') cls.static_object_field = "fred" diff --git a/test/jpypetest/test_jint.py b/test/jpypetest/test_jint.py index 5f09d208e..b9511b84a 100644 --- a/test/jpypetest/test_jint.py +++ b/test/jpypetest/test_jint.py @@ -153,7 +153,7 @@ def testFromJIntWiden(self): self.assertEqual(JInt(JInt(12345678)), 12345678) self.assertEqual(JInt(JLong(12345678)), 12345678) - def testFromJIntWiden(self): + def testFromJIntWiden_2(self): self.assertEqual(JInt(JDouble(12345678)), 12345678) def testFromNone(self): diff --git a/test/jpypetest/test_jlong.py b/test/jpypetest/test_jlong.py index cd4483bcc..5f4178f08 100644 --- a/test/jpypetest/test_jlong.py +++ b/test/jpypetest/test_jlong.py @@ -147,13 +147,13 @@ def f(): with self.assertRaisesRegex(SystemError, "fault"): ja[1:3] = [0, 0] - def testFromJLongWiden(self): + def testFromJLongWiden_2(self): self.assertEqual(JLong(JByte(123)), 123) self.assertEqual(JLong(JShort(12345)), 12345) self.assertEqual(JLong(JInt(12345678)), 12345678) self.assertEqual(JLong(JLong(12345678)), 12345678) - def testFromJLongWiden(self): + def testFromJLongWiden_3(self): self.assertEqual(JLong(JDouble(12345678)), 12345678) def testFromNone(self): @@ -278,7 +278,7 @@ def testCheckJLong(self): self.checkType(JLong(-2**31 + 1)) self.checkType(JLong(2**31 - 1)) - def testCheckJLong(self): + def testCheckJLong_2(self): self.checkType(JLong(-2**63 + 1)) self.checkType(JLong(2**63 - 1)) diff --git a/test/jpypetest/test_jmethod.py b/test/jpypetest/test_jmethod.py index 8fe663568..8216a67ab 100644 --- a/test/jpypetest/test_jmethod.py +++ b/test/jpypetest/test_jmethod.py @@ -145,10 +145,6 @@ def testMethodClone(self): a = copy_func(self.obj.substring) self.assertEqual(a(1), "oo") - def testMethodDump(self): - # This is replaced by doc, should be removed - self.assertIsInstance(jpype.JString("foo").substring.dump(), str) - def testMethodDump(self): # This is replaced by doc, should be removed (or do something useful) self.assertIsInstance(jpype.JString( @@ -180,7 +176,7 @@ def testJMethod_str(self): str(fixture.callInt) @common.requireInstrumentation - def testJMethod_str(self): + def testJMethod_str_2(self): Fixture = JClass("jpype.common.Fixture") fixture = Fixture() _jpype.fault("PyJPMethod_get") @@ -228,7 +224,7 @@ def testJMethod_docFault(self): fixture.callInt.__doc__ = None @common.requireInstrumentation - def testJMethod_docFault(self): + def testJMethod_docFault_2(self): fixture = JClass("jpype.common.Fixture")() _jpype.fault("PyJPMethod_getCodeAttr") with self.assertRaisesRegex(SystemError, "fault"): diff --git a/test/jpypetest/test_jobject.py b/test/jpypetest/test_jobject.py index 7ed920bae..b6fcd87c2 100644 --- a/test/jpypetest/test_jobject.py +++ b/test/jpypetest/test_jobject.py @@ -302,7 +302,7 @@ def testGetSetBad(self): with self.assertRaises(TypeError): setattr(js, object(), 1) - def testGetSetBad(self): + def testGetSetBad_2(self): jo = JClass("java.lang.Object")() self.assertTrue(jo != JInt(0)) self.assertFalse(jo == JInt(0)) diff --git a/test/jpypetest/test_jstring.py b/test/jpypetest/test_jstring.py index 4c6b46190..8328990be 100644 --- a/test/jpypetest/test_jstring.py +++ b/test/jpypetest/test_jstring.py @@ -169,6 +169,10 @@ def testNullHash(self): jsn = JObject(None, JString) self.assertEqual(hash(jsn), hash(None)) + def testEmptyHash(self): + jsn = JObject('', JString) + self.assertEqual(hash(jsn), hash('')) + def testSlice(self): s = 'abcdefghijklmnop' s2 = JString(s) diff --git a/test/jpypetest/test_jvmfinder.py b/test/jpypetest/test_jvmfinder.py index 7994612d2..4e16a7b2e 100644 --- a/test/jpypetest/test_jvmfinder.py +++ b/test/jpypetest/test_jvmfinder.py @@ -111,7 +111,7 @@ def testDarwinBinary(self, mock_mac_ver): # it is included only for coverage purposes. Revise this to be a more meaningful test # next time it breaks. # FIXME this test does passes locally but not in the CI. Disabling for now. - @common.unittest.skip + @common.unittest.skip # type: ignore def testPlatform(self): with mock.patch('jpype._jvmfinder.sys') as mocksys, mock.patch('jpype._jvmfinder.WindowsJVMFinder') as finder: mocksys.platform = 'win32' @@ -147,7 +147,7 @@ def f(s): # FIXME this test is faking files using the mock system. Replace it with stub # files so that we have a more accurate test rather than just testing the implementation. # FIXME this fails in the CI but works locally. Disabling this for now. - @common.unittest.skip + @common.unittest.skip # type: ignore def testCheckArch(self): import struct with mock.patch("builtins.open", mock.mock_open(read_data="data")) as mock_file, \ diff --git a/test/jpypetest/test_leak.py b/test/jpypetest/test_leak.py index f2ed4854f..76ec31524 100644 --- a/test/jpypetest/test_leak.py +++ b/test/jpypetest/test_leak.py @@ -19,7 +19,6 @@ import jpype import gc import sys -import os from os import path import subrun import unittest @@ -27,12 +26,11 @@ try: import resource except ImportError: - resource = None - pass + resource = None # type: ignore[assignment] def haveResource(): - return bool(resource) + return resource is not None def hasRefCount(): @@ -43,7 +41,7 @@ def hasRefCount(): return False -class LeakChecker(): +class LeakChecker: def __init__(self): self.runtime = jpype.java.lang.Runtime.getRuntime() diff --git a/test/jpypetest/test_map.py b/test/jpypetest/test_map.py index bdadcb8d7..b0365d895 100644 --- a/test/jpypetest/test_map.py +++ b/test/jpypetest/test_map.py @@ -59,7 +59,7 @@ def testSetItem(self): obj['b'] = 5 self.assertEqual(obj['b'], 5) - def testSetItem(self): + def testSetItem_2(self): cls = jpype.JClass('java.util.TreeMap') obj = cls() obj.put("a", 1) diff --git a/test/jpypetest/test_sql_generic.py b/test/jpypetest/test_sql_generic.py index 14d637f84..d2381a2ec 100644 --- a/test/jpypetest/test_sql_generic.py +++ b/test/jpypetest/test_sql_generic.py @@ -1,16 +1,9 @@ # This file is Public Domain and may be used without restrictions. -import _jpype -import jpype from jpype.types import * -from jpype import java import jpype.dbapi2 as dbapi2 import common import time -try: - import zlib -except ImportError: - zlib = None class SQLModuleTestCase(common.JPypeTestCase): diff --git a/test/jpypetest/test_sql_h2.py b/test/jpypetest/test_sql_h2.py index e173c0463..e8471ca73 100644 --- a/test/jpypetest/test_sql_h2.py +++ b/test/jpypetest/test_sql_h2.py @@ -1,12 +1,10 @@ # This file is Public Domain and may be used without restrictions, -# because noone should have to waste their lives typing this again. -import _jpype +# because nobody should have to waste their lives typing this again. import jpype from jpype.types import * from jpype import java import jpype.dbapi2 as dbapi2 import common -import time import datetime import decimal import threading @@ -16,7 +14,7 @@ try: import zlib except ImportError: - zlib = None + zlib = None # type: ignore[assignment] db_name = "jdbc:h2:mem:testdb" @@ -795,6 +793,7 @@ def mygen(ls): cu.execute("insert into booze(name,price) values(?,?)", object()) +@common.unittest.skipUnless(zlib, "requires zlib") class AdapterTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) @@ -907,6 +906,7 @@ def testTypesPositionalBAD(self): f = cu.fetchone(types=[]) +@common.unittest.skipUnless(zlib, "requires zlib") class GettersTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) diff --git a/test/jpypetest/test_sql_hsqldb.py b/test/jpypetest/test_sql_hsqldb.py index 41b2913fc..231a3a8a0 100644 --- a/test/jpypetest/test_sql_hsqldb.py +++ b/test/jpypetest/test_sql_hsqldb.py @@ -16,7 +16,7 @@ try: import zlib except ImportError: - zlib = None + zlib = None # type: ignore[assignment] db_name = "jdbc:hsqldb:mem:myDb" @@ -24,6 +24,7 @@ #first = "jdbc:derby:memory:myDb;create=True" +@common.unittest.skipUnless(zlib, "requires zlib") class ConnectTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) @@ -793,6 +794,7 @@ def mygen(ls): cu.execute("insert into booze(name,price) values(?,?)", object()) +@common.unittest.skipUnless(zlib, "requires zlib") class AdapterTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) @@ -905,6 +907,7 @@ def testTypesPositionalBAD(self): f = cu.fetchone(types=[]) +@common.unittest.skipUnless(zlib, "requires zlib") class GettersTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) @@ -921,7 +924,7 @@ def tearDown(self): pass -@common.unittest.skip +@common.unittest.skip # type: ignore class TransactionsTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) diff --git a/test/jpypetest/test_sql_sqlite.py b/test/jpypetest/test_sql_sqlite.py index 182dd515e..a63b4e02c 100644 --- a/test/jpypetest/test_sql_sqlite.py +++ b/test/jpypetest/test_sql_sqlite.py @@ -1,12 +1,10 @@ # This file is Public Domain and may be used without restrictions, -# because noone should have to waste their lives typing this again. -import _jpype +# because nobody should have to waste their lives typing this again. import jpype from jpype.types import * from jpype import java import jpype.dbapi2 as dbapi2 import common -import time import datetime import decimal import threading @@ -16,7 +14,7 @@ try: import zlib except ImportError: - zlib = None + zlib = None # type: ignore[assignment] db_name = "jdbc:sqlite::memory:" @@ -657,7 +655,7 @@ def test_nextset(self): if nxt: self.assertEqual(cu.fetchone(), booze) - @common.unittest.skip + @common.unittest.skip # type: ignore def test_lastrowid(self): with dbapi2.connect(db_name) as cx, cx.cursor() as cu: cu.execute("create table booze(id INTEGER IDENTITY PRIMARY KEY, name varchar(255))") @@ -677,7 +675,7 @@ def test_lastrowid(self): self.assertEqual(f[0][0], id0) self.assertEqual(f[1][0], id2) - @common.unittest.skip + @common.unittest.skip # type: ignore def test_lastrowidMany(self): with dbapi2.connect(db_name) as cx, cx.cursor() as cu: cu.execute("create table booze(id INTEGER IDENTITY PRIMARY KEY, name varchar(255))") @@ -721,7 +719,7 @@ def test_callproc(self): with self.assertRaises(dbapi2.ProgrammingError): r = cu.callproc("lower", ("FOO",)) - @common.unittest.skip + @common.unittest.skip # type: ignore def test_callprocBad(self): with dbapi2.connect(db_name) as cx, cx.cursor() as cu: with self.assertRaises(dbapi2.ProgrammingError): @@ -793,6 +791,7 @@ def mygen(ls): cu.execute("insert into booze(name,price) values(?,?)", object()) +@common.unittest.skipUnless(zlib, "requires zlib") class AdapterTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) @@ -905,6 +904,7 @@ def testTypesPositionalBAD(self): f = cu.fetchone(types=[]) +@common.unittest.skipUnless(zlib, "requires zlib") class GettersTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) @@ -921,7 +921,7 @@ def tearDown(self): pass -@common.unittest.skip +@common.unittest.skip # type: ignore class TransactionsTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) @@ -1327,7 +1327,7 @@ def test_close(self): cu.execute("insert into test(name) values('a')") self._testThread(cu, cu.close, (), dbapi2.ProgrammingError) - @common.unittest.skip + @common.unittest.skip # type: ignore def test_callproc(self): with dbapi2.connect(db_name) as cx, cx.cursor() as cu: cu.execute("create table test(name VARCHAR(10))")