From 1113f2ae1c89e5faf90869f57d36f2ab552faeb3 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Fri, 14 Jul 2017 21:41:32 -0400 Subject: [PATCH 1/3] Document idlelib test coverage. --- Lib/idlelib/idle_test/README.txt | 52 ++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/Lib/idlelib/idle_test/README.txt b/Lib/idlelib/idle_test/README.txt index dc7a28697c1988..554b48c4f12bbc 100644 --- a/Lib/idlelib/idle_test/README.txt +++ b/Lib/idlelib/idle_test/README.txt @@ -159,3 +159,55 @@ complete, though some tests need improvement. To run all htests, run the htest file from an editor or from the command line with: python -m idlelib.idle_test.htest + + +5. Test Coverage + +(The following works for Windows. Adjust for other systems.) + +Install coverage package into py3.6/Lib/site-packages with +> py -3.6 -m pip install coverage +Problem with running coverage with repository python is that coverage +uses absolute imports for its submodules, hence needs to be in a +directory in sys.path. One solution: copy the package to the directory +containing the cpython repository. Call it 'dev' + +Add dev/.coveragerc containing something like the following: +--- +# .coveragerc sets coverage options. +[run] +branch = True + +[report] +# Regexes for lines to exclude from consideration +exclude_lines = + # Don't complain if non-runnable code isn't run: + if 0: + if __name__ == .__main__.: + + .*# htest # + if not _utest: + if _htest: +--- +The 'branch = True' and last three exclude lines are added. If file +exists already (coverage will create it), add these four lines. + +Optionally, add a script like the following: +--- +@echo off +rem Usage: cover filename [test_ suffix] # proper case required by coverage +rem filename without .py, 2nd parameter if test is not test_filename +setlocal +set py=f:\dev\3x\pcbuild\win32\python_d.exe +set src=idlelib.%1 +if "%2" EQU "" set tst=f:/dev/3x/Lib/idlelib/idle_test/test_%1.py +if "%2" NEQ "" set tst=f:/dev/ex/Lib/idlelib/idle_test/test_%2.py + +%py% -m coverage run --pylib --source=%src% %tst% +%py% -m coverage report --show-missing +%py% -m coverage html +start htmlcov\3x_Lib_idlelib_%1_py.html +rem Above opens new report; htmlcov\index.html displays report index +--- +The second parameter was needed for tests of module x not named test_x. +(There were several before modules were renamed, now only one.) \ No newline at end of file From 0377e4365d3038930c109b6848609e61b81bc1e0 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Fri, 14 Jul 2017 22:06:32 -0400 Subject: [PATCH 2/3] undo? --- Lib/idlelib/idle_test/README.txt | 52 -------------------------------- 1 file changed, 52 deletions(-) diff --git a/Lib/idlelib/idle_test/README.txt b/Lib/idlelib/idle_test/README.txt index 554b48c4f12bbc..dc7a28697c1988 100644 --- a/Lib/idlelib/idle_test/README.txt +++ b/Lib/idlelib/idle_test/README.txt @@ -159,55 +159,3 @@ complete, though some tests need improvement. To run all htests, run the htest file from an editor or from the command line with: python -m idlelib.idle_test.htest - - -5. Test Coverage - -(The following works for Windows. Adjust for other systems.) - -Install coverage package into py3.6/Lib/site-packages with -> py -3.6 -m pip install coverage -Problem with running coverage with repository python is that coverage -uses absolute imports for its submodules, hence needs to be in a -directory in sys.path. One solution: copy the package to the directory -containing the cpython repository. Call it 'dev' - -Add dev/.coveragerc containing something like the following: ---- -# .coveragerc sets coverage options. -[run] -branch = True - -[report] -# Regexes for lines to exclude from consideration -exclude_lines = - # Don't complain if non-runnable code isn't run: - if 0: - if __name__ == .__main__.: - - .*# htest # - if not _utest: - if _htest: ---- -The 'branch = True' and last three exclude lines are added. If file -exists already (coverage will create it), add these four lines. - -Optionally, add a script like the following: ---- -@echo off -rem Usage: cover filename [test_ suffix] # proper case required by coverage -rem filename without .py, 2nd parameter if test is not test_filename -setlocal -set py=f:\dev\3x\pcbuild\win32\python_d.exe -set src=idlelib.%1 -if "%2" EQU "" set tst=f:/dev/3x/Lib/idlelib/idle_test/test_%1.py -if "%2" NEQ "" set tst=f:/dev/ex/Lib/idlelib/idle_test/test_%2.py - -%py% -m coverage run --pylib --source=%src% %tst% -%py% -m coverage report --show-missing -%py% -m coverage html -start htmlcov\3x_Lib_idlelib_%1_py.html -rem Above opens new report; htmlcov\index.html displays report index ---- -The second parameter was needed for tests of module x not named test_x. -(There were several before modules were renamed, now only one.) \ No newline at end of file From cc11544c1cffc0bb48a7a032136e577ae3d00588 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Wed, 19 Jul 2017 20:23:58 -0400 Subject: [PATCH 3/3] bpo-30968: Fix test_get_font in IDLE's test_config. --- Lib/idlelib/idle_test/test_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/idlelib/idle_test/test_config.py b/Lib/idlelib/idle_test/test_config.py index 5f23c8d2f4075a..bbf06504fc2552 100644 --- a/Lib/idlelib/idle_test/test_config.py +++ b/Lib/idlelib/idle_test/test_config.py @@ -608,7 +608,7 @@ def test_get_font(self): f = Font.actual(Font(name='TkFixedFont', exists=True, root=root)) self.assertEqual( conf.GetFont(root, 'main', 'EditorWindow'), - (f['family'], 10 if f['size'] < 10 else f['size'], f['weight'])) + (f['family'], 10 if f['size'] <= 0 else f['size'], f['weight'])) # Cleanup root root.destroy()