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
8bd24fe9
Kaydet (Commit)
8bd24fe9
authored
Agu 20, 2012
tarafından
Nick Coghlan
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #12643: Respect sys.excepthook in code.InteractiveConsole
üst
c0c03be5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
5 deletions
+91
-5
code.py
Lib/code.py
+15
-4
test_code_module.py
Lib/test/test_code_module.py
+72
-0
test_sundry.py
Lib/test/test_sundry.py
+0
-1
ACKS
Misc/ACKS
+1
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/code.py
Dosyayı görüntüle @
8bd24fe9
...
...
@@ -105,9 +105,10 @@ class InteractiveInterpreter:
The output is written by self.write(), below.
"""
type
,
value
,
sys
.
last_traceback
=
sys
.
exc_info
()
type
,
value
,
tb
=
sys
.
exc_info
()
sys
.
last_type
=
type
sys
.
last_value
=
value
sys
.
last_traceback
=
tb
if
filename
and
type
is
SyntaxError
:
# Work hard to stuff the correct filename in the exception
try
:
...
...
@@ -119,8 +120,13 @@ class InteractiveInterpreter:
# Stuff in the right filename
value
=
SyntaxError
(
msg
,
(
filename
,
lineno
,
offset
,
line
))
sys
.
last_value
=
value
lines
=
traceback
.
format_exception_only
(
type
,
value
)
self
.
write
(
''
.
join
(
lines
))
if
sys
.
excepthook
is
sys
.
__excepthook__
:
lines
=
traceback
.
format_exception_only
(
type
,
value
)
self
.
write
(
''
.
join
(
lines
))
else
:
# If someone has set sys.excepthook, we let that take precedence
# over self.write
sys
.
excepthook
(
type
,
value
,
tb
)
def
showtraceback
(
self
):
"""Display the exception that just occurred.
...
...
@@ -143,7 +149,12 @@ class InteractiveInterpreter:
lines
.
extend
(
traceback
.
format_exception_only
(
type
,
value
))
finally
:
tblist
=
tb
=
None
self
.
write
(
''
.
join
(
lines
))
if
sys
.
excepthook
is
sys
.
__excepthook__
:
self
.
write
(
''
.
join
(
lines
))
else
:
# If someone has set sys.excepthook, we let that take precedence
# over self.write
sys
.
excepthook
(
type
,
value
,
tb
)
def
write
(
self
,
data
):
"""Write a string.
...
...
Lib/test/test_code_module.py
0 → 100644
Dosyayı görüntüle @
8bd24fe9
"Test InteractiveConsole and InteractiveInterpreter from code module"
import
sys
import
unittest
from
contextlib
import
ExitStack
from
unittest
import
mock
from
test
import
support
code
=
support
.
import_module
(
'code'
)
class
TestInteractiveConsole
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
console
=
code
.
InteractiveConsole
()
self
.
mock_sys
()
def
mock_sys
(
self
):
"Mock system environment for InteractiveConsole"
# use exit stack to match patch context managers to addCleanup
stack
=
ExitStack
()
self
.
addCleanup
(
stack
.
close
)
self
.
infunc
=
stack
.
enter_context
(
mock
.
patch
(
'code.input'
,
create
=
True
))
self
.
stdout
=
stack
.
enter_context
(
mock
.
patch
(
'code.sys.stdout'
))
self
.
stderr
=
stack
.
enter_context
(
mock
.
patch
(
'code.sys.stderr'
))
prepatch
=
mock
.
patch
(
'code.sys'
,
wraps
=
code
.
sys
,
spec
=
code
.
sys
)
self
.
sysmod
=
stack
.
enter_context
(
prepatch
)
if
sys
.
excepthook
is
sys
.
__excepthook__
:
self
.
sysmod
.
excepthook
=
self
.
sysmod
.
__excepthook__
def
test_ps1
(
self
):
self
.
infunc
.
side_effect
=
EOFError
(
'Finished'
)
self
.
console
.
interact
()
self
.
assertEqual
(
self
.
sysmod
.
ps1
,
'>>> '
)
def
test_ps2
(
self
):
self
.
infunc
.
side_effect
=
EOFError
(
'Finished'
)
self
.
console
.
interact
()
self
.
assertEqual
(
self
.
sysmod
.
ps2
,
'... '
)
def
test_console_stderr
(
self
):
self
.
infunc
.
side_effect
=
[
"'antioch'"
,
""
,
EOFError
(
'Finished'
)]
self
.
console
.
interact
()
for
call
in
list
(
self
.
stdout
.
method_calls
):
if
'antioch'
in
''
.
join
(
call
[
1
]):
break
else
:
raise
AssertionError
(
"no console stdout"
)
def
test_syntax_error
(
self
):
self
.
infunc
.
side_effect
=
[
"undefined"
,
EOFError
(
'Finished'
)]
self
.
console
.
interact
()
for
call
in
self
.
stderr
.
method_calls
:
if
'NameError:'
in
''
.
join
(
call
[
1
]):
break
else
:
raise
AssertionError
(
"No syntax error from console"
)
def
test_sysexcepthook
(
self
):
self
.
infunc
.
side_effect
=
[
"raise ValueError('')"
,
EOFError
(
'Finished'
)]
hook
=
mock
.
Mock
()
self
.
sysmod
.
excepthook
=
hook
self
.
console
.
interact
()
self
.
assertTrue
(
hook
.
called
)
def
test_main
():
support
.
run_unittest
(
TestInteractiveConsole
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Lib/test/test_sundry.py
Dosyayı görüntüle @
8bd24fe9
...
...
@@ -9,7 +9,6 @@ class TestUntestedModules(unittest.TestCase):
with
support
.
check_warnings
(
quiet
=
True
):
import
bdb
import
cgitb
import
code
import
distutils.bcppcompiler
import
distutils.ccompiler
...
...
Misc/ACKS
Dosyayı görüntüle @
8bd24fe9
...
...
@@ -487,6 +487,7 @@ Fredrik Håård
Catalin Iacob
Mihai Ibanescu
Ali Ikinci
Aaron Iles
Lars Immisch
Bobby Impollonia
Meador Inge
...
...
Misc/NEWS
Dosyayı görüntüle @
8bd24fe9
...
...
@@ -19,6 +19,9 @@ Core and Builtins
Library
-------
- Issue #12643: code.InteractiveConsole now respects sys.excepthook when
displaying exceptions (Patch by Aaron Iles)
- Issue #13579: string.Formatter now understands the '
a
' conversion specifier.
- Issue #15595: Fix subprocess.Popen(universal_newlines=True)
...
...
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