Skip to content

Commit

Permalink
Coverage (jpype-project#769)
Browse files Browse the repository at this point in the history
* Fixed issue with throwing to Java.
* Remove JPPyTuple and fix multiple memory leaks.
* Update sequence and check for leaks
* Make imported packages pass JPackage check.
* Tests for imports is JPackage
* Integration of javadoc to PR
* Removed autogenerator comment
* Swap mvn with ivy.  Complete python coverage.
* Removed stub code attachToJVM.
* Coverage improvements, bug fixes
* Remove memory compiler
* Fixed JObject creating null pointer by default.
* Restored old str() behavior for Exceptions
* Specialize NotRunning
  • Loading branch information
Thrameos authored Jun 13, 2020
1 parent e1afec6 commit 8a158e3
Show file tree
Hide file tree
Showing 62 changed files with 339 additions and 510 deletions.
13 changes: 13 additions & 0 deletions .azure/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ pr:
- test/*

jobs:
- job: Deps
pool:
vmImage: "ubuntu-16.04"
steps:
- template: scripts/ivy.yml

- job: Documentation
pool:
vmImage: "ubuntu-16.04"
Expand All @@ -24,7 +30,9 @@ jobs:
- job: Coverage
pool:
vmImage: "ubuntu-16.04"
dependsOn: Deps
steps:
- template: scripts/deps.yml
- template: scripts/coverage.yml

- job: Tracing
Expand All @@ -34,6 +42,7 @@ jobs:
- template: scripts/tracing.yml

- job: Test
dependsOn: Deps
strategy:
matrix:
linux-3.5:
Expand Down Expand Up @@ -66,10 +75,12 @@ jobs:
pool:
vmImage: $(imageName)
steps:
- template: scripts/deps.yml
- template: scripts/test.yml

- job: Debug
condition: eq(1,0)
dependsOn: Deps
strategy:
matrix:
linux-3.8:
Expand All @@ -79,4 +90,6 @@ jobs:
pool:
vmImage: $(imageName)
steps:
- template: scripts/deps.yml
- template: scripts/debug.yml

4 changes: 4 additions & 0 deletions .azure/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ stages:
vmImage: "ubuntu-16.04"
steps:
- template: scripts/sdist.yml
- template: scripts/ivy.yml

- stage: Package
jobs:
Expand All @@ -46,6 +47,7 @@ stages:
pool:
vmImage: "ubuntu-16.04"
steps:
- template: scripts/deps.yml
- template: scripts/wheels-linux.yml
- template: scripts/publish-dist.yml

Expand All @@ -65,6 +67,7 @@ stages:
pool:
vmImage: 'vs2017-win2016'
steps:
- template: scripts/deps.yml
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
Expand All @@ -90,6 +93,7 @@ stages:
pool:
vmImage: "macOS-10.14"
steps:
- template: scripts/deps.yml
- script: .azure/scripts/osx-python.sh '$(python.version)'
displayName: Install Python.org Python
- template: scripts/jdk.yml
Expand Down
6 changes: 3 additions & 3 deletions .azure/scripts/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ steps:
parameters:
version: 11

- script: mvn -q -f project/coverage package
- script: |
python setup.py test_java
pip install gcovr pytest-cov jedi
Expand All @@ -21,12 +20,13 @@ steps:
displayName: 'Build'

- script: |
python -m pytest -v test/jpypetest --cov=jpype --cov-report=xml:coverage_py.xml --classpath="build/classes" --jacoco --checkjni
ls lib
python -m pytest -v -s test/jpypetest --cov=jpype --cov-report=xml:coverage_py.xml --classpath="build/classes" --jacoco --checkjni
displayName: 'Test'

- script: |
gcovr -r . --xml -o coverage.xml --exclude-unreachable-branches --exclude-throw-branches
java -jar project/coverage/org.jacoco.cli-0.8.5-nodeps.jar report build/coverage/jacoco.exec --classfiles build/classes/ --xml coverage_java.xml --sourcefiles native/java
java -jar lib/org.jacoco.cli-0.8.5-nodeps.jar report build/coverage/jacoco.exec --classfiles build/classes/ --xml coverage_java.xml --sourcefiles native/java
bash <(curl -s https://codecov.io/bash) -f coverage.xml -f coverage_py.xml -f coverage_java.xml -X gcov
displayName: 'Report'

Expand Down
7 changes: 7 additions & 0 deletions .azure/scripts/deps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
steps:
- task: DownloadPipelineArtifact@2
inputs:
source: current
artifact: artifact_Deps
path: lib

10 changes: 10 additions & 0 deletions .azure/scripts/ivy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
steps:
- script: |
wget "https://repo1.maven.org/maven2/org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar" -P lib
java -jar lib/ivy-2.4.0.jar -ivy ivy.xml -retrieve 'lib/[artifact]-[revision](-[classifier]).[ext]'
displayName: 'Resolve'
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'artifact_Deps'
targetPath: 'lib'
displayName: Publish deps
2 changes: 1 addition & 1 deletion .azure/scripts/sdist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ steps:
displayName: Build sdist
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'artifact_$(Agent.JobName)'
artifactName: 'artifact_SourceDistribution'
targetPath: 'dist'
displayName: Publish sdist
4 changes: 2 additions & 2 deletions coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Script for testing coverage locally
PYTHON=python
PIP="python -m pip"
mvn -q -f project/coverage package
./resolve.sh
$PYTHON setup.py test_java
$PIP install gcovr pytest-cov jedi
$PYTHON setup.py --enable-coverage --enable-build-jar build_ext --inplace
Expand All @@ -12,7 +12,7 @@ $PYTHON -m pytest -rsx -v test/jpypetest \
--cov-report=html:build/coverage/python \
--cov=jpype \
--classpath="build/classes" --jacoco --checkjni
java -jar project/coverage/org.jacoco.cli-0.8.5-nodeps.jar report build/coverage/jacoco.exec \
java -jar lib/org.jacoco.cli-0.8.5-nodeps.jar report build/coverage/jacoco.exec \
--classfiles build/classes/ \
--html build/coverage/java \
--sourcefiles native/java
Expand Down
17 changes: 17 additions & 0 deletions ivy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra" xmlns:m="http://ant.apache.org/ivy/maven">
<info organisation="org.jpype" module="jpype"/>

<configurations defaultconf="deps">
<conf name="deps" description="binary jars"/>
</configurations>

<!-- https://www.baeldung.com/java-in-memory-databases -->
<dependencies>
<dependency org="org.jacoco" name="org.jacoco.cli" rev="0.8.5" conf="deps->default">
<artifact name="org.jacoco.cli" type="jar" m:classifier="nodeps"/>
</dependency>
<dependency org="org.jacoco" name="org.jacoco.agent" rev="0.8.5" conf="deps->default">
<artifact name="org.jacoco.agent" type="jar" m:classifier="runtime"/>
</dependency>
</dependencies>
</ivy-module>
2 changes: 2 additions & 0 deletions jpype/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#
# *****************************************************************************
import _jpype
from ._jinit import *
from ._jpackage import *
from ._jproxy import *
from ._core import *
Expand All @@ -39,6 +40,7 @@
from . import _jthread # lgtm [py/import-own-module]

__all__ = ['java', 'javax']
__all__.extend(_jinit.__all__)
__all__.extend(_core.__all__)
__all__.extend(_classpath.__all__)
__all__.extend(types.__all__)
Expand Down
16 changes: 9 additions & 7 deletions jpype/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@
from ._jvmfinder import *

__all__ = [
'isJVMStarted', 'startJVM', 'attachToJVM', 'shutdownJVM',
'isJVMStarted', 'startJVM', 'shutdownJVM',
'getDefaultJVMPath', 'getJVMVersion', 'isThreadAttachedToJVM', 'attachThreadToJVM',
'detachThreadFromJVM', 'synchronized',
'JVMNotFoundException', 'JVMNotSupportedException'
'JVMNotFoundException', 'JVMNotSupportedException', 'JVMNotRunning'
]


class JVMNotRunning(RuntimeError):
pass


def versionTest():
if sys.version_info < (3,):
raise ImportError("Python 2 is not supported")
Expand Down Expand Up @@ -295,11 +299,6 @@ def startJVM(*args, **kwargs):
list(_pykeywords._KEYWORDS))


def attachToJVM(jvm):
_jpype.attach(jvm)
_initialize()


def shutdownJVM():
""" Shuts down the JVM.
Expand Down Expand Up @@ -425,3 +424,6 @@ def addShutdownHook(self, thread):

def removeShutdownHook(self, thread):
return _jpype.JClass("org.jpype.JPypeContext").getInstance().removeShutdownHook(thread)


_jpype.JVMNotRunning = JVMNotRunning
9 changes: 0 additions & 9 deletions jpype/_jarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,6 @@ class _JArrayProto(object):
def __str__(self):
return str(list(self))

@property
def length(self):
""" Get the length of a Java array
This method is provided for compatiblity with Java syntax.
Generally, the Python style ``len(array)`` should be preferred.
"""
return self.__len__()

def __iter__(self):
return _JavaArrayIter(self)

Expand Down
4 changes: 4 additions & 0 deletions jpype/_jcustomizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ def applyCustomizers(self, name, bases, members):
for b in self.bases:
bases.insert(0, b)

module = name.rsplit('.', 1)
if len(module) == 2:
members['__module__'] = module[0]

# Apply implementations
sticky = []
for proto in self.implementations:
Expand Down
22 changes: 20 additions & 2 deletions jpype/_jinit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,30 @@
# *****************************************************************************
import _jpype

__all__ = ['registerJVMInitializer']
__all__ = ['onJVMStart']

JInitializers = []


def onJVMStart(func):
"""Register a function to be called after JVM is started
This can be used to load module resources that depend on the JVM such as loading
classes. If the JVM is not started, the user supplied function is held in a list until
the JVM starts. When startJVM is called, all functions on the deferred list are called
and the list is cleared. If the JVM is already started, then the function is called
immediately.
Errors from the function will either be raised immediately if the JVM is started, or
from startJVM if the JVM is not yet started.
Args:
func (callable): a function to call when the JVM is started.
"""
registerJVMInitializer(func)


def registerJVMInitializer(func):
"""Register a function to be called after jvm is started"""
if not _jpype.isStarted():
JInitializers.append(func)
else:
Expand All @@ -33,3 +50,4 @@ def registerJVMInitializer(func):
def runJVMInitializers():
for func in JInitializers:
func()
JInitializers.clear()
3 changes: 1 addition & 2 deletions jpype/_jobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ class JObject(_jpype._JObject, internal=True):
"""
def __new__(cls, *args, **kwargs):
# Create a null pointer object
if len(args) == 0:
args = [None]
return _jpype._java_lang_Object()
return _JObjectFactory(*args, **kwargs)


Expand Down
2 changes: 0 additions & 2 deletions jpype/_jthread.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import _jpype
import jpype
import jpype.imports
from . import _jcustomizer


Expand Down
8 changes: 6 additions & 2 deletions native/common/include/jp_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ class JPContext

extern void JPRef_failed();

// GCOVR_EXCL_START
// Not currently used
template<class jref>
JPRef<jref>::JPRef(const JPRef& other)
{
Expand All @@ -292,6 +294,7 @@ JPRef<jref>::JPRef(const JPRef& other)
JPRef_failed();
}
}
// GCOVR_EXCL_STOP

template<class jref>
JPRef<jref>::~JPRef()
Expand All @@ -310,11 +313,12 @@ JPRef<jref>& JPRef<jref>::operator=(const JPRef<jref>& other)
// m_Context may or may not be set up here, so we need to use a
// different frame for unreferencing and referencing
if (m_Context != 0 && m_Ref != 0)
{
{ // GCOVR_EXCL_START
// This code is not currently used.
JPJavaFrame frame = JPJavaFrame::external(m_Context, m_Context->getEnv());
if (m_Ref != 0)
frame.DeleteGlobalRef((jobject) m_Ref);
}
} // GCOVR_EXCL_STOP
m_Context = other.m_Context;
m_Ref = other.m_Ref;
if (m_Context != 0 && m_Ref != 0)
Expand Down
9 changes: 5 additions & 4 deletions native/common/include/jp_primitive_accessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class JPConversionLongNumber : public JPConversionLong<base_t>
return match.type = JPMatch::_explicit;
}

virtual void getInfo(JPClass *cls, JPConversionInfo &info)
virtual void getInfo(JPClass *cls, JPConversionInfo &info) override
{
PyObject *typing = PyImport_AddModule("jpype.protocol");
JPPyObject proto = JPPyObject::call(PyObject_GetAttrString(typing, "SupportsFloat"));
Expand All @@ -216,16 +216,17 @@ template <typename base_t>
class JPConversionLongWiden : public JPConversion
{
public:

virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override // GCOVR_EXCL_LINE
// GCOVR_EXCL_START
virtual JPMatch::Type matches(JPClass *cls, JPMatch &match) override
{
return JPMatch::_none; // Not used
}

virtual void getInfo(JPClass *cls, JPConversionInfo &info) override // GCOVR_EXCL_LINE
virtual void getInfo(JPClass *cls, JPConversionInfo &info) override
{
// Not used
}
// GCOVR_EXCL_STOP

virtual jvalue convert(JPMatch &match) override
{
Expand Down
6 changes: 3 additions & 3 deletions native/common/jp_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ JPArray::JPArray(const JPValue &value)

// We will use this during range checks, so cache it
if (m_Object.get() == NULL)
m_Length = 0;
m_Length = 0; // GCOVR_EXCL_LINE
else
m_Length = frame.GetArrayLength(m_Object.get());

Expand All @@ -59,7 +59,7 @@ JPArray::JPArray(JPArray* instance, jsize start, jsize stop, jsize step)
else
m_Length = (stop - start + 1 + step) / step;
if (m_Length < 0)
m_Length = 0;
m_Length = 0; // GCOVR_EXCL_LINE
m_Slice = true;
JP_TRACE_OUT;
}
Expand Down Expand Up @@ -229,7 +229,7 @@ JPArrayView::JPArrayView(JPArray* array, jobject collection)
m_Buffer.shape = m_Shape;
m_Buffer.strides = m_Strides;
m_Buffer.readonly = 1;
JP_TRACE_OUT;
JP_TRACE_OUT; // GCOVR_EXCL_LINE
}

JPArrayView::~JPArrayView()
Expand Down
Loading

0 comments on commit 8a158e3

Please sign in to comment.