Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b344dd0

Browse files
committed
Merged revisions 86236,86240,86332,86340,87271,87273,87447 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k The missing NEWS entries correspond to changes that were made before 3.1.3, but I think it’s not usual to edit entries of released versions, so I put them at the top. ........ r86236 | eric.araujo | 2010-11-06 03:44:43 +0100 (sam., 06 nov. 2010) | 2 lines Make sure each test can be run standalone (./python Lib/distutils/tests/x.py) ........ r86240 | eric.araujo | 2010-11-06 05:11:59 +0100 (sam., 06 nov. 2010) | 2 lines Prevent ResourceWarnings in test_gettext ........ r86332 | eric.araujo | 2010-11-08 19:15:17 +0100 (lun., 08 nov. 2010) | 4 lines Add missing NEWS entry for a fix committed by Senthil. All recent modifications to distutils should now be covered in NEWS. ........ r86340 | eric.araujo | 2010-11-08 22:48:23 +0100 (lun., 08 nov. 2010) | 2 lines This was actually fixed for the previous alpha. ........ r87271 | eric.araujo | 2010-12-15 20:09:58 +0100 (mer., 15 déc. 2010) | 2 lines Improve trace documentation (#9264). Patch by Eli Bendersky. ........ r87273 | eric.araujo | 2010-12-15 20:30:15 +0100 (mer., 15 déc. 2010) | 2 lines Use nested method directives, rewrap long lines, fix whitespace. ........ r87447 | eric.araujo | 2010-12-23 20:13:05 +0100 (jeu., 23 déc. 2010) | 2 lines Fix typo in superclass method name ........
1 parent 6554887 commit b344dd0

42 files changed

Lines changed: 231 additions & 135 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Doc/library/trace.rst

Lines changed: 133 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -13,103 +13,178 @@ or from the command line.
1313

1414
.. _trace-cli:
1515

16-
Command Line Usage
16+
Command-Line Usage
1717
------------------
1818

1919
The :mod:`trace` module can be invoked from the command line. It can be as
2020
simple as ::
2121

22-
python -m trace --count somefile.py ...
22+
python -m trace --count -C . somefile.py ...
2323

24-
The above will generate annotated listings of all Python modules imported during
25-
the execution of :file:`somefile.py`.
24+
The above will execute :file:`somefile.py` and generate annotated listings of
25+
all Python modules imported during the execution into the current directory.
2626

27-
The following command-line arguments are supported:
27+
.. program:: trace
28+
29+
.. cmdoption:: --help
30+
31+
Display usage and exit.
32+
33+
.. cmdoption:: --version
34+
35+
Display the version of the module and exit.
36+
37+
Main options
38+
^^^^^^^^^^^^
39+
40+
At least one of the following options must be specified when invoking
41+
:mod:`trace`. The :option:`--listfuncs <-l>` option is mutually exclusive with
42+
the :option:`--trace <-t>` and :option:`--counts <-c>` options . When
43+
:option:`--listfuncs <-l>` is provided, neither :option:`--counts <-c>` nor
44+
:option:`--trace <-t>` are accepted, and vice versa.
45+
46+
.. program:: trace
47+
48+
.. cmdoption:: -c, --count
49+
50+
Produce a set of annotated listing files upon program completion that shows
51+
how many times each statement was executed. See also
52+
:option:`--coverdir <-C>`, :option:`--file <-f>` and
53+
:option:`--no-report <-R>` below.
54+
55+
.. cmdoption:: -t, --trace
2856

29-
:option:`--trace`, :option:`-t`
3057
Display lines as they are executed.
3158

32-
:option:`--count`, :option:`-c`
33-
Produce a set of annotated listing files upon program completion that shows how
34-
many times each statement was executed.
59+
.. cmdoption:: -l, --listfuncs
60+
61+
Display the functions executed by running the program.
62+
63+
.. cmdoption:: -r, --report
3564

36-
:option:`--report`, :option:`-r`
3765
Produce an annotated list from an earlier program run that used the
38-
:option:`--count` and :option:`--file` arguments.
66+
:option:`--count <-c>` and :option:`--file <-f>` option. This does not
67+
execute any code.
3968

40-
:option:`--no-report`, :option:`-R`
41-
Do not generate annotated listings. This is useful if you intend to make
42-
several runs with :option:`--count` then produce a single set of annotated
43-
listings at the end.
69+
.. cmdoption:: -T, --trackcalls
70+
71+
Display the calling relationships exposed by running the program.
72+
73+
Modifiers
74+
^^^^^^^^^
75+
76+
.. program:: trace
4477

45-
:option:`--listfuncs`, :option:`-l`
46-
List the functions executed by running the program.
78+
.. cmdoption:: -f, --file=<file>
4779

48-
:option:`--trackcalls`, :option:`-T`
49-
Generate calling relationships exposed by running the program.
80+
Name of a file to accumulate counts over several tracing runs. Should be
81+
used with the :option:`--count <-c>` option.
5082

51-
:option:`--file`, :option:`-f`
52-
Name a file containing (or to contain) counts.
83+
.. cmdoption:: -C, --coverdir=<dir>
5384

54-
:option:`--coverdir`, :option:`-C`
55-
Name a directory in which to save annotated listing files.
85+
Directory where the report files go. The coverage report for
86+
``package.module`` is written to file :file:`{dir}/{package}/{module}.cover`.
87+
88+
.. cmdoption:: -m, --missing
5689

57-
:option:`--missing`, :option:`-m`
5890
When generating annotated listings, mark lines which were not executed with
59-
'``>>>>>>``'.
91+
``>>>>>>``.
92+
93+
.. cmdoption:: -s, --summary
94+
95+
When using :option:`--count <-c>` or :option:`--report <-r>`, write a brief
96+
summary to stdout for each file processed.
97+
98+
.. cmdoption:: -R, --no-report
99+
100+
Do not generate annotated listings. This is useful if you intend to make
101+
several runs with :option:`--count <-c>`, and then produce a single set of
102+
annotated listings at the end.
103+
104+
.. cmdoption:: -g, --timing
105+
106+
Prefix each line with the time since the program started. Only used while
107+
tracing.
60108

61-
:option:`--summary`, :option:`-s`
62-
When using :option:`--count` or :option:`--report`, write a brief summary to
63-
stdout for each file processed.
109+
Filters
110+
^^^^^^^
64111

65-
:option:`--ignore-module`
66-
Accepts comma separated list of module names. Ignore each of the named
67-
module and its submodules (if it is a package). May be given
68-
multiple times.
112+
These options may be repeated multiple times.
69113

70-
:option:`--ignore-dir`
71-
Ignore all modules and packages in the named directory and subdirectories
72-
(multiple directories can be joined by os.pathsep). May be given multiple
73-
times.
114+
.. program:: trace
74115

116+
.. cmdoption:: --ignore-module=<mod>
117+
118+
Ignore each of the given module names and its submodules (if it is a
119+
package). The argument can be a list of names separated by a comma.
120+
121+
.. cmdoption:: --ignore-dir=<dir>
122+
123+
Ignore all modules and packages in the named directory and subdirectories.
124+
The argument can be a list of directories separated by :data:`os.pathsep`.
75125

76126
.. _trace-api:
77127

78-
Programming Interface
79-
---------------------
128+
Programmatic Interface
129+
----------------------
130+
131+
.. class:: Trace(count=1, trace=1, countfuncs=0, countcallers=0, ignoremods=(),\
132+
ignoredirs=(), infile=None, outfile=None, timing=False)
133+
134+
Create an object to trace execution of a single statement or expression. All
135+
parameters are optional. *count* enables counting of line numbers. *trace*
136+
enables line execution tracing. *countfuncs* enables listing of the
137+
functions called during the run. *countcallers* enables call relationship
138+
tracking. *ignoremods* is a list of modules or packages to ignore.
139+
*ignoredirs* is a list of directories whose modules or packages should be
140+
ignored. *infile* is the name of the file from which to read stored count
141+
information. *outfile* is the name of the file in which to write updated
142+
count information. *timing* enables a timestamp relative to when tracing was
143+
started to be displayed.
144+
145+
.. method:: run(cmd)
146+
147+
Execute the command and gather statistics from the execution with
148+
the current tracing parameters. *cmd* must be a string or code object,
149+
suitable for passing into :func:`exec`.
80150

151+
.. method:: runctx(cmd, globals=None, locals=None)
81152

82-
.. class:: Trace(count=1, trace=1, countfuncs=0, countcallers=0, ignoremods=(), ignoredirs=(), infile=None, outfile=None, timing=False)
153+
Execute the command and gather statistics from the execution with the
154+
current tracing parameters, in the defined global and local
155+
environments. If not defined, *globals* and *locals* default to empty
156+
dictionaries.
83157

84-
Create an object to trace execution of a single statement or expression. All
85-
parameters are optional. *count* enables counting of line numbers. *trace*
86-
enables line execution tracing. *countfuncs* enables listing of the functions
87-
called during the run. *countcallers* enables call relationship tracking.
88-
*ignoremods* is a list of modules or packages to ignore. *ignoredirs* is a list
89-
of directories whose modules or packages should be ignored. *infile* is the
90-
file from which to read stored count information. *outfile* is a file in which
91-
to write updated count information. *timing* enables a timestamp relative
92-
to when tracing was started to be displayed.
158+
.. method:: runfunc(func, *args, **kwds)
93159

160+
Call *func* with the given arguments under control of the :class:`Trace`
161+
object with the current tracing parameters.
94162

95-
.. method:: Trace.run(cmd)
163+
.. method:: results()
96164

97-
Run *cmd* under control of the Trace object with the current tracing parameters.
165+
Return a :class:`CoverageResults` object that contains the cumulative
166+
results of all previous calls to ``run``, ``runctx`` and ``runfunc``
167+
for the given :class:`Trace` instance. Does not reset the accumulated
168+
trace results.
98169

170+
.. class:: CoverageResults
99171

100-
.. method:: Trace.runctx(cmd, globals=None, locals=None)
172+
A container for coverage results, created by :meth:`Trace.results`. Should
173+
not be created directly by the user.
101174

102-
Run *cmd* under control of the Trace object with the current tracing parameters
103-
in the defined global and local environments. If not defined, *globals* and
104-
*locals* default to empty dictionaries.
175+
.. method:: update(other)
105176

177+
Merge in data from another :class:`CoverageResults` object.
106178

107-
.. method:: Trace.runfunc(func, *args, **kwds)
179+
.. method:: write_results(show_missing=True, summary=False, coverdir=None)
108180

109-
Call *func* with the given arguments under control of the :class:`Trace` object
110-
with the current tracing parameters.
181+
Write coverage results. Set *show_missing* to show lines that had no
182+
hits. Set *summary* to include in the output the coverage summary per
183+
module. *coverdir* specifies the directory into which the coverage
184+
result files will be output. If ``None``, the results for each source
185+
file are placed in its directory.
111186

112-
This is a simple example showing the use of this module::
187+
A simple example demonstrating the use of the programmatic interface::
113188

114189
import sys
115190
import trace

Lib/distutils/tests/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
import os
1616
import sys
1717
import unittest
18+
from test.support import run_unittest
1819

1920

20-
here = os.path.dirname(__file__)
21+
here = os.path.dirname(__file__) or os.curdir
2122

2223

2324
def test_suite():
@@ -32,4 +33,4 @@ def test_suite():
3233

3334

3435
if __name__ == "__main__":
35-
unittest.main(defaultTest="test_suite")
36+
run_unittest(test_suite())

Lib/distutils/tests/test_archive_util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
ARCHIVE_FORMATS)
1313
from distutils.spawn import find_executable, spawn
1414
from distutils.tests import support
15-
from test.support import check_warnings
15+
from test.support import check_warnings, run_unittest
1616

