Skip to content

Commit 38c8fde

Browse files
committed
Merge branch 'master' of https://github.com/python/cpython into blurb-split-master
2 parents b5ae220 + 49f6449 commit 38c8fde

File tree

5 files changed

+71
-2
lines changed

5 files changed

+71
-2
lines changed

Doc/tools/extensions/pyspecific.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from time import asctime
1616
from pprint import pformat
1717
from docutils.io import StringOutput
18+
from docutils.parsers.rst import Directive
1819
from docutils.utils import new_document
1920

2021
from docutils import nodes, utils
@@ -23,7 +24,6 @@
2324
from sphinx.builders import Builder
2425
from sphinx.locale import translators
2526
from sphinx.util.nodes import split_explicit_title
26-
from sphinx.util.compat import Directive
2727
from sphinx.writers.html import HTMLTranslator
2828
from sphinx.writers.text import TextWriter
2929
from sphinx.writers.latex import LaTeXTranslator

Lib/idlelib/idle_test/README.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,59 @@ complete, though some tests need improvement. To run all htests, run the
159159
htest file from an editor or from the command line with:
160160

161161
python -m idlelib.idle_test.htest
162+
163+
164+
5. Test Coverage
165+
166+
Install the coverage package into your Python 3.6 site-packages
167+
directory. (Its exact location depends on the OS).
168+
> python3 -m pip install coverage
169+
(On Windows, replace 'python3 with 'py -3.6' or perhaps just 'python'.)
170+
171+
The problem with running coverage with repository python is that
172+
coverage uses absolute imports for its submodules, hence it needs to be
173+
in a directory in sys.path. One solution: copy the package to the
174+
directory containing the cpython repository. Call it 'dev'. Then run
175+
coverage either directly or from a script in that directory so that
176+
'dev' is prepended to sys.path.
177+
178+
Either edit or add dev/.coveragerc so it looks something like this.
179+
---
180+
# .coveragerc sets coverage options.
181+
[run]
182+
branch = True
183+
184+
[report]
185+
# Regexes for lines to exclude from consideration
186+
exclude_lines =
187+
# Don't complain if non-runnable code isn't run:
188+
if 0:
189+
if __name__ == .__main__.:
190+
191+
.*# htest #
192+
if not _utest:
193+
if _htest:
194+
---
195+
The additions for IDLE are 'branch = True', to test coverage both ways,
196+
and the last three exclude lines, to exclude things peculiar to IDLE
197+
that are not executed during tests.
198+
199+
A script like the following cover.bat (for Windows) is very handy.
200+
---
201+
@echo off
202+
rem Usage: cover filename [test_ suffix] # proper case required by coverage
203+
rem filename without .py, 2nd parameter if test is not test_filename
204+
setlocal
205+
set py=f:\dev\3x\pcbuild\win32\python_d.exe
206+
set src=idlelib.%1
207+
if "%2" EQU "" set tst=f:/dev/3x/Lib/idlelib/idle_test/test_%1.py
208+
if "%2" NEQ "" set tst=f:/dev/ex/Lib/idlelib/idle_test/test_%2.py
209+
210+
%py% -m coverage run --pylib --source=%src% %tst%
211+
%py% -m coverage report --show-missing
212+
%py% -m coverage html
213+
start htmlcov\3x_Lib_idlelib_%1_py.html
214+
rem Above opens new report; htmlcov\index.html displays report index
215+
---
216+
The second parameter was added for tests of module x not named test_x.
217+
(There were several before modules were renamed, now only one is left.)

Lib/test/test_json/test_speedups.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ def test(name):
4444
self.assertRaises(ZeroDivisionError, test, 'check_circular')
4545
self.assertRaises(ZeroDivisionError, test, 'allow_nan')
4646
self.assertRaises(ZeroDivisionError, test, 'sort_keys')
47+
48+
def test_unsortable_keys(self):
49+
with self.assertRaises(TypeError):
50+
self.json.encoder.JSONEncoder(sort_keys=True).encode({'a': 1, 1: 'a'})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Document coverage details for idlelib tests.
2+
3+
* Add section to idlelib/idle-test/README.txt.
4+
5+
* Include check that branches are taken both ways.
6+
7+
* Exclude IDLE-specific code that does not run during unit tests.

Modules/_json.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1589,8 +1589,10 @@ encoder_listencode_dict(PyEncoderObject *s, _PyAccu *acc,
15891589
items = PyMapping_Items(dct);
15901590
if (items == NULL)
15911591
goto bail;
1592-
if (s->sort_keys && PyList_Sort(items) < 0)
1592+
if (s->sort_keys && PyList_Sort(items) < 0) {
1593+
Py_DECREF(items);
15931594
goto bail;
1595+
}
15941596
it = PyObject_GetIter(items);
15951597
Py_DECREF(items);
15961598
if (it == NULL)

0 commit comments

Comments
 (0)