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
c36e504c
Kaydet (Commit)
c36e504c
authored
Şub 18, 2014
tarafından
Zachary Ware
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #20510: Merge with 3.3.
üst
8b21d91e
cefe6b34
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
53 deletions
+32
-53
test_sys.py
Lib/test/test_sys.py
+28
-53
NEWS
Misc/NEWS
+4
-0
No files found.
Lib/test/test_sys.py
Dosyayı görüntüle @
c36e504c
import
unittest
,
test
.
support
from
test.script_helper
import
assert_python_ok
,
assert_python_failure
import
sys
,
io
,
os
import
struct
import
subprocess
...
...
@@ -89,74 +90,50 @@ class SysModuleTest(unittest.TestCase):
# Python/pythonrun.c::PyErr_PrintEx() is tricky.
def
test_exit
(
self
):
# call with two arguments
self
.
assertRaises
(
TypeError
,
sys
.
exit
,
42
,
42
)
# call without argument
try
:
sys
.
exit
(
0
)
except
SystemExit
as
exc
:
self
.
assertEqual
(
exc
.
code
,
0
)
except
:
self
.
fail
(
"wrong exception"
)
else
:
self
.
fail
(
"no exception"
)
rc
,
out
,
err
=
assert_python_ok
(
'-c'
,
'import sys; sys.exit()'
)
self
.
assertEqual
(
rc
,
0
)
self
.
assertEqual
(
out
,
b
''
)
self
.
assertEqual
(
err
,
b
''
)
# call with tuple argument with one entry
# entry will be unpacked
try
:
# call with integer argument
with
self
.
assertRaises
(
SystemExit
)
as
cm
:
sys
.
exit
(
42
)
except
SystemExit
as
exc
:
self
.
assertEqual
(
exc
.
code
,
42
)
except
:
self
.
fail
(
"wrong exception"
)
else
:
self
.
fail
(
"no exception"
)
self
.
assertEqual
(
cm
.
exception
.
code
,
42
)
# call with integer argument
try
:
# call with tuple argument with one entry
# entry will be unpacked
with
self
.
assertRaises
(
SystemExit
)
as
cm
:
sys
.
exit
((
42
,))
except
SystemExit
as
exc
:
self
.
assertEqual
(
exc
.
code
,
42
)
except
:
self
.
fail
(
"wrong exception"
)
else
:
self
.
fail
(
"no exception"
)
self
.
assertEqual
(
cm
.
exception
.
code
,
42
)
# call with string argument
try
:
with
self
.
assertRaises
(
SystemExit
)
as
cm
:
sys
.
exit
(
"exit"
)
except
SystemExit
as
exc
:
self
.
assertEqual
(
exc
.
code
,
"exit"
)
except
:
self
.
fail
(
"wrong exception"
)
else
:
self
.
fail
(
"no exception"
)
self
.
assertEqual
(
cm
.
exception
.
code
,
"exit"
)
# call with tuple argument with two entries
try
:
with
self
.
assertRaises
(
SystemExit
)
as
cm
:
sys
.
exit
((
17
,
23
))
except
SystemExit
as
exc
:
self
.
assertEqual
(
exc
.
code
,
(
17
,
23
))
except
:
self
.
fail
(
"wrong exception"
)
else
:
self
.
fail
(
"no exception"
)
self
.
assertEqual
(
cm
.
exception
.
code
,
(
17
,
23
))
# test that the exit machinery handles SystemExits properly
rc
=
subprocess
.
call
([
sys
.
executable
,
"-c"
,
"raise SystemExit(47)"
])
rc
,
out
,
err
=
assert_python_failure
(
'-c'
,
'raise SystemExit(47)'
)
self
.
assertEqual
(
rc
,
47
)
self
.
assertEqual
(
out
,
b
''
)
self
.
assertEqual
(
err
,
b
''
)
def
check_exit_message
(
code
,
expected
,
env
=
None
):
process
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
code
],
stderr
=
subprocess
.
PIPE
,
env
=
env
)
stdout
,
stderr
=
process
.
communicate
()
self
.
assertEqual
(
process
.
returncode
,
1
)
self
.
assertTrue
(
stderr
.
startswith
(
expected
),
"
%
s doesn't start with
%
s"
%
(
ascii
(
stderr
),
ascii
(
expected
)))
def
check_exit_message
(
code
,
expected
,
**
env_vars
):
rc
,
out
,
err
=
assert_python_failure
(
'-c'
,
code
,
**
env_vars
)
self
.
assertEqual
(
rc
,
1
)
self
.
assertEqual
(
out
,
b
''
)
self
.
assertTrue
(
err
.
startswith
(
expected
),
"
%
s doesn't start with
%
s"
%
(
ascii
(
err
),
ascii
(
expected
)))
# test that stderr buffer i
f
flushed before the exit message is written
# test that stderr buffer i
s
flushed before the exit message is written
# into stderr
check_exit_message
(
r'import sys; sys.stderr.write("unflushed,"); sys.exit("message")'
,
...
...
@@ -170,11 +147,9 @@ class SysModuleTest(unittest.TestCase):
# test that the unicode message is encoded to the stderr encoding
# instead of the default encoding (utf8)
env
=
os
.
environ
.
copy
()
env
[
'PYTHONIOENCODING'
]
=
'latin-1'
check_exit_message
(
r'import sys; sys.exit("h\xe9")'
,
b
"h
\xe9
"
,
env
=
env
)
b
"h
\xe9
"
,
PYTHONIOENCODING
=
'latin-1'
)
def
test_getdefaultencoding
(
self
):
self
.
assertRaises
(
TypeError
,
sys
.
getdefaultencoding
,
42
)
...
...
Misc/NEWS
Dosyayı görüntüle @
c36e504c
...
...
@@ -51,6 +51,10 @@ Library
Tests
-----
-
Issue
#
20510
:
Rewrote
test_exit
in
test_sys
to
match
existing
comments
,
use
modern
unittest
features
,
and
use
helpers
from
test
.
script_helper
instead
of
using
subprocess
directly
.
Patch
by
Gareth
Rees
.
-
Issue
#
20605
:
Make
test_socket
getaddrinfo
OS
X
segfault
test
more
robust
.
...
...
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