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
c34abdc0
Commit
c34abdc0
authored
Jan 13, 2020
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Let tests run without having gevent installed, just on pythonpath. Fixes #1409
parent
c0c91a5d
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
227 additions
and
107 deletions
+227
-107
src/gevent/baseserver.py
src/gevent/baseserver.py
+7
-4
src/gevent/testing/util.py
src/gevent/testing/util.py
+160
-58
src/gevent/tests/test__example_echoserver.py
src/gevent/tests/test__example_echoserver.py
+1
-1
src/gevent/tests/test__example_portforwarder.py
src/gevent/tests/test__example_portforwarder.py
+3
-3
src/gevent/tests/test__example_udp_client.py
src/gevent/tests/test__example_udp_client.py
+6
-4
src/gevent/tests/test__example_udp_server.py
src/gevent/tests/test__example_udp_server.py
+1
-1
src/gevent/tests/test__example_webproxy.py
src/gevent/tests/test__example_webproxy.py
+1
-1
src/gevent/tests/test__example_wsgiserver.py
src/gevent/tests/test__example_wsgiserver.py
+1
-1
src/gevent/tests/test__example_wsgiserver_ssl.py
src/gevent/tests/test__example_wsgiserver_ssl.py
+1
-1
src/gevent/tests/test__examples.py
src/gevent/tests/test__examples.py
+12
-12
src/gevent/tests/test__monkey_module_run.py
src/gevent/tests/test__monkey_module_run.py
+34
-21
No files found.
src/gevent/baseserver.py
View file @
c34abdc0
...
...
@@ -117,7 +117,10 @@ class BaseServer(object):
# XXX: FIXME: Subclasses rely on the presence or absence of the
# `socket` attribute to determine whether we are open/should be opened.
# Instead, have it be None.
self
.
pool
=
None
# XXX: In general, the state management here is confusing. Lots of stuff is
# deferred until the various ``set_`` methods are called, and it's not documented
# when it's safe to call those
self
.
pool
=
None
# can be set from ``spawn``; overrides self.full()
try
:
self
.
set_listener
(
listener
)
self
.
set_spawn
(
spawn
)
...
...
@@ -250,9 +253,9 @@ class BaseServer(object):
self
.
delay
=
min
(
self
.
max_delay
,
self
.
delay
*
2
)
break
def
full
(
self
):
#
copied from self.pool
#
pylint: disable=method-hidden
def
full
(
self
):
# pylint: disable=method-hidden
#
If a Pool is given for to ``set_spawn`` (the *spawn* argument
#
of the constructor) it will replace this method.
return
False
def
__repr__
(
self
):
...
...
src/gevent/testing/util.py
View file @
c34abdc0
This diff is collapsed.
Click to expand it.
src/gevent/tests/test__example_echoserver.py
View file @
c34abdc0
...
...
@@ -6,7 +6,7 @@ from gevent.testing import util
from
gevent.testing
import
params
class
Test
(
util
.
TestServer
):
server
=
'echoserver.py'
example
=
'echoserver.py'
def
_run_all_tests
(
self
):
def
test_client
(
message
):
...
...
src/gevent/tests/test__example_portforwarder.py
View file @
c34abdc0
...
...
@@ -13,9 +13,9 @@ from gevent.testing import util
@
greentest
.
skipOnLibuvOnCIOnPyPy
(
"Timing issues sometimes lead to connection refused"
)
class
Test
(
util
.
TestServer
):
server
=
'portforwarder.py'
example
=
'portforwarder.py'
# [listen on, forward to]
args
=
[
'127.0.0.1:10011'
,
'127.0.0.1:10012'
]
example_
args
=
[
'127.0.0.1:10011'
,
'127.0.0.1:10012'
]
if
greentest
.
WIN
:
from
subprocess
import
CREATE_NEW_PROCESS_GROUP
...
...
@@ -40,7 +40,7 @@ class Test(util.TestServer):
break
log
.
append
(
data
)
server
=
StreamServer
(
self
.
args
[
1
],
handle
)
server
=
StreamServer
(
self
.
example_
args
[
1
],
handle
)
server
.
start
()
try
:
conn
=
socket
.
create_connection
((
'127.0.0.1'
,
10011
))
...
...
src/gevent/tests/test__example_udp_client.py
View file @
c34abdc0
from
gevent
import
monkey
monkey
.
patch_all
(
subprocess
=
True
)
import
sys
from
gevent.server
import
DatagramServer
from
gevent.testing.util
import
run
from
gevent.testing
import
util
from
gevent.testing
import
main
class
Test_udp_client
(
util
.
TestServer
):
start_kwargs
=
{
'timeout'
:
10
}
example
=
'udp_client.py'
example_args
=
[
'Test_udp_client'
]
def
test
(
self
):
log
=
[]
...
...
@@ -20,8 +23,7 @@ class Test_udp_client(util.TestServer):
server
=
DatagramServer
(
'127.0.0.1:9001'
,
handle
)
server
.
start
()
try
:
run
([
sys
.
executable
,
'-W'
,
'ignore'
,
'-u'
,
'udp_client.py'
,
'Test_udp_client'
],
timeout
=
10
,
cwd
=
self
.
cwd
)
self
.
run_example
()
finally
:
server
.
close
()
self
.
assertEqual
(
log
,
[
b'Test_udp_client'
])
...
...
src/gevent/tests/test__example_udp_server.py
View file @
c34abdc0
...
...
@@ -5,7 +5,7 @@ from gevent.testing import main
class
Test
(
util
.
TestServer
):
server
=
'udp_server.py'
example
=
'udp_server.py'
def
_run_all_tests
(
self
):
sock
=
socket
.
socket
(
type
=
socket
.
SOCK_DGRAM
)
...
...
src/gevent/tests/test__example_webproxy.py
View file @
c34abdc0
...
...
@@ -9,7 +9,7 @@ from . import test__example_wsgiserver
@
greentest
.
skipOnCI
(
"Timing issues sometimes lead to a connection refused"
)
@
greentest
.
skipWithoutExternalNetwork
(
"Tries to reach google.com"
)
class
Test_webproxy
(
test__example_wsgiserver
.
Test_wsgiserver
):
server
=
'webproxy.py'
example
=
'webproxy.py'
def
_run_all_tests
(
self
):
status
,
data
=
self
.
read
(
'/'
)
...
...
src/gevent/tests/test__example_wsgiserver.py
View file @
c34abdc0
...
...
@@ -16,7 +16,7 @@ from gevent.testing import params
@
greentest
.
skipOnCI
(
"Timing issues sometimes lead to a connection refused"
)
class
Test_wsgiserver
(
util
.
TestServer
):
server
=
'wsgiserver.py'
example
=
'wsgiserver.py'
URL
=
'http://%s:8088'
%
(
params
.
DEFAULT_LOCAL_HOST_ADDR
,)
PORT
=
8088
not_found_message
=
b'<h1>Not Found</h1>'
...
...
src/gevent/tests/test__example_wsgiserver_ssl.py
View file @
c34abdc0
...
...
@@ -9,7 +9,7 @@ from . import test__example_wsgiserver
@
greentest
.
skipOnCI
(
"Timing issues sometimes lead to a connection refused"
)
class
Test_wsgiserver_ssl
(
test__example_wsgiserver
.
Test_wsgiserver
):
server
=
'wsgiserver_ssl.py'
example
=
'wsgiserver_ssl.py'
URL
=
'https://%s:8443'
%
(
params
.
DEFAULT_LOCAL_HOST_ADDR
,)
PORT
=
8443
_use_ssl
=
True
...
...
src/gevent/tests/test__examples.py
View file @
c34abdc0
...
...
@@ -11,7 +11,6 @@ most commonly the resource will be ``network``. You can use this technique to sp
non-existant resources for things that should never be tested.
"""
import
re
import
sys
import
os
import
glob
import
time
...
...
@@ -45,12 +44,12 @@ time_ranges = {
class
_AbstractTestMixin
(
util
.
ExampleMixin
):
time_range
=
default_time_range
filenam
e
=
None
exampl
e
=
None
def
_check_resources
(
self
):
from
gevent.testing
import
resources
with
open
(
os
.
path
.
join
(
self
.
cwd
,
self
.
filenam
e
),
'r'
)
as
f
:
with
open
(
os
.
path
.
join
(
self
.
cwd
,
self
.
exampl
e
),
'r'
)
as
f
:
contents
=
f
.
read
()
pattern
=
re
.
compile
(
'^# gevent-test-requires-resource: (.*)$'
,
re
.
MULTILINE
)
...
...
@@ -64,14 +63,15 @@ class _AbstractTestMixin(util.ExampleMixin):
start
=
time
.
time
()
min_time
,
max_time
=
self
.
time_range
if
not
util
.
run
([
sys
.
executable
,
'-u'
,
self
.
filename
],
timeout
=
max_time
,
cwd
=
self
.
cwd
,
quiet
=
True
,
buffer_output
=
True
,
nested
=
True
,
setenv
=
{
'GEVENT_DEBUG'
:
'error'
}):
self
.
fail
(
"Failed example: "
+
self
.
filename
)
self
.
start_kwargs
=
{
'timeout'
:
max_time
,
'quiet'
:
True
,
'buffer_output'
:
True
,
'nested'
:
True
,
'setenv'
:
{
'GEVENT_DEBUG'
:
'error'
}
}
if
not
self
.
run_example
():
self
.
fail
(
"Failed example: "
+
self
.
example
)
else
:
took
=
time
.
time
()
-
start
self
.
assertGreaterEqual
(
took
,
min_time
)
...
...
@@ -94,7 +94,7 @@ def _build_test_classes():
'Test_'
+
bn
,
(
_AbstractTestMixin
,
greentest
.
TestCase
),
{
'
filenam
e'
:
bn
,
'
exampl
e'
:
bn
,
'time_range'
:
time_ranges
.
get
(
bn
,
_AbstractTestMixin
.
time_range
)
}
)
...
...
src/gevent/tests/test__monkey_module_run.py
View file @
c34abdc0
...
...
@@ -13,15 +13,15 @@ import os
import
os.path
import
sys
from
subprocess
import
Popen
from
subprocess
import
PIPE
from
gevent
import
testing
as
greentest
from
gevent.testing.util
import
absolute_pythonpath
from
gevent.testing.util
import
run
class
TestRun
(
greentest
.
TestCase
):
maxDiff
=
None
def
setUp
(
self
):
self
.
abs_pythonpath
=
absolute_pythonpath
()
# before we cd
self
.
cwd
=
os
.
getcwd
()
os
.
chdir
(
os
.
path
.
dirname
(
__file__
))
...
...
@@ -31,29 +31,42 @@ class TestRun(greentest.TestCase):
def
_run
(
self
,
script
,
module
=
False
):
env
=
os
.
environ
.
copy
()
env
[
'PYTHONWARNINGS'
]
=
'ignore'
if
self
.
abs_pythonpath
:
env
[
'PYTHONPATH'
]
=
self
.
abs_pythonpath
run_kwargs
=
dict
(
buffer_output
=
True
,
quiet
=
True
,
nested
=
True
,
env
=
env
,
timeout
=
10
,
)
args
=
[
sys
.
executable
,
'-m'
,
'gevent.monkey'
]
if
module
:
args
.
append
(
'--module'
)
args
+=
[
script
,
'patched'
]
p
=
Popen
(
args
,
stdout
=
PIPE
,
stderr
=
PIPE
,
env
=
env
)
monkey_out
,
monkey_err
=
p
.
communicate
()
self
.
assertEqual
(
0
,
p
.
returncode
,
(
p
.
returncode
,
monkey_out
,
monkey_err
))
monkey_result
=
run
(
args
,
**
run_kwargs
)
self
.
assertTrue
(
monkey_result
)
if
module
:
args
=
[
sys
.
executable
,
"-m"
,
script
,
'stdlib'
]
else
:
args
=
[
sys
.
executable
,
script
,
'stdlib'
]
p
=
Popen
(
args
,
stdout
=
PIPE
,
stderr
=
PIPE
)
std_out
,
std_err
=
p
.
communicate
()
self
.
assertEqual
(
0
,
p
.
returncode
,
(
p
.
returncode
,
std_out
,
std_err
))
monkey_out_lines
=
monkey_out
.
decode
(
"utf-8"
).
splitlines
()
std_out_lines
=
std_out
.
decode
(
'utf-8'
).
splitlines
()
std_result
=
run
(
args
,
**
run_kwargs
)
self
.
assertTrue
(
std_result
)
monkey_out_lines
=
monkey_result
.
output_lines
std_out_lines
=
std_result
.
output_lines
self
.
assertEqual
(
monkey_out_lines
,
std_out_lines
)
self
.
assertEqual
(
monkey_
err
,
std_er
r
)
self
.
assertEqual
(
monkey_
result
.
error
,
std_result
.
erro
r
)
return
monkey_out_lines
,
monkey_
er
r
return
monkey_out_lines
,
monkey_
result
.
erro
r
def
test_run_simple
(
self
):
self
.
_run
(
os
.
path
.
join
(
'monkey_package'
,
'script.py'
))
...
...
@@ -61,8 +74,8 @@ class TestRun(greentest.TestCase):
def
_run_package
(
self
,
module
):
lines
,
_
=
self
.
_run
(
'monkey_package'
,
module
=
module
)
self
.
assertTrue
(
lines
[
0
].
endswith
(
'__main__.py'
),
lines
[
0
])
self
.
assertEqual
(
lines
[
1
]
,
'__main__'
)
self
.
assertTrue
(
lines
[
0
].
endswith
(
u
'__main__.py'
),
lines
[
0
])
self
.
assertEqual
(
lines
[
1
]
.
strip
(),
u
'__main__'
)
def
test_run_package
(
self
):
# Run a __main__ inside a package, even without specifying -m
...
...
@@ -75,10 +88,10 @@ class TestRun(greentest.TestCase):
def
test_issue_302
(
self
):
lines
,
_
=
self
.
_run
(
os
.
path
.
join
(
'monkey_package'
,
'issue302monkey.py'
))
self
.
assertEqual
(
lines
[
0
]
,
'True'
)
lines
[
1
]
=
lines
[
1
].
replace
(
'
\
\
'
,
'/'
)
# windows path
self
.
assertEqual
(
lines
[
1
]
,
'monkey_package/issue302monkey.py'
)
self
.
assertEqual
(
lines
[
2
]
,
'True'
,
lines
)
self
.
assertEqual
(
lines
[
0
]
.
strip
(),
u
'True'
)
lines
[
1
]
=
lines
[
1
].
replace
(
u'
\
\
'
,
u
'/'
)
# windows path
self
.
assertEqual
(
lines
[
1
]
.
strip
(),
u
'monkey_package/issue302monkey.py'
)
self
.
assertEqual
(
lines
[
2
]
.
strip
(),
u
'True'
,
lines
)
# These three tests all sometimes fail on Py2 on CI, writing
# to stderr:
...
...
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