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
a9b61d6c
Commit
a9b61d6c
authored
5 years ago
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Let the examples be skipped if resources aren't around.
parent
92812e46
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
59 additions
and
20 deletions
+59
-20
examples/concurrent_download.py
examples/concurrent_download.py
+1
-1
examples/dns_mass_resolve.py
examples/dns_mass_resolve.py
+1
-0
examples/geventsendfile.py
examples/geventsendfile.py
+1
-0
examples/psycopg2_pool.py
examples/psycopg2_pool.py
+1
-0
examples/unixsocket_client.py
examples/unixsocket_client.py
+1
-0
examples/unixsocket_server.py
examples/unixsocket_server.py
+1
-0
examples/webpy.py
examples/webpy.py
+1
-0
src/gevent/testing/resources.py
src/gevent/testing/resources.py
+20
-4
src/gevent/testing/skipping.py
src/gevent/testing/skipping.py
+2
-7
src/gevent/tests/test__examples.py
src/gevent/tests/test__examples.py
+30
-8
No files found.
examples/concurrent_download.py
View file @
a9b61d6c
#!/usr/bin/python
# Copyright (c) 2009 Denis Bilenko. See LICENSE for details.
# gevent-test-requires-resource: network
"""Spawn multiple workers and wait for them to complete"""
from
__future__
import
print_function
import
gevent
...
...
This diff is collapsed.
Click to expand it.
examples/dns_mass_resolve.py
View file @
a9b61d6c
#!/usr/bin/python
# gevent-test-requires-resource: network
"""Resolve hostnames concurrently, exit after 2 seconds.
Under the hood, this might use an asynchronous resolver based on
...
...
This diff is collapsed.
Click to expand it.
examples/geventsendfile.py
View file @
a9b61d6c
...
...
@@ -2,6 +2,7 @@
[1] http://pypi.python.org/pypi/py-sendfile/
"""
# gevent-test-requires-resource: sendfile
# pylint:disable=import-error
from
errno
import
EAGAIN
from
sendfile
import
sendfile
as
original_sendfile
...
...
This diff is collapsed.
Click to expand it.
examples/psycopg2_pool.py
View file @
a9b61d6c
from
__future__
import
print_function
# gevent-test-requires-resource: psycopg2
# pylint:disable=import-error,broad-except,bare-except
import
sys
import
contextlib
...
...
This diff is collapsed.
Click to expand it.
examples/unixsocket_client.py
View file @
a9b61d6c
from
__future__
import
print_function
# gevent-test-requires-resource: unixsocket_server
import
socket
s
=
socket
.
socket
(
socket
.
AF_UNIX
,
socket
.
SOCK_STREAM
)
...
...
This diff is collapsed.
Click to expand it.
examples/unixsocket_server.py
View file @
a9b61d6c
# gevent-test-requires-resource: unixsocket_client
import
os
from
gevent.pywsgi
import
WSGIServer
from
gevent
import
socket
...
...
This diff is collapsed.
Click to expand it.
examples/webpy.py
View file @
a9b61d6c
#!/usr/bin/python
# gevent-test-requires-resource: webpy
"""A web.py application powered by gevent"""
from
__future__
import
print_function
...
...
This diff is collapsed.
Click to expand it.
src/gevent/testing/resources.py
View file @
a9b61d6c
...
...
@@ -171,6 +171,15 @@ def setup_resources(resources=None):
return
resources
def
ensure_setup_resources
():
# Call when you don't know if resources have been setup and you want to
# get the environment variable if needed.
# Returns an object with `is_resource_enabled`.
from
.
import
support
if
not
support
.
gevent_has_setup_resources
:
setup_resources
()
return
support
def
exit_without_resource
(
resource
):
"""
...
...
@@ -178,15 +187,22 @@ def exit_without_resource(resource):
Exits with a status of 0 if the resource isn't enabled.
"""
from
.
import
support
if
not
support
.
gevent_has_setup_resources
:
setup_resources
()
if
not
support
.
is_resource_enabled
(
resource
):
if
not
ensure_setup_resources
()
.
is_resource_enabled
(
resource
):
print
(
"Skipped: %r not enabled"
%
(
resource
,))
import
sys
sys
.
exit
(
0
)
def
skip_without_resource
(
resource
,
reason
=
''
):
requires
=
'Requires resource %r'
%
(
resource
,)
if
not
reason
:
reason
=
requires
else
:
reason
=
reason
+
' ('
+
requires
+
')'
if
not
ensure_setup_resources
().
is_resource_enabled
(
resource
):
import
unittest
raise
unittest
.
SkipTest
(
reason
)
if
__name__
==
'__main__'
:
print
(
setup_resources
())
This diff is collapsed.
Click to expand it.
src/gevent/testing/skipping.py
View file @
a9b61d6c
...
...
@@ -172,16 +172,11 @@ def skipWithoutResource(resource, reason=''):
else
:
reason
=
reason
+
' ('
+
requires
+
')'
# Defer until runtime; resources are established as part
# of test startup.
def
predicate
():
# This is easily cached if needed
from
.
import
support
if
not
support
.
gevent_has_setup_resources
:
# In this case, nothing to do but pull from the environment
from
.
import
resources
resources
.
setup_resources
()
return
support
.
is_resource_enabled
(
resource
)
from
.
import
resources
return
resources
.
ensure_setup_resources
().
is_resource_enabled
(
resource
)
return
_make_runtime_skip_decorator
(
reason
,
predicate
)
...
...
This diff is collapsed.
Click to expand it.
src/gevent/tests/test__examples.py
View file @
a9b61d6c
"""
Test the contents of the ``examples/`` directory.
If an existing test in *this* directory named ``test__example_<fn>.py`` exists,
where ``<fn>`` is the base filename of an example file, it will not be tested
here.
Examples can specify that they need particular test resources to be enabled
by commenting (one per line) ``# gevent-test-requires-resource: <resource>``;
most commonly the resource will be ``network``. You can use this technique to specify
non-existant resources for things that should never be tested.
"""
import
re
import
sys
import
os
import
glob
...
...
@@ -9,23 +22,17 @@ from gevent.testing import util
this_dir
=
os
.
path
.
dirname
(
__file__
)
# XXX: Review these, check those that use external network resources
# and exclude if that resource is disabled.
def
_find_files_to_ignore
():
old_dir
=
os
.
getcwd
()
try
:
os
.
chdir
(
this_dir
)
# These three are all tested with test___example_servers.
# TODO: Refactor those to regular test__example_*foo* files.
result
=
[
'wsgiserver.py'
,
'wsgiserver_ssl.py'
,
'webproxy.py'
,
'webpy.py'
,
'unixsocket_server.py'
,
'unixsocket_client.py'
,
'psycopg2_pool.py'
,
'geventsendfile.py'
,
]
if
greentest
.
PYPY
and
greentest
.
RUNNING_ON_APPVEYOR
:
# For some reason on Windows with PyPy, this times out,
...
...
@@ -48,7 +55,21 @@ class _AbstractTestMixin(util.ExampleMixin):
time_range
=
(
2
,
4
)
filename
=
None
def
_check_resources
(
self
):
from
gevent.testing
import
resources
with
open
(
os
.
path
.
join
(
self
.
cwd
,
self
.
filename
),
'r'
)
as
f
:
contents
=
f
.
read
()
pattern
=
re
.
compile
(
'^# gevent-test-requires-resource: (.*)$'
,
re
.
MULTILINE
)
resources_needed
=
re
.
finditer
(
pattern
,
contents
)
for
match
in
resources_needed
:
needed
=
contents
[
match
.
start
(
1
):
match
.
end
(
1
)]
resources
.
skip_without_resource
(
needed
)
def
test_runs
(
self
):
self
.
_check_resources
()
start
=
time
.
time
()
min_time
,
max_time
=
self
.
time_range
if
not
util
.
run
([
sys
.
executable
,
'-u'
,
self
.
filename
],
...
...
@@ -76,6 +97,7 @@ def _build_test_classes():
bn
=
os
.
path
.
basename
(
filename
)
if
bn
in
ignore
:
continue
tc
=
type
(
'Test_'
+
bn
,
(
_AbstractTestMixin
,
greentest
.
TestCase
),
...
...
This diff is collapsed.
Click to expand it.
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