diff --git a/.coveragerc b/.coveragerc index 28d2317ba..ef72dd31a 100644 --- a/.coveragerc +++ b/.coveragerc @@ -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__ diff --git a/src/debugpy/common/log.py b/src/debugpy/common/log.py index 7802f6a87..09888111b 100644 --- a/src/debugpy/common/log.py +++ b/src/debugpy/common/log.py @@ -58,7 +58,7 @@ def __init__(self, filename, file, levels=LEVELS, close_file=True): 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 @@ def write(self, level, output): try: self.file.write(output) self.file.flush() - except Exception: + except Exception: # pragma: no cover pass def close(self): @@ -90,7 +90,7 @@ def close(self): 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 report_paths(get_paths, label=None): importlib_metadata = None try: import importlib_metadata - except ImportError: + except ImportError: # pragma: no cover try: from importlib import metadata as importlib_metadata except ImportError: diff --git a/src/debugpy/common/messaging.py b/src/debugpy/common/messaging.py index eb9556d2f..b133f71b6 100644 --- a/src/debugpy/common/messaging.py +++ b/src/debugpy/common/messaging.py @@ -102,7 +102,7 @@ def from_socket(cls, sock, name=None): def cleanup(): try: sock.shutdown(socket.SHUT_RDWR) - except Exception: + except Exception: # pragma: no cover pass sock.close() @@ -155,7 +155,7 @@ def close(self): 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 @@ def log_message_and_reraise_exception(format_string="", *args, **kwargs): 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 @@ def log_message_and_reraise_exception(format_string="", *args, **kwargs): 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 @@ def log_message_and_reraise_exception(format_string="", *args, **kwargs): 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 @@ def write_json(self, value, encoder=None): 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 @@ def write_json(self, value, encoder=None): 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 @@ def __init__(self, message, items=None): 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): diff --git a/src/debugpy/common/sockets.py b/src/debugpy/common/sockets.py index 453dbf1aa..ffcef80f6 100644 --- a/src/debugpy/common/sockets.py +++ b/src/debugpy/common/sockets.py @@ -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 )