Skip to content

Commit 572854e

Browse files
committed
Split coverage.rst into restored CPython and Jython versions.
Speak distinctly about Jython in a coherent section. Keep (and update) the CPython story exactly as that project tells it.
1 parent fb6988e commit 572854e

File tree

3 files changed

+134
-35
lines changed

3 files changed

+134
-35
lines changed

coverage.rst

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,8 @@
1-
.. This file is derived from a file of the same name in the CPython devguide
2-
and will receive updates from the CPython guide by merging.
3-
41
.. _coverage:
52

6-
73
Increase Test Coverage
84
======================
95

10-
Jython adopts the Python Standard Library practically wholesale.
11-
Its quality is taken care of almost entirely by the CPython project,
12-
while Jython tries to minimise the amount of Jython-specific code either
13-
in the standard library and our tests,
14-
or added to the Jython code base to supersede standard modules.
15-
Improvements to the library and its test coverage may emerge from Jython,
16-
but the strategy requires they be contributes upstream to CPython.
17-
18-
.. note:: A lot of this section is identical to the CPython guide and not
19-
validated in a Jython context. The section on C is not relevant to Java,
20-
and we need to write one that is.
21-
22-
.. In the 2017 revision, scoring for C-specific content suggested we create a
23-
coverage_jy companion file.
24-
25-
266
Python development follows a practice that all semantic changes and additions
277
to the language and :abbr:`stdlib (standard library)` are accompanied by
288
appropriate unit tests. Unfortunately Python was in existence for a long time
@@ -262,20 +242,11 @@ times.
262242
Filing the Issue
263243
""""""""""""""""
264244
Once you have increased coverage, you need to create an issue on the
265-
`Jython issue tracker`_ and submit a :doc:`pull request or patch <pullrequest>`.
266-
On the issue set the "Components" to "Test" and "Versions" to the version of
267-
Jython you worked on (i.e., the in-development version).
268-
269-
.. _Jython issue tracker: http://bugs.jython.org
270-
271-
272-
273-
Measuring coverage of Java code
274-
"""""""""""""""""""""""""""""""
275-
276-
TODO
277-
245+
`issue tracker`_ and submit a :doc:`pull request <pullrequest>`. On the
246+
issue set the "Components" to "Test" and "Versions" to the version of Python you
247+
worked on (i.e., the in-development version).
278248

249+
.. _issue tracker: https://bugs.python.org
279250

280251

281252
Measuring coverage of C code with gcov and lcov
@@ -307,5 +278,3 @@ about 20 to 30 minutes on a modern computer.
307278

308279
.. _gcov: http://gcc.gnu.org/onlinedocs/gcc/Gcov.html
309280
.. _lcov: http://ltp.sourceforge.net/coverage/lcov.php
310-
311-

coverage_jy.rst

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
.. Jython companion to coverage.rst
2+
3+
.. _coverage-jy:
4+
5+
Test Coverage in Jython
6+
=======================
7+
8+
In broad groups, we have three things to test:
9+
10+
#. The Python Standard Library modules implemented in Python,
11+
#. The Java implementation of modules in the Standard Library, and
12+
#. The core of Jython implemented in Java.
13+
14+
In each case, Jython relies heavily on the tests provided by the CPython
15+
reference implementation.
16+
17+
Jython adopts the Python Standard Library wholesale, and
18+
its quality is assured by the CPython project.
19+
Jython makes some small changes to its copy
20+
to replace or add to tests and library modules.
21+
We aim to minimise the Jython-specific code in both the
22+
standard library and our tests.
23+
24+
Python development follows the practice that all semantic changes and additions
25+
to the language and :abbr:`stdlib (standard library)` are accompanied by
26+
appropriate unit tests.
27+
This is the aim of ensuring sufficient :doc:`test coverage <coverage>`.
28+
To the extent that CPython achieves this, a large part of Jython developement
29+
may be driven by these freely provided tests.
30+
31+
Improvements to the library and its test coverage may emerge from Jython,
32+
but the strategy depends on contributing them
33+
:doc:`upstream to CPython <coverage>`.
34+
35+
.. _coverage-by-regrtest-jy:
36+
37+
38+
Test Coverage Challenges
39+
------------------------
40+
41+
There are places where Jython cannot depend on tests provided by CPython:
42+
43+
#. Java integration (calling and being called by Java).
44+
#. Concurrency (where CPython's :abbr:`GIL (Global Interpreter Lock)` saves it
45+
but not Jython).
46+
#. Tests dependent on garbage collection (sometimes inadvertently).
47+
#. Tests that expose implementation details that differ.
48+
49+
For these cases we create tests in Python (to supersede or supplement the
50+
ones in the CPython :mod:`test` module) and tests in Java.
51+
52+
53+
Java Integration
54+
''''''''''''''''
55+
56+
Java integration is unique to Jython, so we must have our own tests.
57+
Where possible, tests should be in Python, using :mod:`unittest`.
58+
Where tests have to be in Java, we recommend the JUnit_ framework.
59+
60+
61+
Concurrency
62+
'''''''''''
63+
64+
The JVM has strong support for concurrency.
65+
There are many constructs in the Java library to support concurrency,
66+
which may be used directly from Python.
67+
68+
Python also has support for concurrency, and a rich library,
69+
but in the CPython interpreter,
70+
only one thread may be executing CPython bytecode at a time.
71+
Concurrency is limited to releasing the global lock during blocking operations
72+
such as i/o.
73+
If a task is CPU-bound,
74+
one must use multiple CPython interpreters in order to scale it.
75+
76+
By contrast, the JVM may switch threads at any time,
77+
part-way through what in CPython would be an atomic operation.
78+
(JVM instructions may be atomic, but this barely helps us at all.)
79+
Re-use or translation of implementations used in CPython needs to bear this
80+
difference in mind, and additional tests are likely to be necessary to
81+
assure us of correctness.
82+
83+
Some Jython applications will run in an environments with high concurrency,
84+
and Java thread pools (such as a web-service),
85+
where faulty concurrency is more likely to be exposed than in typical uses of
86+
CPython.
87+
88+
89+
Garbage Collection
90+
''''''''''''''''''
91+
92+
Many older tests create objects they assume are garbage-collected immediately
93+
they go out of scope.
94+
Examples:
95+
96+
* Files assumed closed as soon as dereferenced.
97+
* The timing of weak reference invalidation.
98+
99+
These tests may need adaptation to Java.
100+
There is no way to force garbage collection in Java, only to "suggest" it.
101+
Tests that open files are a particular problem on Windows,
102+
where files that remain open when they pass out of scope,
103+
cannot be deleted.
104+
105+
106+
Jython Internals
107+
''''''''''''''''
108+
109+
Tests of internal methods not accessible to Python are necessarily in Java,
110+
usually as JUnit_ tests.
111+
Examples:
112+
113+
* The buffer interface.
114+
* Type exposure.
115+
116+
117+
Filing the Issue
118+
----------------
119+
120+
Once you have increased coverage, you need to create an issue on the
121+
`Jython issue tracker`_ and a patch there.
122+
(In the future process, you will probably submit a
123+
:doc:`pull request <pullrequest>`.)
124+
On the issue set the "Components" to "Test" and "Versions" to the version of
125+
Jython you worked on (i.e., the in-development version).
126+
127+
.. _Jython issue tracker: http://bugs.jython.org
128+
.. _Junit: http://junit.org
129+

index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ Full Table of Contents
319319
patch_hg_jy
320320
pullrequest
321321
runtests
322+
coverage_jy
322323
docquality
323324
documenting
324325
silencewarnings

0 commit comments

Comments
 (0)