Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
d221f870
Commit
d221f870
authored
May 05, 2012
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test__subprocess.py: add a few more regression tests
parent
a961638c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
12 deletions
+72
-12
greentest/test__subprocess.py
greentest/test__subprocess.py
+72
-12
No files found.
greentest/test__subprocess.py
View file @
d221f870
import
sys
import
os
import
greentest
import
time
from
gevent
import
subprocess
,
sleep
from
gevent
import
subprocess
if
subprocess
.
mswindows
:
SETBINARY
=
(
'import msvcrt; msvcrt.setmode(sys.stdout.fileno(), '
'os.O_BINARY);'
)
else
:
SETBINARY
=
''
class
Test
(
greentest
.
TestCase
):
...
...
@@ -19,16 +25,14 @@ class Test(greentest.TestCase):
else
:
raise
AssertionError
(
'Expected OSError: [Errno 2] No such file or directory'
)
if
os
.
path
.
exists
(
'/proc'
):
def
test_leak
(
self
):
fd_directory
=
'/proc/%d/fd'
%
os
.
getpid
()
num_before
=
len
(
os
.
listdir
(
fd_directory
))
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
"print()"
],
stdout
=
subprocess
.
PIPE
)
p
.
wait
()
del
p
num_after
=
len
(
os
.
listdir
(
fd_directory
))
self
.
assertEqual
(
num_before
,
num_after
)
def
test_leak
(
self
):
num_before
=
greentest
.
get_number_open_files
()
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
"print()"
],
stdout
=
subprocess
.
PIPE
)
p
.
wait
()
del
p
num_after
=
greentest
.
get_number_open_files
()
self
.
assertEqual
(
num_before
,
num_after
)
def
test_communicate
(
self
):
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
...
...
@@ -45,6 +49,62 @@ class Test(greentest.TestCase):
else
:
self
.
assertEqual
(
stderr
,
"pineapple"
)
def
test_universal1
(
self
):
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
'import sys,os;'
+
SETBINARY
+
'sys.stdout.write("line1
\
\
n");'
'sys.stdout.flush();'
'sys.stdout.write("line2
\
\
r");'
'sys.stdout.flush();'
'sys.stdout.write("line3
\
\
r
\
\
n");'
'sys.stdout.flush();'
'sys.stdout.write("line4
\
\
r");'
'sys.stdout.flush();'
'sys.stdout.write("
\
\
nline5");'
'sys.stdout.flush();'
'sys.stdout.write("
\
\
nline6");'
],
stdout
=
subprocess
.
PIPE
,
universal_newlines
=
1
)
try
:
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"
)
finally
:
p
.
stdout
.
close
()
def
test_universal2
(
self
):
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
'import sys,os;'
+
SETBINARY
+
'sys.stdout.write("line1
\
\
n");'
'sys.stdout.flush();'
'sys.stdout.write("line2
\
\
r");'
'sys.stdout.flush();'
'sys.stdout.write("line3
\
\
r
\
\
n");'
'sys.stdout.flush();'
'sys.stdout.write("line4
\
\
r
\
\
nline5");'
'sys.stdout.flush();'
'sys.stdout.write("
\
\
nline6");'
],
stdout
=
subprocess
.
PIPE
,
universal_newlines
=
1
)
try
:
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"
)
finally
:
p
.
stdout
.
close
()
if
__name__
==
'__main__'
:
greentest
.
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