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
fc8db79f
Commit
fc8db79f
authored
Mar 30, 2018
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor '-m gevent.monkey' tests for clarity.
parent
9a198e54
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
116 additions
and
53 deletions
+116
-53
src/gevent/_util.py
src/gevent/_util.py
+13
-2
src/gevent/local.py
src/gevent/local.py
+11
-7
src/gevent/monkey.py
src/gevent/monkey.py
+2
-1
src/greentest/monkey_package/issue302monkey.py
src/greentest/monkey_package/issue302monkey.py
+21
-0
src/greentest/monkey_package/script.py
src/greentest/monkey_package/script.py
+19
-0
src/greentest/test__issue302monkey.py
src/greentest/test__issue302monkey.py
+0
-15
src/greentest/test__monkey_scope.py
src/greentest/test__monkey_scope.py
+48
-27
src/greentest/tests_that_dont_do_leakchecks.txt
src/greentest/tests_that_dont_do_leakchecks.txt
+1
-0
src/greentest/tests_that_dont_monkeypatch.txt
src/greentest/tests_that_dont_monkeypatch.txt
+1
-0
src/greentest/tests_that_dont_use_resolver.txt
src/greentest/tests_that_dont_use_resolver.txt
+0
-1
No files found.
src/gevent/_util.py
View file @
fc8db79f
...
...
@@ -86,11 +86,22 @@ def import_c_accel(globs, cname):
# or we're running from the C extension
return
import
importlib
from
gevent._compat
import
PURE_PYTHON
if
PURE_PYTHON
:
return
import
importlib
import
warnings
with
warnings
.
catch_warnings
():
# Python 3.7 likes to produce
# "ImportWarning: can't resolve
# package from __spec__ or __package__, falling back on
# __name__ and __path__"
# when we load cython compiled files. This is probably a bug in
# Cython, but it doesn't seem to have any consequences, it's
# just annoying to see and can mess up our unittests.
warnings
.
simplefilter
(
'ignore'
,
ImportWarning
)
mod
=
importlib
.
import_module
(
cname
)
# By adopting the entire __dict__, we get a more accurate
...
...
src/gevent/local.py
View file @
fc8db79f
...
...
@@ -153,8 +153,6 @@ affects what we see:
"""
from
__future__
import
print_function
import
sys
_PYPY
=
hasattr
(
sys
,
'pypy_version_info'
)
from
copy
import
copy
from
weakref
import
ref
...
...
@@ -574,14 +572,20 @@ try:
# in different ways. In CPython and PyPy3, it must be wrapped with classmethod;
# in PyPy2, it must not. In either case, the args that get passed to
# it are stil wrong.
if
_PYPY
and
sys
.
version_info
[:
2
]
<
(
3
,
0
):
local
.
__new__
=
'None'
except
TypeError
:
# pragma: no cover
# Must be compiled
pass
else
:
from
gevent._compat
import
PYPY
from
gevent._compat
import
PY2
if
PYPY
and
PY2
:
local
.
__new__
=
__new__
else
:
local
.
__new__
=
classmethod
(
__new__
)
except
TypeError
:
# pragma: no cover
pass
finally
:
del
sys
del
PYPY
del
PY2
_init
()
...
...
src/gevent/monkey.py
View file @
fc8db79f
...
...
@@ -772,7 +772,8 @@ def main():
# passing .pyc/.pyo files and packages with a __main__ and
# potentially even zip files. Previously we used exec, which only
# worked if we directly read a python source file.
runpy
.
run_path
(
sys
.
argv
[
0
],
run_name
=
'__main__'
)
runpy
.
run_path
(
sys
.
argv
[
0
],
run_name
=
'__main__'
)
else
:
print
(
script_help
)
...
...
src/greentest/monkey_package/issue302monkey.py
0 → 100644
View file @
fc8db79f
from
__future__
import
print_function
import
socket
import
sys
if
sys
.
argv
[
1
]
==
'patched'
:
print
(
'gevent'
in
repr
(
socket
.
socket
))
else
:
assert
sys
.
argv
[
1
]
==
'stdlib'
print
(
'gevent'
not
in
repr
(
socket
.
socket
))
print
(
__file__
)
if
sys
.
version_info
[:
2
]
==
(
2
,
7
):
print
(
__package__
==
None
)
else
:
if
sys
.
argv
[
1
]
==
'patched'
:
# __package__ is handled differently, for some reason,
# and runpy doesn't let us override it. When we call it,
# it becomes ''
print
(
__package__
==
''
)
else
:
# but the interpreter sets it to None
print
(
__package__
==
None
)
src/greentest/monkey_package/script.py
0 → 100644
View file @
fc8db79f
# -*- coding: utf-8 -*-
"""
Test script file, to be used directly as a file.
"""
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
# We need some global imports
from
textwrap
import
dedent
def
use_import
():
return
dedent
(
" text"
)
if
__name__
==
'__main__'
:
print
(
__file__
)
print
(
__name__
)
print
(
use_import
())
src/greentest/test__issue302monkey.py
deleted
100644 → 0
View file @
9a198e54
import
sys
if
'gevent'
not
in
sys
.
modules
:
from
subprocess
import
Popen
args
=
[
sys
.
executable
,
'-m'
,
'gevent.monkey'
,
__file__
]
p
=
Popen
(
args
)
code
=
p
.
wait
()
assert
code
==
0
,
code
else
:
import
socket
assert
'gevent'
in
repr
(
socket
.
socket
),
repr
(
socket
.
socket
)
assert
__file__
==
'test__issue302monkey.py'
,
repr
(
__file__
)
assert
__package__
is
None
,
__package__
src/greentest/test__monkey_scope.py
View file @
fc8db79f
import
sys
import
unittest
if
'gevent'
not
in
sys
.
modules
:
from
subprocess
import
Popen
from
subprocess
import
PIPE
# Run a simple script
args
=
[
sys
.
executable
,
'-m'
,
'gevent.monkey'
,
__file__
]
p
=
Popen
(
args
)
code
=
p
.
wait
()
assert
code
==
0
,
code
from
subprocess
import
Popen
from
subprocess
import
PIPE
# Run a __main__ inside a package.
args
=
[
sys
.
executable
,
'-m'
,
'gevent.monkey'
,
'monkey_package'
]
class
TestRun
(
unittest
.
TestCase
):
def
_run
(
self
,
script
):
args
=
[
sys
.
executable
,
'-m'
,
'gevent.monkey'
,
script
,
'patched'
]
p
=
Popen
(
args
,
stdout
=
PIPE
,
stderr
=
PIPE
)
gout
,
gerr
=
p
.
communicate
()
self
.
assertEqual
(
0
,
p
.
returncode
,
(
gout
,
gerr
))
args
=
[
sys
.
executable
,
script
,
'stdlib'
]
p
=
Popen
(
args
,
stdout
=
PIPE
,
stderr
=
PIPE
)
out
,
err
=
p
.
communicate
()
lines
=
out
.
splitlines
()
assert
lines
[
0
].
endswith
(
b'__main__.py'
),
(
out
,
err
)
assert
lines
[
1
]
==
b'__main__'
,
(
lines
,
out
,
err
)
# Python 3.7 tends to produce some inscrutable
# warning from importlib._bootstrap.py on stderr
# "ImportWarning: can't resolve package from __spec__ or __package__".
# So we don't check that err is empty.
else
:
from
textwrap
import
dedent
def
use_import
():
dedent
(
" text"
)
use_import
()
pout
,
perr
=
p
.
communicate
()
self
.
assertEqual
(
0
,
p
.
returncode
,
(
pout
,
perr
))
glines
=
gout
.
decode
(
"utf-8"
).
splitlines
()
plines
=
pout
.
decode
(
'utf-8'
).
splitlines
()
self
.
assertEqual
(
glines
,
plines
)
self
.
assertEqual
(
gerr
,
perr
)
return
glines
,
gerr
def
test_run_simple
(
self
):
import
os.path
self
.
_run
(
os
.
path
.
join
(
'monkey_package'
,
'script.py'
))
def
test_run_package
(
self
):
# Run a __main__ inside a package.
lines
,
_
=
self
.
_run
(
'monkey_package'
)
self
.
assertTrue
(
lines
[
0
].
endswith
(
'__main__.py'
),
lines
[
0
])
self
.
assertEqual
(
lines
[
1
],
'__main__'
)
def
test_issue_302
(
self
):
import
os
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
)
if
__name__
==
'__main__'
:
unittest
.
main
()
src/greentest/tests_that_dont_do_leakchecks.txt
View file @
fc8db79f
test___monkey_patching.py
test__monkey_ssl_warning.py
test___monitor.py
test__monkey_scope.py
src/greentest/tests_that_dont_monkeypatch.txt
View file @
fc8db79f
...
...
@@ -18,3 +18,4 @@ test___ident.py
test___config.py
test___monitor.py
test__events.py
test__monkey_scope.py
src/greentest/tests_that_dont_use_resolver.txt
View file @
fc8db79f
...
...
@@ -79,7 +79,6 @@ test__hub.py
test__import_blocking_in_greenlet.py
test__import_wait.py
test__issue230.py
test__issue302monkey.py
test__issue330.py
test__issue467.py
test__issue6.py
...
...
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