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
9f7d591b
Commit
9f7d591b
authored
May 05, 2012
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test__fileobject.py: add more tests
parent
a0c91f9b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
6 deletions
+83
-6
greentest/test__fileobject.py
greentest/test__fileobject.py
+83
-6
No files found.
greentest/test__fileobject.py
View file @
9f7d591b
import
os
import
sys
import
greentest
from
gevent.fileobject
import
SocketAdapter
,
FileObjectPosix
import
gevent
from
gevent.fileobject
import
FileObject
,
FileObjectThreadPool
class
Test
(
greentest
.
TestCase
):
def
_test_del
(
self
,
**
kwargs
):
r
,
w
=
os
.
pipe
()
s
=
FileObject
(
w
,
'wb'
)
s
.
write
(
'x'
)
s
.
flush
()
del
s
try
:
os
.
close
(
w
)
except
OSError
:
pass
# expected, because SocketAdapter already closed it
else
:
raise
AssertionError
(
'os.close(%r) must not succeed'
%
w
)
self
.
assertEqual
(
FileObject
(
r
).
read
(),
'x'
)
def
test_del
(
self
):
self
.
_test_del
()
def
test_del_close
(
self
):
self
.
_test_del
(
close
=
True
)
if
FileObject
is
not
FileObjectThreadPool
:
def
test_del_noclose
(
self
):
r
,
w
=
os
.
pipe
()
s
=
FileObject
(
w
,
'wb'
,
close
=
False
)
s
.
write
(
'x'
)
s
.
flush
()
del
s
os
.
close
(
w
)
self
.
assertEqual
(
FileObject
(
r
).
read
(),
'x'
)
def
test_newlines
(
self
):
r
,
w
=
os
.
pipe
()
lines
=
[
'line1
\
n
'
,
'line2
\
r
'
,
'line3
\
r
\
n
'
,
'line4
\
r
\
n
line5'
,
'
\
n
line6'
]
g
=
gevent
.
spawn
(
writer
,
FileObject
(
w
,
'wb'
),
lines
)
try
:
result
=
FileObject
(
r
,
'rU'
).
read
()
self
.
assertEqual
(
'line1
\
n
line2
\
n
line3
\
n
line4
\
n
line5
\
n
line6'
,
result
)
finally
:
g
.
kill
()
def
writer
(
fobj
,
line
):
for
character
in
line
:
fobj
.
write
(
character
)
fobj
.
flush
()
fobj
.
close
()
try
:
from
gevent.fileobject
import
SocketAdapter
except
ImportError
:
pass
else
:
class
TestSocketAdapter
(
greentest
.
TestCase
):
def
_test_del
(
self
,
**
kwargs
):
r
,
w
=
os
.
pipe
()
s
=
SocketAdapter
(
w
)
s
.
sendall
(
'x'
)
del
s
self
.
assertEqual
(
FileObjectPosix
(
r
).
read
(),
'x'
)
try
:
os
.
close
(
w
)
except
OSError
:
pass
# expected, because SocketAdapter already closed it
else
:
raise
AssertionError
(
'os.close(%r) must not succeed'
%
w
)
self
.
assertEqual
(
FileObject
(
r
).
read
(),
'x'
)
def
test_del
(
self
):
self
.
_test_del
()
def
test_del_close
(
self
):
self
.
_test_del
(
close
=
True
)
def
test_del_noclose
(
self
):
r
,
w
=
os
.
pipe
()
s
=
SocketAdapter
(
w
,
close
=
False
)
s
.
sendall
(
'x'
)
del
s
os
.
close
(
w
)
self
.
assertEqual
(
FileObject
(
r
).
read
(),
'x'
)
if
__name__
==
'__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