mirror of
https://github.com/microsoft/debugpy.git
synced 2025-12-23 08:48:12 +00:00
Re-enable coverage for debugpy.common.log and use comments to exclude specific lines instead.
This commit is contained in:
parent
8e91dfb085
commit
9df16cec07
4 changed files with 24 additions and 28 deletions
|
|
@ -8,14 +8,10 @@ omit =
|
|||
src/debugpy/_version.py
|
||||
src/debugpy/_vendored/*
|
||||
src/debugpy/server/*
|
||||
src/debugpy/common/log.py
|
||||
data_file = coverage/.coverage
|
||||
|
||||
[report]
|
||||
exclude_lines =
|
||||
# Have to re-enable the standard pragma.
|
||||
pragma: no cover
|
||||
|
||||
exclude_also =
|
||||
# __repr__ is mostly used for error messages.
|
||||
def __repr__
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class LogFile(object):
|
|||
platform.machine(),
|
||||
platform.python_implementation(),
|
||||
platform.python_version(),
|
||||
64 if sys.maxsize > 2 ** 32 else 32,
|
||||
64 if sys.maxsize > 2**32 else 32,
|
||||
debugpy.__version__,
|
||||
_to_files=[self],
|
||||
)
|
||||
|
|
@ -78,7 +78,7 @@ class LogFile(object):
|
|||
try:
|
||||
self.file.write(output)
|
||||
self.file.flush()
|
||||
except Exception:
|
||||
except Exception: # pragma: no cover
|
||||
pass
|
||||
|
||||
def close(self):
|
||||
|
|
@ -90,7 +90,7 @@ class LogFile(object):
|
|||
if self.close_file:
|
||||
try:
|
||||
self.file.close()
|
||||
except Exception:
|
||||
except Exception: # pragma: no cover
|
||||
pass
|
||||
|
||||
def __enter__(self):
|
||||
|
|
@ -151,7 +151,7 @@ def write_format(level, format_string, *args, **kwargs):
|
|||
|
||||
try:
|
||||
text = format_string.format(*args, **kwargs)
|
||||
except Exception:
|
||||
except Exception: # pragma: no cover
|
||||
reraise_exception()
|
||||
|
||||
return write(level, text, kwargs.pop("_to_files", all))
|
||||
|
|
@ -253,7 +253,7 @@ def to_file(filename=None, prefix=None, levels=LEVELS):
|
|||
return NoLog()
|
||||
try:
|
||||
os.makedirs(log_dir)
|
||||
except OSError:
|
||||
except OSError: # pragma: no cover
|
||||
pass
|
||||
filename = f"{log_dir}/{prefix}-{os.getpid()}.log"
|
||||
|
||||
|
|
@ -347,7 +347,7 @@ def get_environment_description(header):
|
|||
importlib_metadata = None
|
||||
try:
|
||||
import importlib_metadata
|
||||
except ImportError:
|
||||
except ImportError: # pragma: no cover
|
||||
try:
|
||||
from importlib import metadata as importlib_metadata
|
||||
except ImportError:
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ class JsonIOStream(object):
|
|||
def cleanup():
|
||||
try:
|
||||
sock.shutdown(socket.SHUT_RDWR)
|
||||
except Exception:
|
||||
except Exception: # pragma: no cover
|
||||
pass
|
||||
sock.close()
|
||||
|
||||
|
|
@ -155,7 +155,7 @@ class JsonIOStream(object):
|
|||
self._reader.close()
|
||||
finally:
|
||||
self._cleanup()
|
||||
except Exception:
|
||||
except Exception: # pragma: no cover
|
||||
log.reraise_exception("Error while closing {0} message stream", self.name)
|
||||
|
||||
def _log_message(self, dir, data, logger=log.debug):
|
||||
|
|
@ -206,7 +206,7 @@ class JsonIOStream(object):
|
|||
while True:
|
||||
try:
|
||||
line = read_line()
|
||||
except Exception:
|
||||
except Exception: # pragma: no cover
|
||||
# Only log it if we have already read some headers, and are looking
|
||||
# for a blank line terminating them. If this is the very first read,
|
||||
# there's no message data to log in any case, and the caller might
|
||||
|
|
@ -229,7 +229,7 @@ class JsonIOStream(object):
|
|||
length = int(headers[b"Content-Length"])
|
||||
if not (0 <= length <= self.MAX_BODY_SIZE):
|
||||
raise ValueError
|
||||
except (KeyError, ValueError):
|
||||
except (KeyError, ValueError): # pragma: no cover
|
||||
try:
|
||||
raise IOError("Content-Length is missing or invalid:")
|
||||
except Exception:
|
||||
|
|
@ -253,12 +253,12 @@ class JsonIOStream(object):
|
|||
body = b"".join(raw_chunks[body_start:])
|
||||
try:
|
||||
body = body.decode("utf-8")
|
||||
except Exception:
|
||||
except Exception: # pragma: no cover
|
||||
log_message_and_reraise_exception()
|
||||
|
||||
try:
|
||||
body = decoder.decode(body)
|
||||
except Exception:
|
||||
except Exception: # pragma: no cover
|
||||
log_message_and_reraise_exception()
|
||||
|
||||
# If parsed successfully, log as JSON for readability.
|
||||
|
|
@ -285,7 +285,7 @@ class JsonIOStream(object):
|
|||
|
||||
try:
|
||||
body = encoder.encode(value)
|
||||
except Exception:
|
||||
except Exception: # pragma: no cover
|
||||
self._log_message("<--", repr(value), logger=log.reraise_exception)
|
||||
body = body.encode("utf-8")
|
||||
|
||||
|
|
@ -297,7 +297,7 @@ class JsonIOStream(object):
|
|||
written = writer.write(data[data_written:])
|
||||
data_written += written
|
||||
writer.flush()
|
||||
except Exception as exc:
|
||||
except Exception as exc: # pragma: no cover
|
||||
self._log_message("<--", value, logger=log.swallow_exception)
|
||||
raise JsonIOError(stream=self, cause=exc)
|
||||
|
||||
|
|
@ -344,7 +344,7 @@ class MessageDict(collections.OrderedDict):
|
|||
def __repr__(self):
|
||||
try:
|
||||
return format(json.repr(self))
|
||||
except Exception:
|
||||
except Exception: # pragma: no cover
|
||||
return super().__repr__()
|
||||
|
||||
def __call__(self, key, validate, optional=False):
|
||||
|
|
|
|||
|
|
@ -30,13 +30,13 @@ def create_server(host, port=0, backlog=socket.SOMAXCONN, timeout=None):
|
|||
else:
|
||||
try:
|
||||
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
except (AttributeError, OSError):
|
||||
except (AttributeError, OSError): # pragma: no cover
|
||||
pass # Not available everywhere
|
||||
server.bind((host, port))
|
||||
if timeout is not None:
|
||||
server.settimeout(timeout)
|
||||
server.listen(backlog)
|
||||
except Exception:
|
||||
except Exception: # pragma: no cover
|
||||
server.close()
|
||||
raise
|
||||
return server
|
||||
|
|
@ -56,19 +56,19 @@ def _new_sock():
|
|||
# and closes the connection after 5 failed ping (TCP_KEEPCNT), or 15 seconds
|
||||
try:
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
|
||||
except (AttributeError, OSError):
|
||||
except (AttributeError, OSError): # pragma: no cover
|
||||
pass # May not be available everywhere.
|
||||
try:
|
||||
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 1)
|
||||
except (AttributeError, OSError):
|
||||
except (AttributeError, OSError): # pragma: no cover
|
||||
pass # May not be available everywhere.
|
||||
try:
|
||||
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 3)
|
||||
except (AttributeError, OSError):
|
||||
except (AttributeError, OSError): # pragma: no cover
|
||||
pass # May not be available everywhere.
|
||||
try:
|
||||
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 5)
|
||||
except (AttributeError, OSError):
|
||||
except (AttributeError, OSError): # pragma: no cover
|
||||
pass # May not be available everywhere.
|
||||
return sock
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ def close_socket(sock):
|
|||
"""Shutdown and close the socket."""
|
||||
try:
|
||||
shut_down(sock)
|
||||
except Exception:
|
||||
except Exception: # pragma: no cover
|
||||
pass
|
||||
sock.close()
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ def serve(name, handler, host, port=0, backlog=socket.SOMAXCONN, timeout=None):
|
|||
|
||||
try:
|
||||
listener = create_server(host, port, backlog, timeout)
|
||||
except Exception:
|
||||
except Exception: # pragma: no cover
|
||||
log.reraise_exception(
|
||||
"Error listening for incoming {0} connections on {1}:{2}:", name, host, port
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue