Add code coverage for tests (excluding ptvsd.server and pydevd).

Fix some issues on Python 2.7.

Remove dead code.
This commit is contained in:
Pavel Minaev 2019-09-18 20:05:47 -07:00 committed by Pavel Minaev
parent b7c48cc9fe
commit 0825dbeb37
12 changed files with 59 additions and 63 deletions

35
.coveragerc Normal file
View file

@ -0,0 +1,35 @@
[run]
branch = True
include =
src/ptvsd/*
omit =
src/ptvsd/__init__.py
src/ptvsd/_version.py
src/ptvsd/_vendored/*
src/ptvsd/server/*
data_file = coverage/.coverage
[report]
exclude_lines =
# Have to re-enable the standard pragma.
pragma: no cover
# __repr__ is mostly used for error messages.
def __repr__
# Asserts and error conditions.
raise AssertionError
raise NotImplementedError
\.isnt_valid\(
\.cant_handle\(
# Code that's deliberately excluded.
if 0:
if __name__ == .__main__.:
[html]
directory = coverage/html
title = ptvsd coverage report
[xml]
output = coverage/coverage.xml

3
.gitignore vendored
View file

@ -37,7 +37,8 @@ pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
coverage/html/
coverage/coverage.xml
tests/_logs/*.log
.tox/
.coverage

1
coverage/README Normal file
View file

@ -0,0 +1 @@
codecov data files and HTML reports go here.

View file

@ -162,4 +162,4 @@ __file__ = os.path.abspath(__file__)
# Preload encodings that we're going to use to avoid import deadlocks on Python 2,
# before importing anything from ptvsd.
map(codecs.lookup, ["ascii", "utf8", "utf-8", "latin1", "latin-1"])
map(codecs.lookup, ["ascii", "utf8", "utf-8", "latin1", "latin-1", "idna"])

View file

@ -202,15 +202,15 @@ class Session(util.Observable):
cmdline = ["sudo"] if sudo else []
cmdline += [sys.executable, os.path.dirname(ptvsd.launcher.__file__)]
cmdline += args
env = {"PTVSD_SESSION_ID": str(self.id)}
env = {str("PTVSD_SESSION_ID"): str(self.id)}
def spawn_launcher():
with self._accept_connection_from_launcher() as (_, launcher_port):
env["PTVSD_LAUNCHER_PORT"] = str(launcher_port)
env[str("PTVSD_LAUNCHER_PORT")] = str(launcher_port)
if common_options.log_dir is not None:
env["PTVSD_LOG_DIR"] = compat.filename(common_options.log_dir)
env[str("PTVSD_LOG_DIR")] = compat.filename_str(common_options.log_dir)
if adapter_options.log_stderr:
env["PTVSD_LOG_STDERR"] = "debug info warning error"
env[str("PTVSD_LOG_STDERR")] = str("debug info warning error")
if console == "internalConsole":
# If we are talking to the IDE over stdio, sys.stdin and sys.stdout are
# redirected to avoid mangling the DAP message stream. Make sure the

View file

@ -8,22 +8,6 @@ import threading
import sys
def new_hidden_thread(name, target, prefix='ptvsd.common.', daemon=True, **kwargs):
"""Return a thread that will be ignored by pydevd."""
if prefix is not None and not name.startswith(prefix):
name = prefix + name
t = threading.Thread(
name=name,
target=target,
**kwargs
)
t.pydev_do_not_trace = True
t.is_pydev_daemon_thread = True
if daemon:
t.daemon = False
return t
def evaluate(code, path=__file__, mode="eval"):
# Setting file path here to avoid breaking here if users have set
# "break on exception raised" setting. This code can potentially run

View file

@ -1,38 +0,0 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root
# for license information.
from __future__ import absolute_import, print_function, unicode_literals
from ptvsd.server import log, options
from ptvsd.server.__main__ import run_file, run_module, run_code
RUNNERS = {"module": run_module, "script": run_file, "code": run_code}
# Not actually used, but VS will try to add entries to it.
DONT_DEBUG = []
# A legacy entrypoint for Visual Studio, to allow older versions to work with new ptvsd.server.
# All new code should use the entrypoints in ptvsd.server.__main__ directly.
def debug(filename, port_num, debug_id, debug_options, run_as):
log.to_file()
log.info(
"debug{0!r}", (filename, port_num, debug_id, debug_options, run_as)
)
try:
run = RUNNERS[run_as]
except KeyError:
raise ValueError("run_as must be one of: {0!r}".format(tuple(RUNNERS.keys())))
options.target_kind = "file" if run_as == "script" else run_as
options.target = filename
options.port = port_num
options.client = True
# debug_id is ignored because it has no meaning in DAP.
# debug_options are ignored, because they will be passed later via DAP "launch" request.
run()

View file

@ -116,6 +116,10 @@ class Handlers(object):
cwd = None if program == () else (os.path.dirname(program) or None)
env = os.environ.copy()
if "PTVSD_TEST" in env:
# If we're running as part of a ptvsd test, make sure that codecov is not
# applied to the debuggee, since it will conflict with pydevd.
env.pop("COV_CORE_SOURCE", None)
env.update(request("env", json.object(unicode)))
redirect_output = "RedirectOutput" in debug_options

View file

@ -61,7 +61,10 @@ def _starts_debugging(func):
end_patterns,
)
return func(start_patterns, end_patterns)
try:
return func(start_patterns, end_patterns)
except Exception:
raise log.exception("{0}() failed:", func.__name__)
return debug

View file

@ -279,6 +279,7 @@ class Launch(DebugStartBase):
cwd = request("cwd", ".")
env = os.environ.copy()
env.pop("COV_CORE_SOURCE", None) # disable codecov subprocess hook
env.update(request("env", json.object(unicode)))
if sys.version_info < (3,):
@ -346,6 +347,7 @@ class AttachBase(DebugStartBase):
target_str = target.strpath
env = os.environ.copy()
env.pop("COV_CORE_SOURCE", None) # disable codecov subprocess hook
env.update(kwargs["env"])
cli_args = kwargs.get("cli_args")

View file

@ -3,6 +3,7 @@
# pytest>=5 does not support Python 2.7
pytest<5
pytest-cov
pytest-timeout
pytest-xdist
tox

View file

@ -1,8 +1,11 @@
[tox]
envlist = py{27,34,35,36,37}
envlist = py{27,34,35,36,37}{,-cov}
[testenv]
deps = -rtests/requirements.txt
passenv = PTVSD_LOG_DIR
setenv =
PTVSD_TEST=1
commands =
pytest {posargs:-n8}
!cov: pytest {posargs}
cov: pytest --cov --cov-append --cov-config=.coveragerc {posargs}