From 678742a8cf7b3f9c00c161916e73ca1fdb08920a Mon Sep 17 00:00:00 2001 From: Gabriel Pettier Date: Fri, 6 Dec 2019 01:00:51 +0100 Subject: [PATCH] activate coveralls again --- .coveragerc | 6 ++++++ .github/workflows/push.yml | 34 ++++++++++++---------------------- pytest.ini | 2 ++ setup.py | 4 ++++ tests/__init__.py | 0 tests/test_int_vs_long.py | 8 ++++---- tests/test_proxy.py | 18 +++++++++--------- tests/test_signature.py | 16 ++++++++-------- 8 files changed, 45 insertions(+), 43 deletions(-) create mode 100644 .coveragerc create mode 100644 pytest.ini create mode 100644 tests/__init__.py diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 00000000..49d63f46 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,6 @@ +[run] +plugins = Cython.Coverage +source = jnius/ +omit = + tests + *__init__.py diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index b959aa5f..e0100a0d 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -50,49 +50,39 @@ jobs: if: matrix.os == 'windows-latest' run: | "%VS140COMNTOOLS%../../VC/vcvarsall.bat" - echo "$INCLUDE" set INCLUDE "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt" pip install --timeout=120 -U setuptools cython - pip install --timeout=120 -vv .[dev,ci] + pip install --timeout=120 --editable .[dev,ci] - name: install if: matrix.os == 'ubuntu-latest' run: | pip install --timeout=120 -U setuptools cython - pip install --timeout=120 .[dev,ci] + pip install --timeout=120 --editable .[dev,ci] - name: install-osx if: matrix.os == 'macOs-latest' run: | brew install ant pip install --timeout=120 --user -U setuptools cython - pip install --timeout=120 --user .[dev,ci] + pip install --timeout=120 --user --editable .[dev,ci] - name: test-windows if: matrix.os == 'windows-latest' run: | $env:PATH +=";$env:JAVA_HOME\jre\bin\server\;$env:JAVA_HOME\jre\bin\client\;$env:JAVA_HOME\bin\server\" - $env:CLASSPATH ="../build/test-classes;../build/classes" - + $env:CLASSPATH ="./build/test-classes;./build/classes" ant all - cd tests - pytest -v + pytest - name: test - if: matrix.os == 'ubuntu-latest' - run: | - ant all - cd tests - CLASSPATH=../build/test-classes:../build/classes pytest -v - - - name: test - if: matrix.os == 'macOs-latest' + if: matrix.os != 'windows-latest' run: | ant all - cd tests - CLASSPATH=../build/test-classes:../build/classes python -m pytest -v + CLASSPATH=./build/test-classes:./build/classes python -m pytest -# - name: coveralls -# run: python -m coveralls -# env: -# COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} + - name: coveralls + run: python -m coveralls + env: + COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} + COVERALLS_PARALLEL: true diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..e71d3ce0 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +addopts = --cov=jnius -v tests diff --git a/setup.py b/setup.py index 04d25b1f..3059654b 100644 --- a/setup.py +++ b/setup.py @@ -95,6 +95,10 @@ def compile_native_invocation_handler(*possible_homes): # generate the config.pxi with open(join(dirname(__file__), 'jnius', 'config.pxi'), 'w') as fd: fd.write('DEF JNIUS_PLATFORM = {0!r}\n\n'.format(PLATFORM)) + if getenv('GITHUB_WORKFLOW') == 'Tests': + print("GITHUB_WORKFLOW Tests detected, tracing cython code for coverage") + fd.write('# cython: linetrace=True') + fd.write('# distutils: define_macros=CYTHON_TRACE=1') if not PY2: fd.write('# cython: language_level=3\n\n') fd.write('DEF JNIUS_PYTHON3 = True\n\n') diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_int_vs_long.py b/tests/test_int_vs_long.py index 7bc6b065..ee0d16a9 100644 --- a/tests/test_int_vs_long.py +++ b/tests/test_int_vs_long.py @@ -3,15 +3,15 @@ from jnius import autoclass, cast, PythonJavaClass, java_method -class TestImplemIterator(PythonJavaClass): +class _TestImplemIterator(PythonJavaClass): __javainterfaces__ = ['java/util/ListIterator'] -class TestImplem(PythonJavaClass): +class _TestImplem(PythonJavaClass): __javainterfaces__ = ['java/util/List'] def __init__(self, *args): - super(TestImplem, self).__init__(*args) + super(_TestImplem, self).__init__(*args) self.data = list(args) @java_method('()I') @@ -39,7 +39,7 @@ def test_reverse(self): Collections = autoclass('java.util.Collections') List = autoclass('java.util.List') pylist = list(range(10)) - a = TestImplem(*pylist) + a = _TestImplem(*pylist) self.assertEqual(a.data, pylist) self.assertEqual(str(a.data), '[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]') diff --git a/tests/test_proxy.py b/tests/test_proxy.py index 0e8dc793..13f642aa 100644 --- a/tests/test_proxy.py +++ b/tests/test_proxy.py @@ -9,7 +9,7 @@ print('1: declare a TestImplem that implement Collection') -class TestImplemIterator(PythonJavaClass): +class _TestImplemIterator(PythonJavaClass): __javainterfaces__ = [ #'java/util/Iterator', 'java/util/ListIterator', ] @@ -55,16 +55,16 @@ def set(self, obj): self.collection.data[self.index - 1] = obj -class TestImplem(PythonJavaClass): +class _TestImplem(PythonJavaClass): __javainterfaces__ = ['java/util/List'] def __init__(self, *args): - super(TestImplem, self).__init__(*args) + super(_TestImplem, self).__init__(*args) self.data = list(args) @java_method('()Ljava/util/Iterator;') def iterator(self): - it = TestImplemIterator(self) + it = _TestImplemIterator(self) return it @java_method('()Ljava/lang/String;') @@ -91,17 +91,17 @@ def toArray(self): @java_method('()Ljava/util/ListIterator;') def listIterator(self): - it = TestImplemIterator(self) + it = _TestImplemIterator(self) return it @java_method('(I)Ljava/util/ListIterator;', name='ListIterator') def listIteratorI(self, index): - it = TestImplemIterator(self, index) + it = _TestImplemIterator(self, index) return it -class TestBadSignature(PythonJavaClass): +class _TestBadSignature(PythonJavaClass): __javainterfaces__ = ['java/util/List'] @java_method('(Landroid/bluetooth/BluetoothDevice;IB[])V') @@ -110,7 +110,7 @@ def bad_signature(self, *args): print('2: instantiate the class, with some data') -a = TestImplem(*list(range(10))) +a = _TestImplem(*list(range(10))) print(a) print(dir(a)) @@ -158,7 +158,7 @@ def bad_signature(self, *args): # test bad signature threw = False try: - TestBadSignature() + _TestBadSignature() except Exception: threw = True diff --git a/tests/test_signature.py b/tests/test_signature.py index 07c9422f..a6d44d0d 100644 --- a/tests/test_signature.py +++ b/tests/test_signature.py @@ -8,12 +8,12 @@ JString = autoclass('java/lang/String') JListIterator = autoclass("java.util.ListIterator") -class TestImplemIterator(PythonJavaClass): +class _TestImplemIterator(PythonJavaClass): __javainterfaces__ = [ 'java/util/ListIterator', ] def __init__(self, collection, index=0): - super(TestImplemIterator, self).__init__() + super(_TestImplemIterator, self).__init__() self.collection = collection self.index = index @@ -54,16 +54,16 @@ def set(self, obj): self.collection.data[self.index - 1] = obj -class TestImplem(PythonJavaClass): +class _TestImplem(PythonJavaClass): __javainterfaces__ = ['java/util/List'] def __init__(self, *args): - super(TestImplem, self).__init__(*args) + super(_TestImplem, self).__init__(*args) self.data = list(args) @with_signature(autoclass("java.util.Iterator"), []) def iterator(self): - it = TestImplemIterator(self) + it = _TestImplemIterator(self) return it @with_signature(JString, []) @@ -90,14 +90,14 @@ def toArray(self): @with_signature(JListIterator, []) def listIterator(self): - it = TestImplemIterator(self) + it = _TestImplemIterator(self) return it # TODO cover this case of listIterator. @java_method(signature(JListIterator, [jint]), name='ListIterator') def listIteratorI(self, index): - it = TestImplemIterator(self, index) + it = _TestImplemIterator(self, index) return it @@ -107,7 +107,7 @@ class SignaturesTest(unittest.TestCase): def test_construct_stack_from_testimplem(self): Stack = autoclass("java.util.Stack") - pyjlist = TestImplem(1, 2, 3, 4, 5, 6, 7) + pyjlist = _TestImplem(1, 2, 3, 4, 5, 6, 7) stack = Stack() stack.addAll(pyjlist) self.assertEquals(7, pyjlist.size())