mirror of
https://github.com/AdaCore/cpython.git
synced 2026-02-12 12:57:15 -08:00
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60568-60598,60600-60616 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r60568 | christian.heimes | 2008-02-04 19:48:38 +0100 (Mon, 04 Feb 2008) | 1 line Increase debugging to investige failing tests on some build bots ........ r60570 | christian.heimes | 2008-02-04 20:30:05 +0100 (Mon, 04 Feb 2008) | 1 line Small adjustments for test compact freelist test. It's no passing on Windows as well. ........ r60573 | amaury.forgeotdarc | 2008-02-04 21:53:14 +0100 (Mon, 04 Feb 2008) | 2 lines Correct quotes in NEWS file ........ r60575 | amaury.forgeotdarc | 2008-02-04 22:45:05 +0100 (Mon, 04 Feb 2008) | 13 lines #1750076: Debugger did not step on every iteration of a while statement. The mapping between bytecode offsets and source lines (lnotab) did not contain an entry for the beginning of the loop. Now it does, and the lnotab can be a bit larger: in particular, several statements on the same line generate several entries. However, this does not bother the settrace function, which will trigger only one 'line' event. The lnotab seems to be exactly the same as with python2.4. ........ r60584 | amaury.forgeotdarc | 2008-02-05 01:26:21 +0100 (Tue, 05 Feb 2008) | 3 lines Change r60575 broke test_compile: there is no need to emit co_lnotab item when both offsets are zeros. ........ r60587 | skip.montanaro | 2008-02-05 03:32:16 +0100 (Tue, 05 Feb 2008) | 1 line sync with most recent version from python-mode sf project ........ r60588 | lars.gustaebel | 2008-02-05 12:51:40 +0100 (Tue, 05 Feb 2008) | 5 lines Issue #2004: Use mode 0700 for temporary directories and default permissions for missing directories. (will backport to 2.5) ........ r60590 | georg.brandl | 2008-02-05 13:01:24 +0100 (Tue, 05 Feb 2008) | 2 lines Convert external links to internal links. Fixes #2010. ........ r60592 | marc-andre.lemburg | 2008-02-05 15:50:40 +0100 (Tue, 05 Feb 2008) | 3 lines Keep distutils Python 2.1 compatible (or even Python 2.4 in this case). ........ r60593 | andrew.kuchling | 2008-02-05 17:06:57 +0100 (Tue, 05 Feb 2008) | 5 lines Update PEP URL. (This code is duplicated between pydoc and DocXMLRPCServer; maybe it should be refactored as a GHOP project.) 2.5.2 backport candidate. ........ r60596 | guido.van.rossum | 2008-02-05 18:32:15 +0100 (Tue, 05 Feb 2008) | 2 lines In the experimental 'Scanner' feature, the group count was set wrong. ........ r60602 | facundo.batista | 2008-02-05 20:03:32 +0100 (Tue, 05 Feb 2008) | 3 lines Issue 1951. Converts wave test cases to unittest. ........ r60603 | georg.brandl | 2008-02-05 20:07:10 +0100 (Tue, 05 Feb 2008) | 2 lines Actually run the test. ........ r60604 | skip.montanaro | 2008-02-05 20:24:30 +0100 (Tue, 05 Feb 2008) | 2 lines correct object name ........ r60605 | georg.brandl | 2008-02-05 20:58:17 +0100 (Tue, 05 Feb 2008) | 7 lines * Use the same code to profile for test_profile and test_cprofile. * Convert both to unittest. * Use the same unit testing code. * Include the expected output in both test files. * Make it possible to regenerate the expected output by running the file as a script with an '-r' argument. ........ r60613 | raymond.hettinger | 2008-02-06 02:49:00 +0100 (Wed, 06 Feb 2008) | 1 line Sync-up with Py3k work. ........ r60614 | christian.heimes | 2008-02-06 13:44:34 +0100 (Wed, 06 Feb 2008) | 1 line Limit free list of method and builtin function objects to 256 entries each. ........ r60616 | christian.heimes | 2008-02-06 14:33:44 +0100 (Wed, 06 Feb 2008) | 7 lines Unified naming convention for free lists and their limits. All free lists in Object/ are named ``free_list``, the counter ``numfree`` and the upper limit is a macro ``PyName_MAXFREELIST`` inside an #ifndef block. The chances should make it easier to adjust Python for platforms with less memory, e.g. mobile phones. ........
This commit is contained in:
@@ -265,7 +265,7 @@ the organizations that use Python.
|
||||
**What are the restrictions on Python's use?**
|
||||
|
||||
They're practically nonexistent. Consult the :file:`Misc/COPYRIGHT` file in the
|
||||
source distribution, or http://www.python.org/doc/Copyright.html for the full
|
||||
source distribution, or the section :ref:`history-and-license` for the full
|
||||
language, but it boils down to three conditions.
|
||||
|
||||
* You have to leave the copyright notice on the software; if you don't include
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
.. _curses-howto:
|
||||
|
||||
**********************************
|
||||
Curses Programming with Python
|
||||
**********************************
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
.. _regex-howto:
|
||||
|
||||
****************************
|
||||
Regular Expression HOWTO
|
||||
****************************
|
||||
|
||||
@@ -276,7 +276,7 @@ Unicode result). The following examples show the differences::
|
||||
|
||||
Encodings are specified as strings containing the encoding's name. Python
|
||||
comes with roughly 100 different encodings; see the Python Library Reference at
|
||||
<http://docs.python.org/lib/standard-encodings.html> for a list. Some encodings
|
||||
:ref:`standard-encodings` for a list. Some encodings
|
||||
have multiple names; for example, 'latin-1', 'iso_8859_1' and '8859' are all
|
||||
synonyms for the same encoding.
|
||||
|
||||
|
||||
@@ -45,9 +45,9 @@ Linux and the BSD variants of Unix.
|
||||
Convenience function to ensure proper terminal setup and resetting on
|
||||
application entry and exit.
|
||||
|
||||
`Curses Programming with Python <http://www.python.org/doc/howto/curses/curses.html>`_
|
||||
:ref:`curses-howto`
|
||||
Tutorial material on using curses with Python, by Andrew Kuchling and Eric
|
||||
Raymond, is available on the Python Web site.
|
||||
Raymond.
|
||||
|
||||
The :file:`Demo/curses/` directory in the Python source distribution contains
|
||||
some example programs using the curses bindings provided by this module.
|
||||
|
||||
@@ -65,8 +65,7 @@ and implementation of regular expressions, consult the Friedl book referenced
|
||||
above, or almost any textbook about compiler construction.
|
||||
|
||||
A brief explanation of the format of regular expressions follows. For further
|
||||
information and a gentler presentation, consult the Regular Expression HOWTO,
|
||||
accessible from http://www.python.org/doc/howto/.
|
||||
information and a gentler presentation, consult the :ref:`regex-howto`.
|
||||
|
||||
Regular expressions can contain both special and ordinary characters. Most
|
||||
ordinary characters, like ``'A'``, ``'a'``, or ``'0'``, are the simplest regular
|
||||
|
||||
@@ -30,7 +30,7 @@ class ServerHTMLDoc(pydoc.HTMLDoc):
|
||||
results = []
|
||||
here = 0
|
||||
|
||||
# XXX Note that this regular expressions does not allow for the
|
||||
# XXX Note that this regular expression does not allow for the
|
||||
# hyperlinking of arbitrary strings being used as method
|
||||
# names. Only methods with names consisting of word characters
|
||||
# and '.'s are hyperlinked.
|
||||
@@ -52,7 +52,7 @@ class ServerHTMLDoc(pydoc.HTMLDoc):
|
||||
url = 'http://www.rfc-editor.org/rfc/rfc%d.txt' % int(rfc)
|
||||
results.append('<a href="%s">%s</a>' % (url, escape(all)))
|
||||
elif pep:
|
||||
url = 'http://www.python.org/peps/pep-%04d.html' % int(pep)
|
||||
url = 'http://www.python.org/dev/peps/pep-%04d/' % int(pep)
|
||||
results.append('<a href="%s">%s</a>' % (url, escape(all)))
|
||||
elif text[end:end+1] == '(':
|
||||
results.append(self.namelink(name, methods, funcs, classes))
|
||||
|
||||
@@ -385,6 +385,7 @@ class Mapping(metaclass=ABCMeta):
|
||||
def __ne__(self, other):
|
||||
return not (self == other)
|
||||
|
||||
|
||||
class MappingView(metaclass=ABCMeta):
|
||||
|
||||
def __init__(self, mapping):
|
||||
|
||||
@@ -37,8 +37,12 @@ if os.name == "nt" and "\\pc\\v" in project_base[-10:].lower():
|
||||
# different (hard-wired) directories.
|
||||
# Setup.local is available for Makefile builds including VPATH builds,
|
||||
# Setup.dist is available on Windows
|
||||
python_build = any(os.path.isfile(os.path.join(project_base, "Modules", fn))
|
||||
for fn in ("Setup.dist", "Setup.local"))
|
||||
def _python_build():
|
||||
for fn in ("Setup.dist", "Setup.local"):
|
||||
if os.path.isfile(os.path.join(project_base, "Modules", fn)):
|
||||
return True
|
||||
return False
|
||||
python_build = _python_build()
|
||||
|
||||
def get_python_version():
|
||||
"""Return a string containing the major and minor Python version,
|
||||
|
||||
@@ -536,7 +536,7 @@ class HTMLDoc(Doc):
|
||||
url = 'http://www.rfc-editor.org/rfc/rfc%d.txt' % int(rfc)
|
||||
results.append('<a href="%s">%s</a>' % (url, escape(all)))
|
||||
elif pep:
|
||||
url = 'http://www.python.org/peps/pep-%04d' % int(pep)
|
||||
url = 'http://www.python.org/dev/peps/pep-%04d/' % int(pep)
|
||||
results.append('<a href="%s">%s</a>' % (url, escape(all)))
|
||||
elif text[end:end+1] == '(':
|
||||
results.append(self.namelink(name, methods, funcs, classes))
|
||||
|
||||
@@ -294,8 +294,8 @@ class Scanner:
|
||||
p.append(sre_parse.SubPattern(s, [
|
||||
(SUBPATTERN, (len(p)+1, sre_parse.parse(phrase, flags))),
|
||||
]))
|
||||
s.groups = len(p)+1
|
||||
p = sre_parse.SubPattern(s, [(BRANCH, (None, p))])
|
||||
s.groups = len(p)
|
||||
self.scanner = sre_compile.compile(p)
|
||||
def scan(self, string):
|
||||
result = []
|
||||
|
||||
@@ -2005,15 +2005,11 @@ class TarFile(object):
|
||||
|
||||
for tarinfo in members:
|
||||
if tarinfo.isdir():
|
||||
# Extract directory with a safe mode, so that
|
||||
# all files below can be extracted as well.
|
||||
try:
|
||||
os.makedirs(os.path.join(path, tarinfo.name), 0o700)
|
||||
except EnvironmentError:
|
||||
pass
|
||||
# Extract directories with a safe mode.
|
||||
directories.append(tarinfo)
|
||||
else:
|
||||
self.extract(tarinfo, path)
|
||||
tarinfo = copy.copy(tarinfo)
|
||||
tarinfo.mode = 0o700
|
||||
self.extract(tarinfo, path)
|
||||
|
||||
# Reverse sort directories.
|
||||
directories.sort(key=lambda a: a.name)
|
||||
@@ -2118,6 +2114,8 @@ class TarFile(object):
|
||||
# Create all upper directories.
|
||||
upperdirs = os.path.dirname(targetpath)
|
||||
if upperdirs and not os.path.exists(upperdirs):
|
||||
# Create directories that are not part of the archive with
|
||||
# default permissions.
|
||||
os.makedirs(upperdirs)
|
||||
|
||||
if tarinfo.islnk() or tarinfo.issym():
|
||||
@@ -2154,7 +2152,9 @@ class TarFile(object):
|
||||
"""Make a directory called targetpath.
|
||||
"""
|
||||
try:
|
||||
os.mkdir(targetpath)
|
||||
# Use a safe mode for the directory, the real mode is set
|
||||
# later in _extract_member().
|
||||
os.mkdir(targetpath, 0o700)
|
||||
except EnvironmentError as e:
|
||||
if e.errno != errno.EEXIST:
|
||||
raise
|
||||
|
||||
@@ -1,97 +0,0 @@
|
||||
test_profile
|
||||
125 function calls (105 primitive calls) in 1.000 CPU seconds
|
||||
|
||||
Ordered by: standard name
|
||||
|
||||
ncalls tottime percall cumtime percall filename:lineno(function)
|
||||
4 0.000 0.000 0.000 0.000 :0(append)
|
||||
4 0.000 0.000 0.000 0.000 :0(exc_info)
|
||||
1 0.000 0.000 1.000 1.000 :0(exec)
|
||||
12 0.000 0.000 0.012 0.001 :0(hasattr)
|
||||
1 0.000 0.000 0.000 0.000 :0(setprofile)
|
||||
1 0.000 0.000 1.000 1.000 <string>:1(<module>)
|
||||
2 0.000 0.000 0.000 0.000 io.py:1213(flush)
|
||||
1 0.000 0.000 0.000 0.000 io.py:269(flush)
|
||||
1 0.000 0.000 0.000 0.000 io.py:656(closed)
|
||||
1 0.000 0.000 0.000 0.000 io.py:874(flush)
|
||||
0 0.000 0.000 profile:0(profiler)
|
||||
1 0.000 0.000 1.000 1.000 profile:0(testfunc())
|
||||
8 0.064 0.008 0.080 0.010 test_profile.py:103(subhelper)
|
||||
28 0.028 0.001 0.028 0.001 test_profile.py:115(__getattr__)
|
||||
1 0.270 0.270 1.000 1.000 test_profile.py:30(testfunc)
|
||||
23/3 0.150 0.007 0.170 0.057 test_profile.py:40(factorial)
|
||||
20 0.020 0.001 0.020 0.001 test_profile.py:53(mul)
|
||||
2 0.040 0.020 0.600 0.300 test_profile.py:60(helper)
|
||||
4 0.116 0.029 0.120 0.030 test_profile.py:78(helper1)
|
||||
2 0.000 0.000 0.140 0.070 test_profile.py:89(helper2_indirect)
|
||||
8 0.312 0.039 0.400 0.050 test_profile.py:93(helper2)
|
||||
|
||||
|
||||
Ordered by: standard name
|
||||
|
||||
Function called...
|
||||
:0(append) ->
|
||||
:0(exc_info) ->
|
||||
:0(exec) -> <string>:1(<module>)(1) 1.000
|
||||
io.py:1213(flush)(2) 0.000
|
||||
:0(hasattr) -> test_profile.py:115(__getattr__)(12) 0.028
|
||||
:0(setprofile) ->
|
||||
<string>:1(<module>) -> test_profile.py:30(testfunc)(1) 1.000
|
||||
io.py:1213(flush) -> io.py:269(flush)(1) 0.000
|
||||
io.py:874(flush)(1) 0.000
|
||||
io.py:269(flush) ->
|
||||
io.py:656(closed) ->
|
||||
io.py:874(flush) -> io.py:656(closed)(1) 0.000
|
||||
profile:0(profiler) -> profile:0(testfunc())(1) 1.000
|
||||
profile:0(testfunc()) -> :0(exec)(1) 1.000
|
||||
:0(setprofile)(1) 0.000
|
||||
test_profile.py:103(subhelper) -> test_profile.py:115(__getattr__)(16) 0.028
|
||||
test_profile.py:115(__getattr__) ->
|
||||
test_profile.py:30(testfunc) -> test_profile.py:40(factorial)(1) 0.170
|
||||
test_profile.py:60(helper)(2) 0.600
|
||||
test_profile.py:40(factorial) -> test_profile.py:40(factorial)(20) 0.170
|
||||
test_profile.py:53(mul)(20) 0.020
|
||||
test_profile.py:53(mul) ->
|
||||
test_profile.py:60(helper) -> test_profile.py:78(helper1)(4) 0.120
|
||||
test_profile.py:89(helper2_indirect)(2) 0.140
|
||||
test_profile.py:93(helper2)(6) 0.400
|
||||
test_profile.py:78(helper1) -> :0(append)(4) 0.000
|
||||
:0(exc_info)(4) 0.000
|
||||
:0(hasattr)(4) 0.012
|
||||
test_profile.py:89(helper2_indirect) -> test_profile.py:40(factorial)(2) 0.170
|
||||
test_profile.py:93(helper2)(2) 0.400
|
||||
test_profile.py:93(helper2) -> :0(hasattr)(8) 0.012
|
||||
test_profile.py:103(subhelper)(8) 0.080
|
||||
|
||||
|
||||
Ordered by: standard name
|
||||
|
||||
Function was called by...
|
||||
:0(append) <- test_profile.py:78(helper1)(4) 0.120
|
||||
:0(exc_info) <- test_profile.py:78(helper1)(4) 0.120
|
||||
:0(exec) <- profile:0(testfunc())(1) 1.000
|
||||
:0(hasattr) <- test_profile.py:78(helper1)(4) 0.120
|
||||
test_profile.py:93(helper2)(8) 0.400
|
||||
:0(setprofile) <- profile:0(testfunc())(1) 1.000
|
||||
<string>:1(<module>) <- :0(exec)(1) 1.000
|
||||
io.py:1213(flush) <- :0(exec)(2) 1.000
|
||||
io.py:269(flush) <- io.py:1213(flush)(1) 0.000
|
||||
io.py:656(closed) <- io.py:874(flush)(1) 0.000
|
||||
io.py:874(flush) <- io.py:1213(flush)(1) 0.000
|
||||
profile:0(profiler) <-
|
||||
profile:0(testfunc()) <- profile:0(profiler)(1) 0.000
|
||||
test_profile.py:103(subhelper) <- test_profile.py:93(helper2)(8) 0.400
|
||||
test_profile.py:115(__getattr__) <- :0(hasattr)(12) 0.012
|
||||
test_profile.py:103(subhelper)(16) 0.080
|
||||
test_profile.py:30(testfunc) <- <string>:1(<module>)(1) 1.000
|
||||
test_profile.py:40(factorial) <- test_profile.py:30(testfunc)(1) 1.000
|
||||
test_profile.py:40(factorial)(20) 0.170
|
||||
test_profile.py:89(helper2_indirect)(2) 0.140
|
||||
test_profile.py:53(mul) <- test_profile.py:40(factorial)(20) 0.170
|
||||
test_profile.py:60(helper) <- test_profile.py:30(testfunc)(2) 1.000
|
||||
test_profile.py:78(helper1) <- test_profile.py:60(helper)(4) 0.600
|
||||
test_profile.py:89(helper2_indirect) <- test_profile.py:60(helper)(2) 0.600
|
||||
test_profile.py:93(helper2) <- test_profile.py:60(helper)(6) 0.600
|
||||
test_profile.py:89(helper2_indirect)(2) 0.140
|
||||
|
||||
|
||||
115
Lib/test/profilee.py
Normal file
115
Lib/test/profilee.py
Normal file
@@ -0,0 +1,115 @@
|
||||
"""
|
||||
Input for test_profile.py and test_cprofile.py.
|
||||
|
||||
IMPORTANT: This stuff is touchy. If you modify anything above the
|
||||
test class you'll have to regenerate the stats by running the two
|
||||
test files.
|
||||
|
||||
*ALL* NUMBERS in the expected output are relevant. If you change
|
||||
the formatting of pstats, please don't just regenerate the expected
|
||||
output without checking very carefully that not a single number has
|
||||
changed.
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
# In order to have reproducible time, we simulate a timer in the global
|
||||
# variable 'TICKS', which represents simulated time in milliseconds.
|
||||
# (We can't use a helper function increment the timer since it would be
|
||||
# included in the profile and would appear to consume all the time.)
|
||||
TICKS = 42000
|
||||
|
||||
def timer():
|
||||
return TICKS
|
||||
|
||||
def testfunc():
|
||||
# 1 call
|
||||
# 1000 ticks total: 270 ticks local, 730 ticks in subfunctions
|
||||
global TICKS
|
||||
TICKS += 99
|
||||
helper() # 300
|
||||
helper() # 300
|
||||
TICKS += 171
|
||||
factorial(14) # 130
|
||||
|
||||
def factorial(n):
|
||||
# 23 calls total
|
||||
# 170 ticks total, 150 ticks local
|
||||
# 3 primitive calls, 130, 20 and 20 ticks total
|
||||
# including 116, 17, 17 ticks local
|
||||
global TICKS
|
||||
if n > 0:
|
||||
TICKS += n
|
||||
return mul(n, factorial(n-1))
|
||||
else:
|
||||
TICKS += 11
|
||||
return 1
|
||||
|
||||
def mul(a, b):
|
||||
# 20 calls
|
||||
# 1 tick, local
|
||||
global TICKS
|
||||
TICKS += 1
|
||||
return a * b
|
||||
|
||||
def helper():
|
||||
# 2 calls
|
||||
# 300 ticks total: 20 ticks local, 260 ticks in subfunctions
|
||||
global TICKS
|
||||
TICKS += 1
|
||||
helper1() # 30
|
||||
TICKS += 2
|
||||
helper1() # 30
|
||||
TICKS += 6
|
||||
helper2() # 50
|
||||
TICKS += 3
|
||||
helper2() # 50
|
||||
TICKS += 2
|
||||
helper2() # 50
|
||||
TICKS += 5
|
||||
helper2_indirect() # 70
|
||||
TICKS += 1
|
||||
|
||||
def helper1():
|
||||
# 4 calls
|
||||
# 30 ticks total: 29 ticks local, 1 tick in subfunctions
|
||||
global TICKS
|
||||
TICKS += 10
|
||||
hasattr(C(), "foo") # 1
|
||||
TICKS += 19
|
||||
lst = []
|
||||
lst.append(42) # 0
|
||||
sys.exc_info() # 0
|
||||
|
||||
def helper2_indirect():
|
||||
helper2() # 50
|
||||
factorial(3) # 20
|
||||
|
||||
def helper2():
|
||||
# 8 calls
|
||||
# 50 ticks local: 39 ticks local, 11 ticks in subfunctions
|
||||
global TICKS
|
||||
TICKS += 11
|
||||
hasattr(C(), "bar") # 1
|
||||
TICKS += 13
|
||||
subhelper() # 10
|
||||
TICKS += 15
|
||||
|
||||
def subhelper():
|
||||
# 8 calls
|
||||
# 10 ticks total: 8 ticks local, 2 ticks in subfunctions
|
||||
global TICKS
|
||||
TICKS += 2
|
||||
for i in range(2): # 0
|
||||
try:
|
||||
C().foo # 1 x 2
|
||||
except AttributeError:
|
||||
TICKS += 3 # 3 x 2
|
||||
|
||||
class C:
|
||||
def __getattr__(self, name):
|
||||
# 28 calls
|
||||
# 1 tick, local
|
||||
global TICKS
|
||||
TICKS += 1
|
||||
raise AttributeError
|
||||
@@ -117,11 +117,11 @@ b"""<dl><dt><a name="-<lambda>"><strong><lambda></strong></a>(x, y)<
|
||||
The documentation for the "add" method contains the test material.
|
||||
"""
|
||||
self.client.request("GET", "/")
|
||||
response = self.client.getresponse()
|
||||
response = self.client.getresponse().read()
|
||||
|
||||
self.assert_( # This is ugly ... how can it be made better?
|
||||
b"""<dl><dt><a name="-add"><strong>add</strong></a>(x, y)</dt><dd><tt>Add two instances together. This follows <a href="http://www.python.org/peps/pep-0008.html">PEP008</a>, but has nothing<br>\nto do with <a href="http://www.rfc-editor.org/rfc/rfc1952.txt">RFC1952</a>. Case should matter: pEp008 and rFC1952. Things<br>\nthat start with http and ftp should be auto-linked, too:<br>\n<a href="http://google.com">http://google.com</a>.</tt></dd></dl>"""
|
||||
in response.read())
|
||||
b"""<dl><dt><a name="-add"><strong>add</strong></a>(x, y)</dt><dd><tt>Add two instances together. This follows <a href="http://www.python.org/dev/peps/pep-0008/">PEP008</a>, but has nothing<br>\nto do with <a href="http://www.rfc-editor.org/rfc/rfc1952.txt">RFC1952</a>. Case should matter: pEp008 and rFC1952. Things<br>\nthat start with http and ftp should be auto-linked, too:<br>\n<a href="http://google.com">http://google.com</a>.</tt></dd></dl>"""
|
||||
in response, response)
|
||||
|
||||
def test_system_methods(self):
|
||||
"""Test the precense of three consecutive system.* methods.
|
||||
|
||||
268
Lib/test/test_profile.py
Normal file → Executable file
268
Lib/test/test_profile.py
Normal file → Executable file
@@ -1,123 +1,179 @@
|
||||
"""Test suite for the profile module."""
|
||||
|
||||
import profile, pstats, sys
|
||||
import os
|
||||
import sys
|
||||
import pstats
|
||||
import unittest
|
||||
from difflib import unified_diff
|
||||
from io import StringIO
|
||||
from test.test_support import run_unittest
|
||||
|
||||
# In order to have reproducible time, we simulate a timer in the global
|
||||
# variable 'ticks', which represents simulated time in milliseconds.
|
||||
# (We can't use a helper function increment the timer since it would be
|
||||
# included in the profile and would appear to consume all the time.)
|
||||
ticks = 0
|
||||
import profile
|
||||
from test.profilee import testfunc, timer
|
||||
|
||||
|
||||
class ProfileTest(unittest.TestCase):
|
||||
|
||||
profilerclass = profile.Profile
|
||||
methodnames = ['print_stats', 'print_callers', 'print_callees']
|
||||
expected_output = {}
|
||||
|
||||
@classmethod
|
||||
def do_profiling(cls):
|
||||
results = []
|
||||
prof = cls.profilerclass(timer, 0.001)
|
||||
prof.runctx("testfunc()", globals(), locals())
|
||||
results.append(timer())
|
||||
for methodname in cls.methodnames:
|
||||
s = StringIO()
|
||||
stats = pstats.Stats(prof, stream=s)
|
||||
stats.strip_dirs().sort_stats("stdname")
|
||||
getattr(stats, methodname)()
|
||||
results.append(s.getvalue())
|
||||
return results
|
||||
|
||||
def test_cprofile(self):
|
||||
results = self.do_profiling()
|
||||
self.assertEqual(results[0], 43000)
|
||||
for i, method in enumerate(self.methodnames):
|
||||
if results[i+1] != self.expected_output[method]:
|
||||
print("Stats.%s output for %s doesn't fit expectation!" %
|
||||
(method, self.profilerclass.__name__))
|
||||
print('\n'.join(unified_diff(
|
||||
results[i+1].split('\n'),
|
||||
self.expected_output[method].split('\n'))))
|
||||
|
||||
|
||||
def regenerate_expected_output(filename, cls):
|
||||
filename = filename.rstrip('co')
|
||||
print('Regenerating %s...' % filename)
|
||||
results = cls.do_profiling()
|
||||
|
||||
newfile = []
|
||||
with open(filename, 'r') as f:
|
||||
for line in f:
|
||||
newfile.append(line)
|
||||
if line[:6] == '#--cut':
|
||||
break
|
||||
|
||||
with open(filename, 'w') as f:
|
||||
f.writelines(newfile)
|
||||
for i, method in enumerate(cls.methodnames):
|
||||
f.write('%s.expected_output[%r] = """\\\n%s"""\n' % (
|
||||
cls.__name__, method, results[i+1]))
|
||||
f.write('\nif __name__ == "__main__":\n main()\n')
|
||||
|
||||
# IMPORTANT: this is an output test. *ALL* NUMBERS in the expected
|
||||
# output are relevant. If you change the formatting of pstats,
|
||||
# please don't just regenerate output/test_profile without checking
|
||||
# very carefully that not a single number has changed.
|
||||
|
||||
def test_main():
|
||||
global ticks
|
||||
ticks = 42000
|
||||
prof = profile.Profile(timer)
|
||||
prof.runctx("testfunc()", globals(), locals())
|
||||
assert ticks == 43000, ticks
|
||||
st = pstats.Stats(prof)
|
||||
st.strip_dirs().sort_stats('stdname').print_stats()
|
||||
st.print_callees()
|
||||
st.print_callers()
|
||||
run_unittest(ProfileTest)
|
||||
|
||||
def timer():
|
||||
return ticks*0.001
|
||||
|
||||
def testfunc():
|
||||
# 1 call
|
||||
# 1000 ticks total: 270 ticks local, 730 ticks in subfunctions
|
||||
global ticks
|
||||
ticks += 99
|
||||
helper() # 300
|
||||
helper() # 300
|
||||
ticks += 171
|
||||
factorial(14) # 130
|
||||
|
||||
def factorial(n):
|
||||
# 23 calls total
|
||||
# 170 ticks total, 150 ticks local
|
||||
# 3 primitive calls, 130, 20 and 20 ticks total
|
||||
# including 116, 17, 17 ticks local
|
||||
global ticks
|
||||
if n > 0:
|
||||
ticks += n
|
||||
return mul(n, factorial(n-1))
|
||||
def main():
|
||||
if '-r' not in sys.argv:
|
||||
test_main()
|
||||
else:
|
||||
ticks += 11
|
||||
return 1
|
||||
regenerate_expected_output(__file__, ProfileTest)
|
||||
|
||||
def mul(a, b):
|
||||
# 20 calls
|
||||
# 1 tick, local
|
||||
global ticks
|
||||
ticks += 1
|
||||
return a * b
|
||||
|
||||
def helper():
|
||||
# 2 calls
|
||||
# 300 ticks total: 20 ticks local, 260 ticks in subfunctions
|
||||
global ticks
|
||||
ticks += 1
|
||||
helper1() # 30
|
||||
ticks += 2
|
||||
helper1() # 30
|
||||
ticks += 6
|
||||
helper2() # 50
|
||||
ticks += 3
|
||||
helper2() # 50
|
||||
ticks += 2
|
||||
helper2() # 50
|
||||
ticks += 5
|
||||
helper2_indirect() # 70
|
||||
ticks += 1
|
||||
# Don't remove this comment. Everything below it is auto-generated.
|
||||
#--cut--------------------------------------------------------------------------
|
||||
ProfileTest.expected_output['print_stats'] = """\
|
||||
126 function calls (106 primitive calls) in 999.751 CPU seconds
|
||||
|
||||
def helper1():
|
||||
# 4 calls
|
||||
# 30 ticks total: 29 ticks local, 1 tick in subfunctions
|
||||
global ticks
|
||||
ticks += 10
|
||||
hasattr(C(), "foo") # 1
|
||||
ticks += 19
|
||||
lst = []
|
||||
lst.append(42) # 0
|
||||
sys.exc_info() # 0
|
||||
Ordered by: standard name
|
||||
|
||||
def helper2_indirect():
|
||||
helper2() # 50
|
||||
factorial(3) # 20
|
||||
ncalls tottime percall cumtime percall filename:lineno(function)
|
||||
4 -0.004 -0.001 -0.004 -0.001 :0(append)
|
||||
4 -0.004 -0.001 -0.004 -0.001 :0(exc_info)
|
||||
1 -0.004 -0.004 999.753 999.753 :0(exec)
|
||||
12 -0.024 -0.002 11.964 0.997 :0(hasattr)
|
||||
1 0.000 0.000 0.000 0.000 :0(setprofile)
|
||||
1 -0.002 -0.002 999.767 999.767 <string>:1(<module>)
|
||||
2 -0.004 -0.002 -0.010 -0.005 io.py:1213(flush)
|
||||
2 -0.002 -0.001 -0.002 -0.001 io.py:656(closed)
|
||||
2 -0.004 -0.002 -0.006 -0.003 io.py:874(flush)
|
||||
0 0.000 0.000 profile:0(profiler)
|
||||
1 -0.002 -0.002 999.751 999.751 profile:0(testfunc())
|
||||
28 27.972 0.999 27.972 0.999 profilee.py:110(__getattr__)
|
||||
1 269.996 269.996 999.769 999.769 profilee.py:25(testfunc)
|
||||
23/3 149.937 6.519 169.917 56.639 profilee.py:35(factorial)
|
||||
20 19.980 0.999 19.980 0.999 profilee.py:48(mul)
|
||||
2 39.986 19.993 599.830 299.915 profilee.py:55(helper)
|
||||
4 115.984 28.996 119.964 29.991 profilee.py:73(helper1)
|
||||
2 -0.006 -0.003 139.946 69.973 profilee.py:84(helper2_indirect)
|
||||
8 311.976 38.997 399.912 49.989 profilee.py:88(helper2)
|
||||
8 63.976 7.997 79.960 9.995 profilee.py:98(subhelper)
|
||||
|
||||
def helper2():
|
||||
# 8 calls
|
||||
# 50 ticks local: 39 ticks local, 11 ticks in subfunctions
|
||||
global ticks
|
||||
ticks += 11
|
||||
hasattr(C(), "bar") # 1
|
||||
ticks += 13
|
||||
subhelper() # 10
|
||||
ticks += 15
|
||||
|
||||
def subhelper():
|
||||
# 8 calls
|
||||
# 10 ticks total: 8 ticks local, 2 ticks in subfunctions
|
||||
global ticks
|
||||
ticks += 2
|
||||
for i in range(2): # 0
|
||||
try:
|
||||
C().foo # 1 x 2
|
||||
except AttributeError:
|
||||
ticks += 3 # 3 x 2
|
||||
"""
|
||||
ProfileTest.expected_output['print_callers'] = """\
|
||||
Ordered by: standard name
|
||||
|
||||
class C:
|
||||
def __getattr__(self, name):
|
||||
# 28 calls
|
||||
# 1 tick, local
|
||||
global ticks
|
||||
ticks += 1
|
||||
raise AttributeError
|
||||
Function was called by...
|
||||
:0(append) <- profilee.py:73(helper1)(4) 119.964
|
||||
:0(exc_info) <- profilee.py:73(helper1)(4) 119.964
|
||||
:0(exec) <- profile:0(testfunc())(1) 999.751
|
||||
:0(hasattr) <- profilee.py:73(helper1)(4) 119.964
|
||||
profilee.py:88(helper2)(8) 399.912
|
||||
:0(setprofile) <- profile:0(testfunc())(1) 999.751
|
||||
<string>:1(<module>) <- :0(exec)(1) 999.753
|
||||
io.py:1213(flush) <- :0(exec)(2) 999.753
|
||||
io.py:656(closed) <- io.py:874(flush)(2) -0.006
|
||||
io.py:874(flush) <- io.py:1213(flush)(2) -0.010
|
||||
profile:0(profiler) <-
|
||||
profile:0(testfunc()) <- profile:0(profiler)(1) 0.000
|
||||
profilee.py:110(__getattr__) <- :0(hasattr)(12) 11.964
|
||||
profilee.py:98(subhelper)(16) 79.960
|
||||
profilee.py:25(testfunc) <- <string>:1(<module>)(1) 999.767
|
||||
profilee.py:35(factorial) <- profilee.py:25(testfunc)(1) 999.769
|
||||
profilee.py:35(factorial)(20) 169.917
|
||||
profilee.py:84(helper2_indirect)(2) 139.946
|
||||
profilee.py:48(mul) <- profilee.py:35(factorial)(20) 169.917
|
||||
profilee.py:55(helper) <- profilee.py:25(testfunc)(2) 999.769
|
||||
profilee.py:73(helper1) <- profilee.py:55(helper)(4) 599.830
|
||||
profilee.py:84(helper2_indirect) <- profilee.py:55(helper)(2) 599.830
|
||||
profilee.py:88(helper2) <- profilee.py:55(helper)(6) 599.830
|
||||
profilee.py:84(helper2_indirect)(2) 139.946
|
||||
profilee.py:98(subhelper) <- profilee.py:88(helper2)(8) 399.912
|
||||
|
||||
|
||||
"""
|
||||
ProfileTest.expected_output['print_callees'] = """\
|
||||
Ordered by: standard name
|
||||
|
||||
Function called...
|
||||
:0(append) ->
|
||||
:0(exc_info) ->
|
||||
:0(exec) -> <string>:1(<module>)(1) 999.767
|
||||
io.py:1213(flush)(2) -0.010
|
||||
:0(hasattr) -> profilee.py:110(__getattr__)(12) 27.972
|
||||
:0(setprofile) ->
|
||||
<string>:1(<module>) -> profilee.py:25(testfunc)(1) 999.769
|
||||
io.py:1213(flush) -> io.py:874(flush)(2) -0.006
|
||||
io.py:656(closed) ->
|
||||
io.py:874(flush) -> io.py:656(closed)(2) -0.002
|
||||
profile:0(profiler) -> profile:0(testfunc())(1) 999.751
|
||||
profile:0(testfunc()) -> :0(exec)(1) 999.753
|
||||
:0(setprofile)(1) 0.000
|
||||
profilee.py:110(__getattr__) ->
|
||||
profilee.py:25(testfunc) -> profilee.py:35(factorial)(1) 169.917
|
||||
profilee.py:55(helper)(2) 599.830
|
||||
profilee.py:35(factorial) -> profilee.py:35(factorial)(20) 169.917
|
||||
profilee.py:48(mul)(20) 19.980
|
||||
profilee.py:48(mul) ->
|
||||
profilee.py:55(helper) -> profilee.py:73(helper1)(4) 119.964
|
||||
profilee.py:84(helper2_indirect)(2) 139.946
|
||||
profilee.py:88(helper2)(6) 399.912
|
||||
profilee.py:73(helper1) -> :0(append)(4) -0.004
|
||||
:0(exc_info)(4) -0.004
|
||||
:0(hasattr)(4) 11.964
|
||||
profilee.py:84(helper2_indirect) -> profilee.py:35(factorial)(2) 169.917
|
||||
profilee.py:88(helper2)(2) 399.912
|
||||
profilee.py:88(helper2) -> :0(hasattr)(8) 11.964
|
||||
profilee.py:98(subhelper)(8) 79.960
|
||||
profilee.py:98(subhelper) -> profilee.py:110(__getattr__)(16) 27.972
|
||||
|
||||
|
||||
"""
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
main()
|
||||
|
||||
@@ -339,11 +339,14 @@ class SysModuleTest(unittest.TestCase):
|
||||
# freed blocks shouldn't change
|
||||
self.assertEqual(r[0][2], 0)
|
||||
# fill freelists
|
||||
floats = [float(i) for i in range(12000)]
|
||||
ints = list(range(10000))
|
||||
floats = [float(i) for i in ints]
|
||||
del ints
|
||||
del floats
|
||||
# should free more than 200 blocks
|
||||
# should free more than 100 blocks
|
||||
r = sys._compact_freelists()
|
||||
self.assert_(r[0][2] > 200, r[0][2])
|
||||
self.assert_(r[0][1] > 100, r[0][1])
|
||||
self.assert_(r[0][2] > 100, r[0][2])
|
||||
|
||||
def test_main():
|
||||
test.test_support.run_unittest(SysModuleTest)
|
||||
|
||||
@@ -252,14 +252,16 @@ class TraceTestCase(unittest.TestCase):
|
||||
"\n".join(difflib.ndiff([str(x) for x in expected_events],
|
||||
[str(x) for x in events])))
|
||||
|
||||
|
||||
def run_test(self, func):
|
||||
def run_and_compare(self, func, events):
|
||||
tracer = Tracer()
|
||||
sys.settrace(tracer.trace)
|
||||
func()
|
||||
sys.settrace(None)
|
||||
self.compare_events(func.__code__.co_firstlineno,
|
||||
tracer.events, func.events)
|
||||
tracer.events, events)
|
||||
|
||||
def run_test(self, func):
|
||||
self.run_and_compare(func, func.events)
|
||||
|
||||
def run_test2(self, func):
|
||||
tracer = Tracer()
|
||||
@@ -321,6 +323,59 @@ class TraceTestCase(unittest.TestCase):
|
||||
self.compare_events(generator_example.__code__.co_firstlineno,
|
||||
tracer.events, generator_example.events)
|
||||
|
||||
def test_14_onliner_if(self):
|
||||
def onliners():
|
||||
if True: False
|
||||
else: True
|
||||
return 0
|
||||
self.run_and_compare(
|
||||
onliners,
|
||||
[(0, 'call'),
|
||||
(1, 'line'),
|
||||
(3, 'line'),
|
||||
(3, 'return')])
|
||||
|
||||
def test_15_loops(self):
|
||||
# issue1750076: "while" expression is skipped by debugger
|
||||
def for_example():
|
||||
for x in range(2):
|
||||
pass
|
||||
self.run_and_compare(
|
||||
for_example,
|
||||
[(0, 'call'),
|
||||
(1, 'line'),
|
||||
(2, 'line'),
|
||||
(1, 'line'),
|
||||
(2, 'line'),
|
||||
(1, 'line'),
|
||||
(1, 'return')])
|
||||
|
||||
def while_example():
|
||||
# While expression should be traced on every loop
|
||||
x = 2
|
||||
while x > 0:
|
||||
x -= 1
|
||||
self.run_and_compare(
|
||||
while_example,
|
||||
[(0, 'call'),
|
||||
(2, 'line'),
|
||||
(3, 'line'),
|
||||
(4, 'line'),
|
||||
(3, 'line'),
|
||||
(4, 'line'),
|
||||
(3, 'line'),
|
||||
(3, 'return')])
|
||||
|
||||
def test_16_blank_lines(self):
|
||||
namespace = {}
|
||||
exec("def f():\n" + "\n" * 256 + " pass", namespace)
|
||||
self.run_and_compare(
|
||||
namespace["f"],
|
||||
[(0, 'call'),
|
||||
(257, 'line'),
|
||||
(257, 'return')])
|
||||
|
||||
|
||||
class RaisingTraceFuncTestCase(unittest.TestCase):
|
||||
def trace(self, frame, event, arg):
|
||||
"""A trace function that raises an exception in response to a
|
||||
|
||||
@@ -1,32 +1,45 @@
|
||||
from test.test_support import TestFailed, TESTFN
|
||||
from test.test_support import TESTFN, run_unittest
|
||||
import os
|
||||
import wave
|
||||
|
||||
def check(t, msg=None):
|
||||
if not t:
|
||||
raise TestFailed(msg)
|
||||
import unittest
|
||||
|
||||
nchannels = 2
|
||||
sampwidth = 2
|
||||
framerate = 8000
|
||||
nframes = 100
|
||||
|
||||
f = wave.open(TESTFN, 'wb')
|
||||
f.setnchannels(nchannels)
|
||||
f.setsampwidth(sampwidth)
|
||||
f.setframerate(framerate)
|
||||
f.setnframes(nframes)
|
||||
output = b'\0' * nframes * nchannels * sampwidth
|
||||
f.writeframes(output)
|
||||
f.close()
|
||||
class TestWave(unittest.TestCase):
|
||||
|
||||
f = wave.open(TESTFN, 'rb')
|
||||
check(nchannels == f.getnchannels(), "nchannels")
|
||||
check(sampwidth == f.getsampwidth(), "sampwidth")
|
||||
check(framerate == f.getframerate(), "framerate")
|
||||
check(nframes == f.getnframes(), "nframes")
|
||||
input = f.readframes(nframes)
|
||||
check(input == output, "data")
|
||||
f.close()
|
||||
def setUp(self):
|
||||
self.f = None
|
||||
|
||||
os.remove(TESTFN)
|
||||
def tearDown(self):
|
||||
if self.f is not None:
|
||||
self.f.close()
|
||||
try:
|
||||
os.remove(TESTFN)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
def test_it(self):
|
||||
self.f = wave.open(TESTFN, 'wb')
|
||||
self.f.setnchannels(nchannels)
|
||||
self.f.setsampwidth(sampwidth)
|
||||
self.f.setframerate(framerate)
|
||||
self.f.setnframes(nframes)
|
||||
output = b'\0' * nframes * nchannels * sampwidth
|
||||
self.f.writeframes(output)
|
||||
self.f.close()
|
||||
|
||||
self.f = wave.open(TESTFN, 'rb')
|
||||
self.assertEqual(nchannels, self.f.getnchannels())
|
||||
self.assertEqual(sampwidth, self.f.getsampwidth())
|
||||
self.assertEqual(framerate, self.f.getframerate())
|
||||
self.assertEqual(nframes, self.f.getnframes())
|
||||
self.assertEqual(self.f.readframes(nframes), output)
|
||||
|
||||
def test_main():
|
||||
run_unittest(TestWave)
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_main()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user