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
1b4145db
Kaydet (Commit)
1b4145db
authored
Mar 16, 2007
tarafından
Collin Winter
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Patch #1676994: Refactor test_popen2 to use unittest.
üst
dd2cf1cb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
110 deletions
+82
-110
popen2.py
Lib/popen2.py
+0
-42
test_popen2.py
Lib/test/test_popen2.py
+82
-68
No files found.
Lib/popen2.py
Dosyayı görüntüle @
1b4145db
...
...
@@ -200,45 +200,3 @@ else:
return
inst
.
fromchild
,
inst
.
tochild
__all__
.
extend
([
"Popen3"
,
"Popen4"
])
def
_test
():
# When the test runs, there shouldn't be any open pipes
_cleanup
()
assert
not
_active
,
"Active pipes when test starts "
+
repr
([
c
.
cmd
for
c
in
_active
])
cmd
=
"cat"
teststr
=
"ab cd
\n
"
if
os
.
name
==
"nt"
:
cmd
=
"more"
# "more" doesn't act the same way across Windows flavors,
# sometimes adding an extra newline at the start or the
# end. So we strip whitespace off both ends for comparison.
expected
=
teststr
.
strip
()
print
"testing popen2..."
r
,
w
=
popen2
(
cmd
)
w
.
write
(
teststr
)
w
.
close
()
got
=
r
.
read
()
if
got
.
strip
()
!=
expected
:
raise
ValueError
(
"wrote
%
r read
%
r"
%
(
teststr
,
got
))
print
"testing popen3..."
try
:
r
,
w
,
e
=
popen3
([
cmd
])
except
:
r
,
w
,
e
=
popen3
(
cmd
)
w
.
write
(
teststr
)
w
.
close
()
got
=
r
.
read
()
if
got
.
strip
()
!=
expected
:
raise
ValueError
(
"wrote
%
r read
%
r"
%
(
teststr
,
got
))
got
=
e
.
read
()
if
got
:
raise
ValueError
(
"unexpected
%
r on stderr"
%
(
got
,))
for
inst
in
_active
[:]:
inst
.
wait
()
_cleanup
()
if
_active
:
raise
ValueError
(
"_active not empty"
)
print
"All OK"
if
__name__
==
'__main__'
:
_test
()
Lib/test/test_popen2.py
Dosyayı görüntüle @
1b4145db
#! /usr/bin/env python
"""Test script for popen2.py
Christian Tismer
"""
"""Test script for popen2.py"""
import
os
import
sys
from
test.test_support
import
TestSkipped
,
reap_children
# popen2 contains its own testing routine
# which is especially useful to see if open files
# like stdin can be read successfully by a forked
# subprocess.
def
main
():
print
"Test popen2 module:"
if
(
sys
.
platform
[:
4
]
==
'beos'
or
sys
.
platform
[:
6
]
==
'atheos'
)
\
and
__name__
!=
'__main__'
:
# Locks get messed up or something. Generally we're supposed
# to avoid mixing "posix" fork & exec with native threads, and
# they may be right about that after all.
raise
TestSkipped
,
"popen2() doesn't work during import on "
+
sys
.
platform
try
:
from
os
import
popen
except
ImportError
:
# if we don't have os.popen, check that
# we have os.fork. if not, skip the test
# (by raising an ImportError)
from
os
import
fork
import
popen2
popen2
.
_test
()
def
_test
():
# same test as popen2._test(), but using the os.popen*() API
print
"Testing os module:"
import
popen2
# When the test runs, there shouldn't be any open pipes
popen2
.
_cleanup
()
assert
not
popen2
.
_active
,
"Active pipes when test starts "
+
repr
([
c
.
cmd
for
c
in
popen2
.
_active
])
cmd
=
"cat"
teststr
=
"ab cd
\n
"
import
unittest
import
popen2
from
test.test_support
import
TestSkipped
,
run_unittest
,
reap_children
if
sys
.
platform
[:
4
]
==
'beos'
or
sys
.
platform
[:
6
]
==
'atheos'
:
# Locks get messed up or something. Generally we're supposed
# to avoid mixing "posix" fork & exec with native threads, and
# they may be right about that after all.
raise
TestSkipped
(
"popen2() doesn't work on "
+
sys
.
platform
)
# if we don't have os.popen, check that
# we have os.fork. if not, skip the test
# (by raising an ImportError)
try
:
from
os
import
popen
del
popen
except
ImportError
:
from
os
import
fork
del
fork
class
Popen2Test
(
unittest
.
TestCase
):
cmd
=
"cat"
if
os
.
name
==
"nt"
:
cmd
=
"more"
teststr
=
"ab cd
\n
"
# "more" doesn't act the same way across Windows flavors,
# sometimes adding an extra newline at the start or the
# end. So we strip whitespace off both ends for comparison.
expected
=
teststr
.
strip
()
print
"testing popen2..."
w
,
r
=
os
.
popen2
(
cmd
)
w
.
write
(
teststr
)
w
.
close
()
got
=
r
.
read
()
if
got
.
strip
()
!=
expected
:
raise
ValueError
(
"wrote
%
r read
%
r"
%
(
teststr
,
got
))
print
"testing popen3..."
try
:
w
,
r
,
e
=
os
.
popen3
([
cmd
])
except
:
w
,
r
,
e
=
os
.
popen3
(
cmd
)
w
.
write
(
teststr
)
w
.
close
()
got
=
r
.
read
()
if
got
.
strip
()
!=
expected
:
raise
ValueError
(
"wrote
%
r read
%
r"
%
(
teststr
,
got
))
got
=
e
.
read
()
if
got
:
raise
ValueError
(
"unexpected
%
r on stderr"
%
(
got
,))
for
inst
in
popen2
.
_active
[:]:
inst
.
wait
()
popen2
.
_cleanup
()
if
popen2
.
_active
:
raise
ValueError
(
"_active not empty"
)
print
"All OK"
main
()
_test
()
reap_children
()
def
setUp
(
self
):
popen2
.
_cleanup
()
# When the test runs, there shouldn't be any open pipes
self
.
assertFalse
(
popen2
.
_active
,
"Active pipes when test starts"
+
repr
([
c
.
cmd
for
c
in
popen2
.
_active
]))
def
tearDown
(
self
):
for
inst
in
popen2
.
_active
:
inst
.
wait
()
popen2
.
_cleanup
()
self
.
assertFalse
(
popen2
.
_active
,
"_active not empty"
)
reap_children
()
def
validate_output
(
self
,
teststr
,
expected_out
,
r
,
w
,
e
=
None
):
w
.
write
(
teststr
)
w
.
close
()
got
=
r
.
read
()
self
.
assertEquals
(
expected_out
,
got
.
strip
(),
"wrote
%
r read
%
r"
%
(
teststr
,
got
))
if
e
is
not
None
:
got
=
e
.
read
()
self
.
assertFalse
(
got
,
"unexpected
%
r on stderr"
%
got
)
def
test_popen2
(
self
):
r
,
w
=
popen2
.
popen2
(
self
.
cmd
)
self
.
validate_output
(
self
.
teststr
,
self
.
expected
,
r
,
w
)
def
test_popen3
(
self
):
if
os
.
name
==
'posix'
:
r
,
w
,
e
=
popen2
.
popen3
([
self
.
cmd
])
self
.
validate_output
(
self
.
teststr
,
self
.
expected
,
r
,
w
,
e
)
r
,
w
,
e
=
popen2
.
popen3
(
self
.
cmd
)
self
.
validate_output
(
self
.
teststr
,
self
.
expected
,
r
,
w
,
e
)
def
test_os_popen2
(
self
):
# same test as test_popen2(), but using the os.popen*() API
w
,
r
=
os
.
popen2
(
self
.
cmd
)
self
.
validate_output
(
self
.
teststr
,
self
.
expected
,
r
,
w
)
def
test_os_popen3
(
self
):
# same test as test_popen3(), but using the os.popen*() API
if
os
.
name
==
'posix'
:
w
,
r
,
e
=
os
.
popen3
([
self
.
cmd
])
self
.
validate_output
(
self
.
teststr
,
self
.
expected
,
r
,
w
,
e
)
w
,
r
,
e
=
os
.
popen3
(
self
.
cmd
)
self
.
validate_output
(
self
.
teststr
,
self
.
expected
,
r
,
w
,
e
)
def
test_main
():
run_unittest
(
Popen2Test
)
if
__name__
==
"__main__"
:
test_main
()
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