From 9c8f90d69a8fc5b9712528e49254a3e9bdce4c34 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 17 Nov 2012 23:32:01 -0500 Subject: Add tests and docs to the kit, though they are not installed. #137 --HG-- rename : doc/branches.py => lab/branches.py --- CHANGES.txt | 3 +++ MANIFEST.in | 6 ++++- Makefile | 4 +-- doc/branches.py | 78 --------------------------------------------------------- lab/branches.py | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ switchpy.cmd | 14 ----------- 6 files changed, 88 insertions(+), 95 deletions(-) delete mode 100644 doc/branches.py create mode 100644 lab/branches.py delete mode 100644 switchpy.cmd diff --git a/CHANGES.txt b/CHANGES.txt index 95274785..e129a910 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -37,6 +37,8 @@ Version 3.6b1 Distribute. You must have one of them installed first, as `issue 202` recommended. +- The coverage.py kit now includes docs (closing `issue 137`) and tests. + - On Windows, files are now reported in their correct case, fixing `issue 89`_ and `issue 203`_. @@ -63,6 +65,7 @@ Version 3.6b1 .. _issue 89: https://bitbucket.org/ned/coveragepy/issue/89/on-windows-all-packages-are-reported-in .. _issue 111: https://bitbucket.org/ned/coveragepy/issue/111/when-installing-coverage-with-pip-not +.. _issue 137: https://bitbucket.org/ned/coveragepy/issue/137/provide-docs-with-source-distribution .. _issue 139: https://bitbucket.org/ned/coveragepy/issue/139/easy-check-for-a-certain-coverage-in-tests .. _issue 143: https://bitbucket.org/ned/coveragepy/issue/143/omit-doesnt-seem-to-work-in-coverage .. _issue 153: https://bitbucket.org/ned/coveragepy/issue/153/non-existent-filename-triggers diff --git a/MANIFEST.in b/MANIFEST.in index 7bb26ac0..0150d90e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -7,6 +7,10 @@ include setup.py include README.txt include CHANGES.txt include AUTHORS.txt +include requirements.txt +include igor.py +include tox.ini -prune test +recursive-include test * +recursive-include doc *.rst global-exclude *.pyc diff --git a/Makefile b/Makefile index 3e921862..2c87f004 100644 --- a/Makefile +++ b/Makefile @@ -22,10 +22,10 @@ clean: -rm -f $(TEST_ZIP) -rm -rf test/eggsrc/build test/eggsrc/dist test/eggsrc/*.egg-info -rm -f setuptools-*.egg distribute-*.egg distribute-*.tar.gz - -rm -rf doc/_build/* + -rm -rf doc/_build sterile: clean - -rm -rf .tox .tox_kits + -rm -rf .tox* LINTABLE = coverage setup.py test diff --git a/doc/branches.py b/doc/branches.py deleted file mode 100644 index 1fa705f0..00000000 --- a/doc/branches.py +++ /dev/null @@ -1,78 +0,0 @@ -# Demonstrate some issues with coverage.py branch testing. - -def my_function(x): - """This isn't real code, just snippets...""" - - # An infinite loop is structurally still a branch: it can next execute the - # first line of the loop, or the first line after the loop. But - # "while True" will never jump to the line after the loop, so the line - # is shown as a partial branch: - - i = 0 - while True: - print "In while True" - if i > 0: - break - i += 1 - print "Left the True loop" - - # Notice that "while 1" also has this problem. Even though the compiler - # knows there's no computation at the top of the loop, it's still expressed - # in byte code as a branch with two possibilities. - - i = 0 - while 1: - print "In while 1" - if i > 0: - break - i += 1 - print "Left the 1 loop" - - # Coverage.py lets the developer exclude lines that he knows will not be - # executed. So far, the branch coverage doesn't use all that information - # when deciding which lines are partially executed. - # - # Here, even though the else line is explicitly marked as never executed, - # the if line complains that it never branched to the else: - - if x < 1000: - # This branch is always taken - print "x is reasonable" - else: # pragma: nocover - print "this never happens" - - # try-except structures are complex branches. An except clause with a - # type is a three-way branch: there could be no exception, there could be - # a matching exception, and there could be a non-matching exception. - # - # Here we run the code twice: once with no exception, and once with a - # matching exception. The "except" line is marked as partial because we - # never executed its third case: a non-matching exception. - - for y in (1, 2): - try: - if y % 2: - raise ValueError("y is odd!") - except ValueError: - print "y must have been odd" - print "done with y" - print "done with 1, 2" - - # Another except clause, but this time all three cases are executed. No - # partial lines are shown: - - for y in (0, 1, 2): - try: - if y % 2: - raise ValueError("y is odd!") - if y == 0: - raise Exception("zero!") - except ValueError: - print "y must have been odd" - except: - print "y is something else" - print "done with y" - print "done with 0, 1, 2" - - -my_function(1) diff --git a/lab/branches.py b/lab/branches.py new file mode 100644 index 00000000..1fa705f0 --- /dev/null +++ b/lab/branches.py @@ -0,0 +1,78 @@ +# Demonstrate some issues with coverage.py branch testing. + +def my_function(x): + """This isn't real code, just snippets...""" + + # An infinite loop is structurally still a branch: it can next execute the + # first line of the loop, or the first line after the loop. But + # "while True" will never jump to the line after the loop, so the line + # is shown as a partial branch: + + i = 0 + while True: + print "In while True" + if i > 0: + break + i += 1 + print "Left the True loop" + + # Notice that "while 1" also has this problem. Even though the compiler + # knows there's no computation at the top of the loop, it's still expressed + # in byte code as a branch with two possibilities. + + i = 0 + while 1: + print "In while 1" + if i > 0: + break + i += 1 + print "Left the 1 loop" + + # Coverage.py lets the developer exclude lines that he knows will not be + # executed. So far, the branch coverage doesn't use all that information + # when deciding which lines are partially executed. + # + # Here, even though the else line is explicitly marked as never executed, + # the if line complains that it never branched to the else: + + if x < 1000: + # This branch is always taken + print "x is reasonable" + else: # pragma: nocover + print "this never happens" + + # try-except structures are complex branches. An except clause with a + # type is a three-way branch: there could be no exception, there could be + # a matching exception, and there could be a non-matching exception. + # + # Here we run the code twice: once with no exception, and once with a + # matching exception. The "except" line is marked as partial because we + # never executed its third case: a non-matching exception. + + for y in (1, 2): + try: + if y % 2: + raise ValueError("y is odd!") + except ValueError: + print "y must have been odd" + print "done with y" + print "done with 1, 2" + + # Another except clause, but this time all three cases are executed. No + # partial lines are shown: + + for y in (0, 1, 2): + try: + if y % 2: + raise ValueError("y is odd!") + if y == 0: + raise Exception("zero!") + except ValueError: + print "y must have been odd" + except: + print "y is something else" + print "done with y" + print "done with 0, 1, 2" + + +my_function(1) diff --git a/switchpy.cmd b/switchpy.cmd deleted file mode 100644 index 089df2a5..00000000 --- a/switchpy.cmd +++ /dev/null @@ -1,14 +0,0 @@ -@echo off -set PATH=.;%HOME%\bin -set PATH=%PATH%;c:\windows\system32;c:\windows -set PATH=%PATH%;%1\scripts;%1 -set PATH=%PATH%;C:\Program Files\Mercurial\bin -set PATH=%PATH%;c:\cygwin\bin -set PATH=%PATH%;c:\app\MinGW\bin -set PYTHONPATH=;c:\ned\py -set PYHOME=%1 -rem title Py %1 -if "%2"=="quiet" goto done -python -c "import sys; print ('\n=== Python %%s %%s' %% (sys.version.split()[0], '='*80))" - -:done -- cgit v1.2.1