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
772add7e
Kaydet (Commit)
772add7e
authored
Kas 06, 2011
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Try to make the tty input() tests more robust
üst
5ee9d8a8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
21 deletions
+31
-21
test_builtin.py
Lib/test/test_builtin.py
+31
-21
No files found.
Lib/test/test_builtin.py
Dosyayı görüntüle @
772add7e
...
@@ -11,12 +11,13 @@ import ast
...
@@ -11,12 +11,13 @@ import ast
import
types
import
types
import
builtins
import
builtins
import
random
import
random
import
traceback
from
test.support
import
TESTFN
,
unlink
,
run_unittest
,
check_warnings
from
test.support
import
TESTFN
,
unlink
,
run_unittest
,
check_warnings
from
operator
import
neg
from
operator
import
neg
try
:
try
:
import
pty
import
pty
,
signal
except
ImportError
:
except
ImportError
:
pty
=
None
pty
=
signal
=
None
class
Squares
:
class
Squares
:
...
@@ -1005,7 +1006,7 @@ class BuiltinTest(unittest.TestCase):
...
@@ -1005,7 +1006,7 @@ class BuiltinTest(unittest.TestCase):
fp
.
close
()
fp
.
close
()
unlink
(
TESTFN
)
unlink
(
TESTFN
)
@unittest.skipUnless
(
pty
,
"the pty
module isn't
available"
)
@unittest.skipUnless
(
pty
,
"the pty
and signal modules must be
available"
)
def
check_input_tty
(
self
,
prompt
,
terminal_input
,
stdio_encoding
=
None
):
def
check_input_tty
(
self
,
prompt
,
terminal_input
,
stdio_encoding
=
None
):
r
,
w
=
os
.
pipe
()
r
,
w
=
os
.
pipe
()
try
:
try
:
...
@@ -1016,23 +1017,26 @@ class BuiltinTest(unittest.TestCase):
...
@@ -1016,23 +1017,26 @@ class BuiltinTest(unittest.TestCase):
self
.
skipTest
(
"pty.fork() raised {}"
.
format
(
e
))
self
.
skipTest
(
"pty.fork() raised {}"
.
format
(
e
))
if
pid
==
0
:
if
pid
==
0
:
# Child
# Child
os
.
close
(
r
)
try
:
# Check the error handlers are accounted for
# Make sure we don't get stuck if there's a problem
if
stdio_encoding
:
signal
.
alarm
(
2
)
sys
.
stdin
=
io
.
TextIOWrapper
(
sys
.
stdin
.
detach
(),
os
.
close
(
r
)
encoding
=
stdio_encoding
,
# Check the error handlers are accounted for
errors
=
'surrogateescape'
)
if
stdio_encoding
:
sys
.
stdout
=
io
.
TextIOWrapper
(
sys
.
stdout
.
detach
(),
sys
.
stdin
=
io
.
TextIOWrapper
(
sys
.
stdin
.
detach
(),
encoding
=
stdio_encoding
,
encoding
=
stdio_encoding
,
errors
=
'replace'
)
errors
=
'surrogateescape'
)
with
open
(
w
,
"w"
)
as
wpipe
:
sys
.
stdout
=
io
.
TextIOWrapper
(
sys
.
stdout
.
detach
(),
try
:
encoding
=
stdio_encoding
,
errors
=
'replace'
)
with
open
(
w
,
"w"
)
as
wpipe
:
print
(
"tty ="
,
sys
.
stdin
.
isatty
()
and
sys
.
stdout
.
isatty
(),
file
=
wpipe
)
print
(
"tty ="
,
sys
.
stdin
.
isatty
()
and
sys
.
stdout
.
isatty
(),
file
=
wpipe
)
print
(
ascii
(
input
(
prompt
)),
file
=
wpipe
)
print
(
ascii
(
input
(
prompt
)),
file
=
wpipe
)
finally
:
except
:
print
(
";EOF"
,
file
=
wpipe
)
traceback
.
print_exc
()
# We don't want to return to unittest...
finally
:
os
.
_exit
(
0
)
# We don't want to return to unittest...
os
.
_exit
(
0
)
# Parent
# Parent
os
.
close
(
w
)
os
.
close
(
w
)
os
.
write
(
fd
,
terminal_input
+
b
"
\r\n
"
)
os
.
write
(
fd
,
terminal_input
+
b
"
\r\n
"
)
...
@@ -1041,15 +1045,21 @@ class BuiltinTest(unittest.TestCase):
...
@@ -1041,15 +1045,21 @@ class BuiltinTest(unittest.TestCase):
lines
=
[]
lines
=
[]
while
True
:
while
True
:
line
=
rpipe
.
readline
()
.
strip
()
line
=
rpipe
.
readline
()
.
strip
()
if
line
==
";EOF"
:
if
line
==
""
:
# The other end was closed => the child exited
break
break
lines
.
append
(
line
)
lines
.
append
(
line
)
# Check the result was got and corresponds to the user's terminal input
if
len
(
lines
)
!=
2
:
# Something went wrong, try to get at stderr
with
open
(
fd
,
"r"
,
encoding
=
"ascii"
,
errors
=
"ignore"
)
as
child_output
:
self
.
fail
(
"got
%
d lines in pipe but expected 2, child output was:
\n
%
s"
%
(
len
(
lines
),
child_output
.
read
()))
os
.
close
(
fd
)
# Check we did exercise the GNU readline path
# Check we did exercise the GNU readline path
self
.
assertIn
(
lines
[
0
],
{
'tty = True'
,
'tty = False'
})
self
.
assertIn
(
lines
[
0
],
{
'tty = True'
,
'tty = False'
})
if
lines
[
0
]
!=
'tty = True'
:
if
lines
[
0
]
!=
'tty = True'
:
self
.
skipTest
(
"standard IO in should have been a tty"
)
self
.
skipTest
(
"standard IO in should have been a tty"
)
# Check the result was got and corresponds to the user's terminal input
self
.
assertEqual
(
len
(
lines
),
2
)
input_result
=
eval
(
lines
[
1
])
# ascii() -> eval() roundtrip
input_result
=
eval
(
lines
[
1
])
# ascii() -> eval() roundtrip
if
stdio_encoding
:
if
stdio_encoding
:
expected
=
terminal_input
.
decode
(
stdio_encoding
,
'surrogateescape'
)
expected
=
terminal_input
.
decode
(
stdio_encoding
,
'surrogateescape'
)
...
...
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