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
d1da29c9
Commit
d1da29c9
authored
Jan 29, 2013
by
Michael Foord
Browse files
Options
Browse Files
Download
Plain Diff
Merge
parents
bd41d1b1
6debd769
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
1 deletion
+50
-1
Lib/unittest/signals.py
Lib/unittest/signals.py
+15
-1
Lib/unittest/test/test_break.py
Lib/unittest/test/test_break.py
+32
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/unittest/signals.py
View file @
d1da29c9
...
...
@@ -9,6 +9,20 @@ __unittest = True
class
_InterruptHandler
(
object
):
def
__init__
(
self
,
default_handler
):
self
.
called
=
False
self
.
original_handler
=
default_handler
if
isinstance
(
default_handler
,
int
):
if
default_handler
==
signal
.
SIG_DFL
:
# Pretend it's signal.default_int_handler instead.
default_handler
=
signal
.
default_int_handler
elif
default_handler
==
signal
.
SIG_IGN
:
# Not quite the same thing as SIG_IGN, but the closest we
# can make it: do nothing.
def
default_handler
(
unused_signum
,
unused_frame
):
pass
else
:
raise
TypeError
(
"expected SIGINT signal handler to be "
"signal.SIG_IGN, signal.SIG_DFL, or a "
"callable object"
)
self
.
default_handler
=
default_handler
def
__call__
(
self
,
signum
,
frame
):
...
...
@@ -54,4 +68,4 @@ def removeHandler(method=None):
global
_interrupt_handler
if
_interrupt_handler
is
not
None
:
signal
.
signal
(
signal
.
SIGINT
,
_interrupt_handler
.
default
_handler
)
signal
.
signal
(
signal
.
SIGINT
,
_interrupt_handler
.
original
_handler
)
Lib/unittest/test/test_break.py
View file @
d1da29c9
...
...
@@ -13,9 +13,12 @@ import unittest
@
unittest
.
skipIf
(
sys
.
platform
==
'freebsd6'
,
"Test kills regrtest on freebsd6 "
"if threads have been used"
)
class
TestBreak
(
unittest
.
TestCase
):
int_handler
=
None
def
setUp
(
self
):
self
.
_default_handler
=
signal
.
getsignal
(
signal
.
SIGINT
)
if
self
.
int_handler
is
not
None
:
signal
.
signal
(
signal
.
SIGINT
,
self
.
int_handler
)
def
tearDown
(
self
):
signal
.
signal
(
signal
.
SIGINT
,
self
.
_default_handler
)
...
...
@@ -72,6 +75,10 @@ class TestBreak(unittest.TestCase):
def
testSecondInterrupt
(
self
):
# Can't use skipIf decorator because the signal handler may have
# been changed after defining this method.
if
signal
.
getsignal
(
signal
.
SIGINT
)
==
signal
.
SIG_IGN
:
self
.
skipTest
(
"test requires SIGINT to not be ignored"
)
result
=
unittest
.
TestResult
()
unittest
.
installHandler
()
unittest
.
registerResult
(
result
)
...
...
@@ -121,6 +128,10 @@ class TestBreak(unittest.TestCase):
def
testHandlerReplacedButCalled
(
self
):
# Can't use skipIf decorator because the signal handler may have
# been changed after defining this method.
if
signal
.
getsignal
(
signal
.
SIGINT
)
==
signal
.
SIG_IGN
:
self
.
skipTest
(
"test requires SIGINT to not be ignored"
)
# If our handler has been replaced (is no longer installed) but is
# called by the *new* handler, then it isn't safe to delay the
# SIGINT and we should immediately delegate to the default handler
...
...
@@ -250,3 +261,24 @@ class TestBreak(unittest.TestCase):
test
()
self
.
assertNotEqual
(
signal
.
getsignal
(
signal
.
SIGINT
),
default_handler
)
@
unittest
.
skipUnless
(
hasattr
(
os
,
'kill'
),
"Test requires os.kill"
)
@
unittest
.
skipIf
(
sys
.
platform
==
"win32"
,
"Test cannot run on Windows"
)
@
unittest
.
skipIf
(
sys
.
platform
==
'freebsd6'
,
"Test kills regrtest on freebsd6 "
"if threads have been used"
)
class
TestBreakDefaultIntHandler
(
TestBreak
):
int_handler
=
signal
.
default_int_handler
@
unittest
.
skipUnless
(
hasattr
(
os
,
'kill'
),
"Test requires os.kill"
)
@
unittest
.
skipIf
(
sys
.
platform
==
"win32"
,
"Test cannot run on Windows"
)
@
unittest
.
skipIf
(
sys
.
platform
==
'freebsd6'
,
"Test kills regrtest on freebsd6 "
"if threads have been used"
)
class
TestBreakSignalIgnored
(
TestBreak
):
int_handler
=
signal
.
SIG_IGN
@
unittest
.
skipUnless
(
hasattr
(
os
,
'kill'
),
"Test requires os.kill"
)
@
unittest
.
skipIf
(
sys
.
platform
==
"win32"
,
"Test cannot run on Windows"
)
@
unittest
.
skipIf
(
sys
.
platform
==
'freebsd6'
,
"Test kills regrtest on freebsd6 "
"if threads have been used"
)
class
TestBreakSignalDefault
(
TestBreak
):
int_handler
=
signal
.
SIG_DFL
Misc/NEWS
View file @
d1da29c9
...
...
@@ -173,6 +173,9 @@ Library
- Issue #1602133: on Mac OS X a shared library build (``--enable-shared``)
now fills the ``os.environ`` variable correctly.
- Issue #15505: `unittest.installHandler` no longer assumes SIGINT handler is
set to a callable object.
- Issue #9290: In IDLE the sys.std* streams now implement io.TextIOBase
interface and support all mandatory methods and properties.
...
...
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