1717
try:
1818
import zipfile
@@ -211,4 +211,4 @@ def test_suite():
211211
return unittest.makeSuite(ArchiveUtilTestCase)
212212

213213
if __name__ == "__main__":
214-
unittest.main(defaultTest="test_suite")
214+
run_unittest(test_suite())

Lib/distutils/tests/test_bdist.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import tempfile
66
import shutil
7+
from test.support import run_unittest
78

89
from distutils.core import Distribution
910
from distutils.command.bdist import bdist
@@ -40,4 +41,4 @@ def test_suite():
4041
return unittest.makeSuite(BuildTestCase)
4142

4243
if __name__ == '__main__':
43-
test_support.run_unittest(test_suite())
44+
run_unittest(test_suite())

Lib/distutils/tests/test_bdist_dumb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import unittest
44
import sys
55
import os
6+
from test.support import run_unittest
67

78
from distutils.core import Distribution
89
from distutils.command.bdist_dumb import bdist_dumb
@@ -77,4 +78,4 @@ def test_suite():
7778
return unittest.makeSuite(BuildDumbTestCase)
7879

7980
if __name__ == '__main__':
80-
test_support.run_unittest(test_suite())
81+
run_unittest(test_suite())

Lib/distutils/tests/test_bdist_rpm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import tempfile
77
import shutil
8+
from test.support import run_unittest
89

