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
a9842bca
Commit
a9842bca
authored
Apr 09, 2019
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply logging updates to test__socket_dns as well.
parent
007a8a50
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
34 deletions
+45
-34
src/gevent/testing/util.py
src/gevent/testing/util.py
+14
-12
src/gevent/tests/test__socket_dns.py
src/gevent/tests/test__socket_dns.py
+31
-22
No files found.
src/gevent/testing/util.py
View file @
a9842bca
...
...
@@ -37,24 +37,26 @@ class Popen(subprocess.Popen):
_colorscheme
=
{
'normal'
:
'normal'
,
'default'
:
'default'
,
'info'
:
'normal'
,
'actual-output'
:
'red'
,
'character-diffs'
:
'magenta'
,
'debug'
:
'cyan'
,
'
suboptimal-behaviour
'
:
'magenta'
,
'
diff-chunk
'
:
'magenta'
,
'error'
:
'brightred'
,
'number'
:
'green'
,
'slow-test'
:
'brightmagenta'
,
'ok-number'
:
'green'
,
'error-number'
:
'brightred'
,
'exception'
:
'red'
,
'expected-output'
:
'green'
,
'failed-example'
:
'cyan'
,
'filename'
:
'lightblue'
,
'info'
:
'normal'
,
'lineno'
:
'lightred'
,
'testname'
:
'lightcyan'
,
'failed-example'
:
'cyan'
,
'expected-output'
:
'green'
,
'actual-output'
:
'red'
,
'character-diffs'
:
'magenta'
,
'diff-chunk'
:
'magenta'
,
'exception'
:
'red'
,
'number'
:
'green'
,
'ok-number'
:
'green'
,
'skipped'
:
'brightyellow'
,
'slow-test'
:
'brightmagenta'
,
'suboptimal-behaviour'
:
'magenta'
,
'testname'
:
'lightcyan'
,
'warning'
:
'cyan'
,
}
_prefixes
=
[
...
...
src/gevent/tests/test__socket_dns.py
View file @
a9842bca
...
...
@@ -6,20 +6,24 @@ from gevent import monkey
import
os
import
re
import
gevent.testing
as
greentest
import
unittest
import
socket
from
time
import
time
import
traceback
import
gevent.socket
as
gevent_socket
from
gevent.testing.util
import
log
import
gevent.testing
as
greentest
#from gevent.testing.util import log
#from gevent.testing.util import debug
from
gevent.testing
import
util
from
gevent.testing
import
six
from
gevent.testing.six
import
xrange
from
gevent.testing
import
flaky
resolver
=
gevent
.
get_hub
().
resolver
lo
g
(
'Resolver: %s'
,
resolver
)
util
.
debu
g
(
'Resolver: %s'
,
resolver
)
if
getattr
(
resolver
,
'pool'
,
None
)
is
not
None
:
resolver
.
pool
.
size
=
1
...
...
@@ -33,8 +37,11 @@ import gevent.testing.timing
assert
gevent_socket
.
gaierror
is
socket
.
gaierror
assert
gevent_socket
.
error
is
socket
.
error
DEBUG
=
os
.
getenv
(
'GEVENT_DEBUG'
,
''
)
==
'trace'
TRACE
=
not
util
.
QUIET
and
os
.
getenv
(
'GEVENT_DEBUG'
,
''
)
==
'trace'
def
trace
(
message
,
*
args
,
**
kwargs
):
if
TRACE
:
util
.
debug
(
message
,
*
args
,
**
kwargs
)
def
_run
(
function
,
*
args
):
try
:
...
...
@@ -42,7 +49,7 @@ def _run(function, *args):
assert
not
isinstance
(
result
,
BaseException
),
repr
(
result
)
return
result
except
Exception
as
ex
:
if
DEBUG
:
if
TRACE
:
traceback
.
print_exc
()
return
ex
...
...
@@ -59,7 +66,9 @@ def format_call(function, args):
return
function
+
args
def
log_fresult
(
result
,
seconds
):
def
trace_fresult
(
result
,
seconds
):
if
not
TRACE
:
return
if
isinstance
(
result
,
Exception
):
msg
=
' -=> raised %r'
%
(
result
,
)
else
:
...
...
@@ -70,23 +79,21 @@ def log_fresult(result, seconds):
space
=
' '
*
space
else
:
space
=
''
lo
g
(
msg
+
space
+
time_ms
)
util
.
debu
g
(
msg
+
space
+
time_ms
)
def
run
(
function
,
*
args
):
if
DEBUG
:
log
(
format_call
(
function
,
args
))
trace
(
format_call
(
function
,
args
))
delta
=
time
()
result
=
_run
(
function
,
*
args
)
delta
=
time
()
-
delta
if
DEBUG
:
log_fresult
(
result
,
delta
)
trace_fresult
(
result
,
delta
)
return
result
,
delta
def
log
_call
(
result
,
runtime
,
function
,
*
args
):
lo
g
(
format_call
(
function
,
args
))
log
_fresult
(
result
,
runtime
)
def
trace
_call
(
result
,
runtime
,
function
,
*
args
):
util
.
debu
g
(
format_call
(
function
,
args
))
trace
_fresult
(
result
,
runtime
)
def
compare_relaxed
(
a
,
b
):
...
...
@@ -223,7 +230,7 @@ class TestCase(greentest.TestCase):
__timeout__ = 30
switch_expected = None
verbose_dns =
False
verbose_dns =
TRACE
def setUp(self):
super(TestCase, self).setUp()
...
...
@@ -253,10 +260,10 @@ class TestCase(greentest.TestCase):
real_func = monkey.get_original('
socket
', func)
real_result, time_real = run(real_func, *args)
gevent_result, time_gevent = run(gevent_func, *args)
if
not DEBUG
and self.should_log_results(real_result, gevent_result):
log('')
log
_call(real_result, time_real, real_func, *args)
log
_call(gevent_result, time_gevent, gevent_func, *args)
if
util.QUIET
and self.should_log_results(real_result, gevent_result):
util.
log('')
trace
_call(real_result, time_real, real_func, *args)
trace
_call(gevent_result, time_gevent, gevent_func, *args)
self.assertEqualResults(real_result, gevent_result, func)
if self.verbose_dns and time_gevent > time_real + 0.01 and time_gevent > 0.02:
...
...
@@ -267,7 +274,7 @@ class TestCase(greentest.TestCase):
else:
word = '
quite
'
log('
\
nWARNING
:
%
s
slow
:
%
s
', word, msg
)
util.log('
\
nWARNING
:
%
s
slow
:
%
s
', word, msg, color='
warning
'
)
return gevent_result
...
...
@@ -332,7 +339,9 @@ class TestCase(greentest.TestCase):
errors
=
(
socket
.
gaierror
,
socket
.
herror
,
TypeError
)
if
isinstance
(
real_result
,
errors
)
and
isinstance
(
gevent_result
,
errors
):
if
type
(
real_result
)
is
not
type
(
gevent_result
):
log
(
'WARNING: error type mismatch: %r (gevent) != %r (stdlib)'
,
gevent_result
,
real_result
)
util
.
log
(
'WARNING: error type mismatch: %r (gevent) != %r (stdlib)'
,
gevent_result
,
real_result
,
color
=
'warning'
)
return
real_result
=
self
.
_normalize_result
(
real_result
,
func
)
...
...
@@ -486,7 +495,7 @@ class TestEtcHosts(TestCase):
hf
=
SanitizedHostsFile
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'hosts_file.txt'
))
all_etc_hosts
=
sorted
(
hf
.
iter_all_host_addr_pairs
())
if
len
(
all_etc_hosts
)
>
cls
.
MAX_HOSTS
and
not
DEBUG
:
if
len
(
all_etc_hosts
)
>
cls
.
MAX_HOSTS
and
util
.
QUIET
:
all_etc_hosts
=
all_etc_hosts
[:
cls
.
MAX_HOSTS
]
for
host
,
ip
in
all_etc_hosts
:
...
...
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