Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
b0478b3f
Kaydet (Commit)
b0478b3f
authored
Eyl 06, 2013
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #18623: Factor out the _SuppressCoreFiles context manager into test.support.
Patch by Valerie Lambert.
üst
4a043016
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
46 deletions
+50
-46
__init__.py
Lib/test/support/__init__.py
+45
-0
test_subprocess.py
Lib/test/test_subprocess.py
+1
-46
test_support.py
Lib/test/test_support.py
+1
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/support/__init__.py
Dosyayı görüntüle @
b0478b3f
...
@@ -57,6 +57,11 @@ try:
...
@@ -57,6 +57,11 @@ try:
except
ImportError
:
except
ImportError
:
lzma
=
None
lzma
=
None
try
:
import
resource
except
ImportError
:
resource
=
None
__all__
=
[
__all__
=
[
"Error"
,
"TestFailed"
,
"ResourceDenied"
,
"import_module"
,
"verbose"
,
"Error"
,
"TestFailed"
,
"ResourceDenied"
,
"import_module"
,
"verbose"
,
"use_resources"
,
"max_memuse"
,
"record_original_stdout"
,
"use_resources"
,
"max_memuse"
,
"record_original_stdout"
,
...
@@ -77,6 +82,7 @@ __all__ = [
...
@@ -77,6 +82,7 @@ __all__ = [
"skip_unless_xattr"
,
"import_fresh_module"
,
"requires_zlib"
,
"skip_unless_xattr"
,
"import_fresh_module"
,
"requires_zlib"
,
"PIPE_MAX_SIZE"
,
"failfast"
,
"anticipate_failure"
,
"run_with_tz"
,
"PIPE_MAX_SIZE"
,
"failfast"
,
"anticipate_failure"
,
"run_with_tz"
,
"requires_gzip"
,
"requires_bz2"
,
"requires_lzma"
,
"suppress_crash_popup"
,
"requires_gzip"
,
"requires_bz2"
,
"requires_lzma"
,
"suppress_crash_popup"
,
"SuppressCoreFiles"
,
]
]
class
Error
(
Exception
):
class
Error
(
Exception
):
...
@@ -2055,3 +2061,42 @@ def patch(test_instance, object_to_patch, attr_name, new_value):
...
@@ -2055,3 +2061,42 @@ def patch(test_instance, object_to_patch, attr_name, new_value):
# actually override the attribute
# actually override the attribute
setattr
(
object_to_patch
,
attr_name
,
new_value
)
setattr
(
object_to_patch
,
attr_name
,
new_value
)
class
SuppressCoreFiles
(
object
):
"""Try to prevent core files from being created."""
old_limit
=
None
def
__enter__
(
self
):
"""Try to save previous ulimit, then set the soft limit to 0."""
if
resource
is
not
None
:
try
:
self
.
old_limit
=
resource
.
getrlimit
(
resource
.
RLIMIT_CORE
)
resource
.
setrlimit
(
resource
.
RLIMIT_CORE
,
(
0
,
self
.
old_limit
[
1
]))
except
(
ValueError
,
OSError
):
pass
if
sys
.
platform
==
'darwin'
:
# Check if the 'Crash Reporter' on OSX was configured
# in 'Developer' mode and warn that it will get triggered
# when it is.
#
# This assumes that this context manager is used in tests
# that might trigger the next manager.
value
=
subprocess
.
Popen
([
'/usr/bin/defaults'
,
'read'
,
'com.apple.CrashReporter'
,
'DialogType'
],
stdout
=
subprocess
.
PIPE
)
.
communicate
()[
0
]
if
value
.
strip
()
==
b
'developer'
:
print
(
"this test triggers the Crash Reporter, "
"that is intentional"
,
end
=
''
)
sys
.
stdout
.
flush
()
def
__exit__
(
self
,
*
ignore_exc
):
"""Return core file behavior to default."""
if
self
.
old_limit
is
None
:
return
if
resource
is
not
None
:
try
:
resource
.
setrlimit
(
resource
.
RLIMIT_CORE
,
self
.
old_limit
)
except
(
ValueError
,
OSError
):
pass
Lib/test/test_subprocess.py
Dosyayı görüntüle @
b0478b3f
...
@@ -18,10 +18,6 @@ import shutil
...
@@ -18,10 +18,6 @@ import shutil
import
gc
import
gc
import
textwrap
import
textwrap
try
:
import
resource
except
ImportError
:
resource
=
None
try
:
try
:
import
threading
import
threading
except
ImportError
:
except
ImportError
:
...
@@ -1147,47 +1143,6 @@ class ProcessTestCase(BaseTestCase):
...
@@ -1147,47 +1143,6 @@ class ProcessTestCase(BaseTestCase):
fds_after_exception
=
os
.
listdir
(
fd_directory
)
fds_after_exception
=
os
.
listdir
(
fd_directory
)
self
.
assertEqual
(
fds_before_popen
,
fds_after_exception
)
self
.
assertEqual
(
fds_before_popen
,
fds_after_exception
)
# context manager
class
_SuppressCoreFiles
(
object
):
"""Try to prevent core files from being created."""
old_limit
=
None
def
__enter__
(
self
):
"""Try to save previous ulimit, then set it to (0, 0)."""
if
resource
is
not
None
:
try
:
self
.
old_limit
=
resource
.
getrlimit
(
resource
.
RLIMIT_CORE
)
resource
.
setrlimit
(
resource
.
RLIMIT_CORE
,
(
0
,
self
.
old_limit
[
1
]))
except
(
ValueError
,
resource
.
error
):
pass
if
sys
.
platform
==
'darwin'
:
# Check if the 'Crash Reporter' on OSX was configured
# in 'Developer' mode and warn that it will get triggered
# when it is.
#
# This assumes that this context manager is used in tests
# that might trigger the next manager.
value
=
subprocess
.
Popen
([
'/usr/bin/defaults'
,
'read'
,
'com.apple.CrashReporter'
,
'DialogType'
],
stdout
=
subprocess
.
PIPE
)
.
communicate
()[
0
]
if
value
.
strip
()
==
b
'developer'
:
print
(
"this tests triggers the Crash Reporter, "
"that is intentional"
,
end
=
''
)
sys
.
stdout
.
flush
()
def
__exit__
(
self
,
*
args
):
"""Return core file behavior to default."""
if
self
.
old_limit
is
None
:
return
if
resource
is
not
None
:
try
:
resource
.
setrlimit
(
resource
.
RLIMIT_CORE
,
self
.
old_limit
)
except
(
ValueError
,
resource
.
error
):
pass
@unittest.skipIf
(
mswindows
,
"POSIX specific tests"
)
@unittest.skipIf
(
mswindows
,
"POSIX specific tests"
)
class
POSIXProcessTestCase
(
BaseTestCase
):
class
POSIXProcessTestCase
(
BaseTestCase
):
...
@@ -1276,7 +1231,7 @@ class POSIXProcessTestCase(BaseTestCase):
...
@@ -1276,7 +1231,7 @@ class POSIXProcessTestCase(BaseTestCase):
def
test_run_abort
(
self
):
def
test_run_abort
(
self
):
# returncode handles signal termination
# returncode handles signal termination
with
_
SuppressCoreFiles
():
with
support
.
SuppressCoreFiles
():
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
'import os; os.abort()'
])
'import os; os.abort()'
])
p
.
wait
()
p
.
wait
()
...
...
Lib/test/test_support.py
Dosyayı görüntüle @
b0478b3f
...
@@ -306,6 +306,7 @@ class TestSupport(unittest.TestCase):
...
@@ -306,6 +306,7 @@ class TestSupport(unittest.TestCase):
# args_from_interpreter_flags
# args_from_interpreter_flags
# can_symlink
# can_symlink
# skip_unless_symlink
# skip_unless_symlink
# SuppressCoreFiles
def
test_main
():
def
test_main
():
...
...
Misc/NEWS
Dosyayı görüntüle @
b0478b3f
...
@@ -202,6 +202,9 @@ Library
...
@@ -202,6 +202,9 @@ Library
Tests
Tests
-----
-----
-
Issue
#
18623
:
Factor
out
the
_SuppressCoreFiles
context
manager
into
test
.
support
.
Patch
by
Valerie
Lambert
.
-
Issue
#
12037
:
Fix
test_email
for
desktop
Windows
.
-
Issue
#
12037
:
Fix
test_email
for
desktop
Windows
.
-
Issue
#
15507
:
test_subprocess
's test_send_signal could fail if the test
-
Issue
#
15507
:
test_subprocess
's test_send_signal could fail if the test
...
...
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