Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
234cbef3
Commit
234cbef3
authored
Sep 30, 2015
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #25220, libregrtest: Move setup_python() to a new submodule
parent
c7eab052
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
123 additions
and
110 deletions
+123
-110
Lib/test/libregrtest/main.py
Lib/test/libregrtest/main.py
+15
-110
Lib/test/libregrtest/setup.py
Lib/test/libregrtest/setup.py
+108
-0
No files found.
Lib/test/libregrtest/main.py
View file @
234cbef3
import
faulthandler
import
os
import
platform
import
random
import
re
import
signal
import
sys
import
sysconfig
import
tempfile
import
textwrap
import
unittest
from
test.libregrtest.runtest
import
(
findtests
,
runtest
,
STDTESTS
,
NOTTESTS
,
PASSED
,
FAILED
,
ENV_CHANGED
,
SKIPPED
,
RESOURCE_DENIED
)
from
test.libregrtest.refleak
import
warm_caches
from
test.libregrtest.cmdline
import
_parse_args
from
test.libregrtest.setup
import
setup_python
from
test
import
support
try
:
import
gc
...
...
@@ -31,88 +28,6 @@ else:
TEMPDIR
=
os
.
path
.
abspath
(
TEMPDIR
)
def
setup_python
(
ns
):
# Display the Python traceback on fatal errors (e.g. segfault)
faulthandler
.
enable
(
all_threads
=
True
)
# Display the Python traceback on SIGALRM or SIGUSR1 signal
signals
=
[]
if
hasattr
(
signal
,
'SIGALRM'
):
signals
.
append
(
signal
.
SIGALRM
)
if
hasattr
(
signal
,
'SIGUSR1'
):
signals
.
append
(
signal
.
SIGUSR1
)
for
signum
in
signals
:
faulthandler
.
register
(
signum
,
chain
=
True
)
replace_stdout
()
support
.
record_original_stdout
(
sys
.
stdout
)
# Some times __path__ and __file__ are not absolute (e.g. while running from
# Lib/) and, if we change the CWD to run the tests in a temporary dir, some
# imports might fail. This affects only the modules imported before os.chdir().
# These modules are searched first in sys.path[0] (so '' -- the CWD) and if
# they are found in the CWD their __file__ and __path__ will be relative (this
# happens before the chdir). All the modules imported after the chdir, are
# not found in the CWD, and since the other paths in sys.path[1:] are absolute
# (site.py absolutize them), the __file__ and __path__ will be absolute too.
# Therefore it is necessary to absolutize manually the __file__ and __path__ of
# the packages to prevent later imports to fail when the CWD is different.
for
module
in
sys
.
modules
.
values
():
if
hasattr
(
module
,
'__path__'
):
module
.
__path__
=
[
os
.
path
.
abspath
(
path
)
for
path
in
module
.
__path__
]
if
hasattr
(
module
,
'__file__'
):
module
.
__file__
=
os
.
path
.
abspath
(
module
.
__file__
)
# MacOSX (a.k.a. Darwin) has a default stack size that is too small
# for deeply recursive regular expressions. We see this as crashes in
# the Python test suite when running test_re.py and test_sre.py. The
# fix is to set the stack limit to 2048.
# This approach may also be useful for other Unixy platforms that
# suffer from small default stack limits.
if
sys
.
platform
==
'darwin'
:
try
:
import
resource
except
ImportError
:
pass
else
:
soft
,
hard
=
resource
.
getrlimit
(
resource
.
RLIMIT_STACK
)
newsoft
=
min
(
hard
,
max
(
soft
,
1024
*
2048
))
resource
.
setrlimit
(
resource
.
RLIMIT_STACK
,
(
newsoft
,
hard
))
if
ns
.
huntrleaks
:
unittest
.
BaseTestSuite
.
_cleanup
=
False
# Avoid false positives due to various caches
# filling slowly with random data:
warm_caches
()
if
ns
.
memlimit
is
not
None
:
support
.
set_memlimit
(
ns
.
memlimit
)
if
ns
.
threshold
is
not
None
:
if
gc
is
not
None
:
gc
.
set_threshold
(
ns
.
threshold
)
else
:
print
(
'No GC available, ignore --threshold.'
)
if
ns
.
nowindows
:
import
msvcrt
msvcrt
.
SetErrorMode
(
msvcrt
.
SEM_FAILCRITICALERRORS
|
msvcrt
.
SEM_NOALIGNMENTFAULTEXCEPT
|
msvcrt
.
SEM_NOGPFAULTERRORBOX
|
msvcrt
.
SEM_NOOPENFILEERRORBOX
)
try
:
msvcrt
.
CrtSetReportMode
except
AttributeError
:
# release build
pass
else
:
for
m
in
[
msvcrt
.
CRT_WARN
,
msvcrt
.
CRT_ERROR
,
msvcrt
.
CRT_ASSERT
]:
msvcrt
.
CrtSetReportMode
(
m
,
msvcrt
.
CRTDBG_MODE_FILE
)
msvcrt
.
CrtSetReportFile
(
m
,
msvcrt
.
CRTDBG_FILE_STDERR
)
class
Regrtest
:
"""Execute a test suite.
...
...
@@ -192,8 +107,14 @@ class Regrtest:
self
.
test_count
,
len
(
self
.
bad
),
test
),
flush
=
True
)
def
setup_regrtest
(
self
):
if
self
.
ns
.
findleaks
:
def
parse_args
(
self
,
kwargs
):
ns
=
_parse_args
(
sys
.
argv
[
1
:],
**
kwargs
)
if
ns
.
threshold
is
not
None
and
gc
is
None
:
print
(
'No GC available, ignore --threshold.'
)
ns
.
threshold
=
None
if
ns
.
findleaks
:
if
gc
is
not
None
:
# Uncomment the line below to report garbage that is not
# freeable by reference counting alone. By default only
...
...
@@ -202,10 +123,12 @@ class Regrtest:
#gc.set_debug(gc.DEBUG_SAVEALL)
else
:
print
(
'No GC available, disabling --findleaks'
)
self
.
ns
.
findleaks
=
False
ns
.
findleaks
=
False
# Strip .py extensions.
removepy
(
self
.
ns
.
args
)
removepy
(
ns
.
args
)
return
ns
def
find_tests
(
self
,
tests
):
self
.
tests
=
tests
...
...
@@ -434,9 +357,9 @@ class Regrtest:
os
.
system
(
"leaks %d"
%
os
.
getpid
())
def
main
(
self
,
tests
=
None
,
**
kwargs
):
self
.
ns
=
_parse_args
(
sys
.
argv
[
1
:],
**
kwargs
)
self
.
ns
=
self
.
parse_args
(
kwargs
)
setup_python
(
self
.
ns
)
self
.
setup_regrtest
()
if
self
.
ns
.
slaveargs
is
not
None
:
from
test.libregrtest.runtest_mp
import
run_tests_slave
...
...
@@ -452,24 +375,6 @@ class Regrtest:
sys
.
exit
(
len
(
self
.
bad
)
>
0
or
self
.
interrupted
)
def
replace_stdout
():
"""Set stdout encoder error handler to backslashreplace (as stderr error
handler) to avoid UnicodeEncodeError when printing a traceback"""
import
atexit
stdout
=
sys
.
stdout
sys
.
stdout
=
open
(
stdout
.
fileno
(),
'w'
,
encoding
=
stdout
.
encoding
,
errors
=
"backslashreplace"
,
closefd
=
False
,
newline
=
'
\
n
'
)
def
restore_stdout
():
sys
.
stdout
.
close
()
sys
.
stdout
=
stdout
atexit
.
register
(
restore_stdout
)
def
removepy
(
names
):
if
not
names
:
return
...
...
Lib/test/libregrtest/setup.py
0 → 100644
View file @
234cbef3
import
atexit
import
faulthandler
import
os
import
signal
import
sys
import
unittest
from
test
import
support
try
:
import
gc
except
ImportError
:
gc
=
None
from
test.libregrtest.refleak
import
warm_caches
def
setup_python
(
ns
):
# Display the Python traceback on fatal errors (e.g. segfault)
faulthandler
.
enable
(
all_threads
=
True
)
# Display the Python traceback on SIGALRM or SIGUSR1 signal
signals
=
[]
if
hasattr
(
signal
,
'SIGALRM'
):
signals
.
append
(
signal
.
SIGALRM
)
if
hasattr
(
signal
,
'SIGUSR1'
):
signals
.
append
(
signal
.
SIGUSR1
)
for
signum
in
signals
:
faulthandler
.
register
(
signum
,
chain
=
True
)
replace_stdout
()
support
.
record_original_stdout
(
sys
.
stdout
)
# Some times __path__ and __file__ are not absolute (e.g. while running from
# Lib/) and, if we change the CWD to run the tests in a temporary dir, some
# imports might fail. This affects only the modules imported before os.chdir().
# These modules are searched first in sys.path[0] (so '' -- the CWD) and if
# they are found in the CWD their __file__ and __path__ will be relative (this
# happens before the chdir). All the modules imported after the chdir, are
# not found in the CWD, and since the other paths in sys.path[1:] are absolute
# (site.py absolutize them), the __file__ and __path__ will be absolute too.
# Therefore it is necessary to absolutize manually the __file__ and __path__ of
# the packages to prevent later imports to fail when the CWD is different.
for
module
in
sys
.
modules
.
values
():
if
hasattr
(
module
,
'__path__'
):
module
.
__path__
=
[
os
.
path
.
abspath
(
path
)
for
path
in
module
.
__path__
]
if
hasattr
(
module
,
'__file__'
):
module
.
__file__
=
os
.
path
.
abspath
(
module
.
__file__
)
# MacOSX (a.k.a. Darwin) has a default stack size that is too small
# for deeply recursive regular expressions. We see this as crashes in
# the Python test suite when running test_re.py and test_sre.py. The
# fix is to set the stack limit to 2048.
# This approach may also be useful for other Unixy platforms that
# suffer from small default stack limits.
if
sys
.
platform
==
'darwin'
:
try
:
import
resource
except
ImportError
:
pass
else
:
soft
,
hard
=
resource
.
getrlimit
(
resource
.
RLIMIT_STACK
)
newsoft
=
min
(
hard
,
max
(
soft
,
1024
*
2048
))
resource
.
setrlimit
(
resource
.
RLIMIT_STACK
,
(
newsoft
,
hard
))
if
ns
.
huntrleaks
:
unittest
.
BaseTestSuite
.
_cleanup
=
False
# Avoid false positives due to various caches
# filling slowly with random data:
warm_caches
()
if
ns
.
memlimit
is
not
None
:
support
.
set_memlimit
(
ns
.
memlimit
)
if
ns
.
threshold
is
not
None
:
gc
.
set_threshold
(
ns
.
threshold
)
if
ns
.
nowindows
:
import
msvcrt
msvcrt
.
SetErrorMode
(
msvcrt
.
SEM_FAILCRITICALERRORS
|
msvcrt
.
SEM_NOALIGNMENTFAULTEXCEPT
|
msvcrt
.
SEM_NOGPFAULTERRORBOX
|
msvcrt
.
SEM_NOOPENFILEERRORBOX
)
try
:
msvcrt
.
CrtSetReportMode
except
AttributeError
:
# release build
pass
else
:
for
m
in
[
msvcrt
.
CRT_WARN
,
msvcrt
.
CRT_ERROR
,
msvcrt
.
CRT_ASSERT
]:
msvcrt
.
CrtSetReportMode
(
m
,
msvcrt
.
CRTDBG_MODE_FILE
)
msvcrt
.
CrtSetReportFile
(
m
,
msvcrt
.
CRTDBG_FILE_STDERR
)
def
replace_stdout
():
"""Set stdout encoder error handler to backslashreplace (as stderr error
handler) to avoid UnicodeEncodeError when printing a traceback"""
stdout
=
sys
.
stdout
sys
.
stdout
=
open
(
stdout
.
fileno
(),
'w'
,
encoding
=
stdout
.
encoding
,
errors
=
"backslashreplace"
,
closefd
=
False
,
newline
=
'
\
n
'
)
def
restore_stdout
():
sys
.
stdout
.
close
()
sys
.
stdout
=
stdout
atexit
.
register
(
restore_stdout
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment