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
c9e363c2
Kaydet (Commit)
c9e363c2
authored
May 15, 2007
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Make test_subprocess pass. The subprocess module now reads and writes
bytes instead of strings. We'll see how long that lasts.
üst
af2362a5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
27 deletions
+16
-27
subprocess.py
Lib/subprocess.py
+8
-6
test_subprocess.py
Lib/test/test_subprocess.py
+8
-21
No files found.
Lib/subprocess.py
Dosyayı görüntüle @
c9e363c2
...
...
@@ -830,7 +830,7 @@ class Popen(object):
# object do the translation: It is based on stdio, which is
# impossible to combine with select (unless forcing no
# buffering).
if
self
.
universal_newlines
and
hasattr
(
file
,
'newlines'
)
:
if
self
.
universal_newlines
:
if
stdout
:
stdout
=
self
.
_translate_newlines
(
stdout
)
if
stderr
:
...
...
@@ -1044,6 +1044,8 @@ class Popen(object):
def
_communicate
(
self
,
input
):
if
isinstance
(
input
,
str
):
# Unicode
input
=
input
.
encode
(
"utf-8"
)
# XXX What else?
read_set
=
[]
write_set
=
[]
stdout
=
None
# Return
...
...
@@ -1080,29 +1082,29 @@ class Popen(object):
if
self
.
stdout
in
rlist
:
data
=
os
.
read
(
self
.
stdout
.
fileno
(),
1024
)
if
data
==
""
:
if
not
data
:
self
.
stdout
.
close
()
read_set
.
remove
(
self
.
stdout
)
stdout
.
append
(
data
)
if
self
.
stderr
in
rlist
:
data
=
os
.
read
(
self
.
stderr
.
fileno
(),
1024
)
if
data
==
""
:
if
not
data
:
self
.
stderr
.
close
()
read_set
.
remove
(
self
.
stderr
)
stderr
.
append
(
data
)
# All data exchanged. Translate lists into strings.
if
stdout
is
not
None
:
stdout
=
''
.
join
(
stdout
)
stdout
=
b
''
.
join
(
stdout
)
if
stderr
is
not
None
:
stderr
=
''
.
join
(
stderr
)
stderr
=
b
''
.
join
(
stderr
)
# Translate newlines, if requested. We cannot let the file
# object do the translation: It is based on stdio, which is
# impossible to combine with select (unless forcing no
# buffering).
if
self
.
universal_newlines
and
hasattr
(
file
,
'newlines'
)
:
if
self
.
universal_newlines
:
if
stdout
:
stdout
=
self
.
_translate_newlines
(
stdout
)
if
stderr
:
...
...
Lib/test/test_subprocess.py
Dosyayı görüntüle @
c9e363c2
...
...
@@ -24,7 +24,7 @@ else:
# shutdown time. That frustrates tests trying to check stderr produced
# from a spawned Python process.
def
remove_stderr_debug_decorations
(
stderr
):
return
re
.
sub
(
r"\[\d+ refs\]\r?\n?$"
,
""
,
st
derr
)
return
re
.
sub
(
r"\[\d+ refs\]\r?\n?$"
,
""
,
st
r8
(
stderr
)
)
class
ProcessTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
@@ -162,7 +162,7 @@ class ProcessTestCase(unittest.TestCase):
stdout
=
d
)
p
.
wait
()
os
.
lseek
(
d
,
0
,
0
)
self
.
assertEqual
(
os
.
read
(
d
,
1024
),
"orange"
)
self
.
assertEqual
(
os
.
read
(
d
,
1024
),
b
"orange"
)
def
test_stdout_fileobj
(
self
):
# stdout is set to open file object
...
...
@@ -300,7 +300,7 @@ class ProcessTestCase(unittest.TestCase):
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
(
stdout
,
stderr
)
=
p
.
communicate
(
"banana"
)
self
.
assertEqual
(
stdout
,
"banana"
)
self
.
assertEqual
(
stdout
,
b
"banana"
)
self
.
assertEqual
(
remove_stderr_debug_decorations
(
stderr
),
"pineapple"
)
...
...
@@ -331,7 +331,7 @@ class ProcessTestCase(unittest.TestCase):
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
string_to_write
=
"abc"
*
pipe_buf
string_to_write
=
b
"abc"
*
pipe_buf
(
stdout
,
stderr
)
=
p
.
communicate
(
string_to_write
)
self
.
assertEqual
(
stdout
,
string_to_write
)
...
...
@@ -345,7 +345,7 @@ class ProcessTestCase(unittest.TestCase):
stderr
=
subprocess
.
PIPE
)
p
.
stdin
.
write
(
"banana"
)
(
stdout
,
stderr
)
=
p
.
communicate
(
"split"
)
self
.
assertEqual
(
stdout
,
"bananasplit"
)
self
.
assertEqual
(
stdout
,
b
"bananasplit"
)
self
.
assertEqual
(
remove_stderr_debug_decorations
(
stderr
),
""
)
def
test_universal_newlines
(
self
):
...
...
@@ -365,14 +365,7 @@ class ProcessTestCase(unittest.TestCase):
stdout
=
subprocess
.
PIPE
,
universal_newlines
=
1
)
stdout
=
p
.
stdout
.
read
()
if
hasattr
(
file
,
'newlines'
):
# Interpreter with universal newline support
self
.
assertEqual
(
stdout
,
"line1
\n
line2
\n
line3
\n
line4
\n
line5
\n
line6"
)
else
:
# Interpreter without universal newline support
self
.
assertEqual
(
stdout
,
"line1
\n
line2
\r
line3
\r\n
line4
\r\n
line5
\n
line6"
)
self
.
assertEqual
(
stdout
,
"line1
\n
line2
\n
line3
\n
line4
\n
line5
\n
line6"
)
def
test_universal_newlines_communicate
(
self
):
# universal newlines through communicate()
...
...
@@ -392,13 +385,7 @@ class ProcessTestCase(unittest.TestCase):
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
universal_newlines
=
1
)
(
stdout
,
stderr
)
=
p
.
communicate
()
if
hasattr
(
file
,
'newlines'
):
# Interpreter with universal newline support
self
.
assertEqual
(
stdout
,
"line1
\n
line2
\n
line3
\n
line4
\n
line5
\n
line6"
)
else
:
# Interpreter without universal newline support
self
.
assertEqual
(
stdout
,
"line1
\n
line2
\r
line3
\r\n
line4
\r\n
line5
\n
line6"
)
self
.
assertEqual
(
stdout
,
b
"line1
\n
line2
\n
line3
\n
line4
\n
line5
\n
line6"
)
def
test_no_leaking
(
self
):
# Make sure we leak no resources
...
...
@@ -414,7 +401,7 @@ class ProcessTestCase(unittest.TestCase):
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
data
=
p
.
communicate
(
"lime"
)[
0
]
self
.
assertEqual
(
data
,
"lime"
)
self
.
assertEqual
(
data
,
b
"lime"
)
def
test_list2cmdline
(
self
):
...
...
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