910
from distutils.core import Distribution
1011
from distutils.command.bdist_rpm import bdist_rpm
@@ -122,4 +123,4 @@ def test_suite():
122123
return unittest.makeSuite(BuildRpmTestCase)
123124

124125
if __name__ == '__main__':
125-
test_support.run_unittest(test_suite())
126+
run_unittest(test_suite())

Lib/distutils/tests/test_bdist_wininst.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for distutils.command.bdist_wininst."""
22
import unittest
3+
from test.support import run_unittest
34

45
from distutils.command.bdist_wininst import bdist_wininst
56
from distutils.tests import support
@@ -27,4 +28,4 @@ def test_suite():
2728
return unittest.makeSuite(BuildWinInstTestCase)
2829

2930
if __name__ == '__main__':
30-
test_support.run_unittest(test_suite())
31+
run_unittest(test_suite())

Lib/distutils/tests/test_build_clib.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import os
44
import sys
55

6+
from test.support import run_unittest
7+
68
from distutils.command.build_clib import build_clib
79
from distutils.errors import DistutilsSetupError
810
from distutils.tests import support
@@ -141,4 +143,4 @@ def test_suite():
141143
return unittest.makeSuite(BuildCLibTestCase)
142144

143145
if __name__ == "__main__":
144-
unittest.main(defaultTest="test_suite")
146+
run_unittest(test_suite())

Lib/distutils/tests/test_build_ext.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import unittest
1717
from test import support
18+
from test.support import run_unittest
1819

1920
# http://bugs.python.org/issue4373
2021
# Don't load the xx module more than once.

Lib/distutils/tests/test_build_py.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from distutils.errors import DistutilsFileError
1111

1212
from distutils.tests import support
13+
from test.support import run_unittest
1314

1415

1516
class BuildPyTestCase(support.TempdirManager,
@@ -114,4 +115,4 @@ def test_suite():
114115
return unittest.makeSuite(BuildPyTestCase)
115116

116117
if __name__ == "__main__":
117-
unittest.main(defaultTest="test_suite")
118+
run_unittest(test_suite())

0 commit comments

Comments
 (0)