Blacken code.

This commit is contained in:
Pavel Minaev 2022-04-13 10:41:36 -07:00 committed by Pavel Minaev
parent cb25e2f106
commit dd5196fbfc
36 changed files with 160 additions and 189 deletions

View file

@ -36,7 +36,7 @@ def get_marked_line_numbers(path):
with open(path, "rb") as f:
lines = {}
for i, line in enumerate(f):
match = re.search(br"#\s*@(.+?)\s*$", line)
match = re.search(rb"#\s*@(.+?)\s*$", line)
if match:
markers = match.group(1).decode("ascii")
for marker in markers.split(","):

View file

@ -58,9 +58,7 @@ class BackChannel(object):
self._socket = sock
self._setup_stream()
accept_thread = threading.Thread(
target=accept_worker, name=f"{self} listener"
)
accept_thread = threading.Thread(target=accept_worker, name=f"{self} listener")
accept_thread.daemon = True
accept_thread.start()
@ -115,8 +113,7 @@ class ScratchPad(object):
raise NotImplementedError
def __setitem__(self, key, value):
"""Sets debuggee.scratchpad[key] = value inside the debugged process.
"""
"""Sets debuggee.scratchpad[key] = value inside the debugged process."""
log.info("{0} debuggee.scratchpad[{1!r}] = {2!r}", self.session, key, value)
expr = f"sys.modules['debuggee'].scratchpad[{key!r}] = {value!r}"
self.session.request("evaluate", {"context": "repl", "expression": expr})

View file

@ -10,8 +10,7 @@ from debugpy.common import log
class CapturedOutput(object):
"""Captures stdout and stderr of the debugged process.
"""
"""Captures stdout and stderr of the debugged process."""
def __init__(self, session, **fds):
self.session = session
@ -59,8 +58,7 @@ class CapturedOutput(object):
self._worker_threads.append(thread)
def wait(self, timeout=None):
"""Wait for all remaining output to be captured.
"""
"""Wait for all remaining output to be captured."""
if not self._worker_threads:
return
log.debug("Waiting for remaining {0} output...", self.session.debuggee_id)

View file

@ -116,7 +116,12 @@ def _runner(f):
@_runner
def launch(session, target, console=None, cwd=None):
assert console in (None, "internalConsole", "integratedTerminal", "externalTerminal")
assert console in (
None,
"internalConsole",
"integratedTerminal",
"externalTerminal",
)
log.info("Launching {0} in {1} using {2}.", target, session, json.repr(console))
@ -144,9 +149,9 @@ def launch(session, target, console=None, cwd=None):
def _attach_common_config(session, target, cwd):
assert target.code is None or "debuggee.setup()" in target.code, (
f"{target.filename} must invoke debuggee.setup()."
)
assert (
target.code is None or "debuggee.setup()" in target.code
), f"{target.filename} must invoke debuggee.setup()."
target.configure(session)
config = session.config

View file

@ -176,7 +176,9 @@ class Session(object):
timeline.Event("output", some.dict.containing({"category": "stdout"})),
timeline.Event("output", some.dict.containing({"category": "stderr"})),
timeline.Event("output", some.dict.containing({"category": "console"})),
timeline.Event("output", some.dict.containing({"category": "important"})),
timeline.Event(
"output", some.dict.containing({"category": "important"})
),
]
)
@ -342,8 +344,7 @@ class Session(object):
assert not len(self.captured_output - {"stdout", "stderr"})
args = [exe] + [
str(s.strpath if isinstance(s, py.path.local) else s)
for s in args
str(s.strpath if isinstance(s, py.path.local) else s) for s in args
]
cwd = cwd.strpath if isinstance(cwd, py.path.local) else cwd
@ -372,12 +373,7 @@ class Session(object):
popen_fds[stream_name] = wfd
capture_fds[stream_name] = rfd
self.debuggee = psutil.Popen(
args,
cwd=cwd,
env=env,
bufsize=0,
stdin=subprocess.PIPE,
**popen_fds
args, cwd=cwd, env=env, bufsize=0, stdin=subprocess.PIPE, **popen_fds
)
log.info("Spawned {0} with PID={1}", self.debuggee_id, self.debuggee.pid)
watchdog.register_spawn(self.debuggee.pid, self.debuggee_id)
@ -482,9 +478,7 @@ class Session(object):
elif event.event == "debugpyAttach":
self.observe(occ)
pid = event("subProcessId", int)
watchdog.register_spawn(
pid, f"{self.debuggee_id}-subprocess-{pid}"
)
watchdog.register_spawn(pid, f"{self.debuggee_id}-subprocess-{pid}")
def run_in_terminal(self, args, cwd, env):
exe = args.pop(0)
@ -715,9 +709,7 @@ class Session(object):
"variables", {"variablesReference": scopes[0]("variablesReference", int)}
)("variables", json.array())
variables = collections.OrderedDict(
((v("name", str), v) for v in variables)
)
variables = collections.OrderedDict(((v("name", str), v) for v in variables))
if varnames:
assert set(varnames) <= set(variables.keys())
return tuple((variables[name] for name in varnames))
@ -725,8 +717,7 @@ class Session(object):
return variables
def get_variable(self, varname, frame_id=None):
"""Same as get_variables(...)[0].
"""
"""Same as get_variables(...)[0]."""
return self.get_variables(varname, frame_id=frame_id)[0]
def wait_for_next_event(self, event, body=some.object, freeze=True):

View file

@ -10,8 +10,7 @@ from tests.patterns import some
class Target(object):
"""Describes Python code that gets run by a Runner.
"""
"""Describes Python code that gets run by a Runner."""
def __init__(self, filename, args=()):
if filename is not None and not isinstance(filename, py.path.local):
@ -63,8 +62,7 @@ class Target(object):
@property
def lines(self):
"""Same as self.filename.lines, if it is valid - e.g. for @pyfile objects.
"""
"""Same as self.filename.lines, if it is valid - e.g. for @pyfile objects."""
assert (
self.filename is not None
), "lines() requires Target created from filename"
@ -74,13 +72,13 @@ class Target(object):
class Program(Target):
"""
A Python script, executed directly.
By default executes a program through its absolute path with:
python /full/path/to/foo.py
If made relative through make_relative(cwd), the cwd is set and the
launch is made relative to it.
i.e.:
Given a path such as /full/path/to/foo.py
if make_relative('/full/path') is called,

View file

@ -348,7 +348,12 @@ def test_invalid_breakpoints(pyfile, target, run):
expected_markers = []
for r in requested_markers:
e_generic = "e" + r[1:]
e_versioned = e_generic + "-" + str(sys.version_info.major) + str(sys.version_info.minor)
e_versioned = (
e_generic
+ "-"
+ str(sys.version_info.major)
+ str(sys.version_info.minor)
)
for e in e_versioned, e_generic, r:
if e in code_to_debug.lines:
expected_markers.append(e)

View file

@ -28,7 +28,9 @@ def test_env_replace_var(pyfile, target, run, case, new_value):
with debug.Session() as session:
backchannel = session.open_backchannel()
session.config.env[varname if case == "match_case" else varname.lower()] = new_value
session.config.env[
varname if case == "match_case" else varname.lower()
] = new_value
os.environ[varname] = "1"
try:

View file

@ -698,4 +698,3 @@ def test_evaluate_thread_locks(pyfile, target, run):
assert evaluate == some.dict.containing({"result": "None"})
session.request_continue()

View file

@ -460,11 +460,13 @@ def test_subprocess_unobserved(pyfile, run, target, wait):
if wait:
# The child process should not have started running user code until
# there was a client connection, so the breakpoint should be hit.
child_session.wait_for_stop(expected_frames=[some.dap.frame(child, line="bp")])
child_session.wait_for_stop(
expected_frames=[some.dap.frame(child, line="bp")]
)
child_session.request_continue()
else:
# The breakpoint shouldn't be hit, since that line should have been
# executed before we attached.
# executed before we attached.
pass
backchannel.send("proceed")
@ -472,7 +474,9 @@ def test_subprocess_unobserved(pyfile, run, target, wait):
@pytest.mark.parametrize("run", runners.all_launch)
@pytest.mark.skipif(sys.platform != "win32", reason="job objects are specific to Windows")
@pytest.mark.skipif(
sys.platform != "win32", reason="job objects are specific to Windows"
)
def test_breakaway_job(pyfile, target, run):
@pyfile
def child():
@ -509,10 +513,12 @@ def test_breakaway_job(pyfile, target, run):
proc.wait()
with debug.Session() as parent_session:
parent_session.config.update({
"redirectOutput": False,
"subProcess": False,
})
parent_session.config.update(
{
"redirectOutput": False,
"subProcess": False,
}
)
parent_session.expected_exit_code = some.int
backchannel = parent_session.open_backchannel()
@ -530,4 +536,4 @@ def test_breakaway_job(pyfile, target, run):
assert backchannel.receive() == "ok"
log.info("Waiting for child process...")
child_process.wait()
child_process.wait()

View file

@ -46,7 +46,7 @@ def expected_system_info():
{
"pid": some.int,
"executable": sys.executable,
"bitness": 64 if sys.maxsize > 2 ** 32 else 32,
"bitness": 64 if sys.maxsize > 2**32 else 32,
}
),
}

View file

@ -34,7 +34,7 @@ def get_test_server_port(start, stop):
n = 0
else:
assert worker_id == some.bytes.matching(
br"gw(\d+)"
rb"gw(\d+)"
), "Unrecognized PYTEST_XDIST_WORKER format"
n = int(worker_id[2:])
@ -75,8 +75,7 @@ def wait_until_port_is_listening(port, interval=1, max_attempts=1000):
class WebRequest(object):
"""An async wrapper around requests.
"""
"""An async wrapper around requests."""
@staticmethod
def get(*args, **kwargs):
@ -136,8 +135,7 @@ class WebRequest(object):
)
def wait_for_response(self, timeout=None):
"""Blocks until the request completes, and returns self.request.
"""
"""Blocks until the request completes, and returns self.request."""
if self._worker_thread.is_alive():
log.info("Waiting for response to {0} ...", self)
self._worker_thread.join(timeout)
@ -147,22 +145,19 @@ class WebRequest(object):
return self.request
def response_text(self):
"""Blocks until the request completes, and returns the response body.
"""
"""Blocks until the request completes, and returns the response body."""
return self.wait_for_response().text
class WebServer(object):
"""Interacts with a web server listening on localhost on the specified port.
"""
"""Interacts with a web server listening on localhost on the specified port."""
def __init__(self, port):
self.port = port
self.url = f"http://localhost:{port}"
def __enter__(self):
"""Blocks until the server starts listening on self.port.
"""
"""Blocks until the server starts listening on self.port."""
log.info("Web server expected on {0}", self.url)
wait_until_port_is_listening(self.port, interval=3)
return self

View file

@ -17,8 +17,7 @@ import pydevd_file_utils
class Some(object):
"""A pattern that can be tested against a value with == to see if it matches.
"""
"""A pattern that can be tested against a value with == to see if it matches."""
def matches(self, value):
raise NotImplementedError
@ -36,23 +35,19 @@ class Some(object):
return not self.matches(value)
def __invert__(self):
"""The inverse pattern - matches everything that this one doesn't.
"""
"""The inverse pattern - matches everything that this one doesn't."""
return Not(self)
def __or__(self, pattern):
"""Union pattern - matches if either of the two patterns match.
"""
"""Union pattern - matches if either of the two patterns match."""
return Either(self, pattern)
def such_that(self, condition):
"""Same pattern, but it only matches if condition() is true.
"""
"""Same pattern, but it only matches if condition() is true."""
return SuchThat(self, condition)
def in_range(self, start, stop):
"""Same pattern, but it only matches if the start <= value < stop.
"""
"""Same pattern, but it only matches if the start <= value < stop."""
return InRange(self, start, stop)
def equal_to(self, obj):
@ -82,8 +77,7 @@ class Some(object):
class Not(Some):
"""Matches the inverse of the pattern.
"""
"""Matches the inverse of the pattern."""
def __init__(self, pattern):
self.pattern = pattern
@ -96,8 +90,7 @@ class Not(Some):
class Either(Some):
"""Matches either of the patterns.
"""
"""Matches either of the patterns."""
def __init__(self, *patterns):
assert len(patterns) > 0
@ -117,8 +110,7 @@ class Either(Some):
class Object(Some):
"""Matches anything.
"""
"""Matches anything."""
name = "<?>"
@ -127,8 +119,7 @@ class Object(Some):
class Thing(Some):
"""Matches anything that is not None.
"""
"""Matches anything that is not None."""
name = "<>"
@ -137,8 +128,7 @@ class Thing(Some):
class InstanceOf(Some):
"""Matches any object that is an instance of the specified type.
"""
"""Matches any object that is an instance of the specified type."""
def __init__(self, classinfo, name=None):
if isinstance(classinfo, type):
@ -199,8 +189,7 @@ class Path(Some):
class ListContaining(Some):
"""Matches any list that contains the specified subsequence of elements.
"""
"""Matches any list that contains the specified subsequence of elements."""
def __init__(self, *items):
self.items = tuple(items)
@ -241,10 +230,10 @@ class ListContaining(Some):
class DictContaining(Some):
"""Matches any dict that contains the specified key-value pairs::
d1 = {'a': 1, 'b': 2, 'c': 3}
d2 = {'a': 1, 'b': 2}
assert d1 == some.dict.containing(d2)
assert d2 != some.dict.containing(d1)
d1 = {'a': 1, 'b': 2, 'c': 3}
d2 = {'a': 1, 'b': 2}
assert d1 == some.dict.containing(d2)
assert d2 != some.dict.containing(d1)
"""
def __init__(self, items):
@ -268,8 +257,7 @@ class DictContaining(Some):
class Also(Some):
"""Base class for patterns that narrow down another pattern.
"""
"""Base class for patterns that narrow down another pattern."""
def __init__(self, pattern):
self.pattern = pattern
@ -282,8 +270,7 @@ class Also(Some):
class SuchThat(Also):
"""Matches only if condition is true.
"""
"""Matches only if condition is true."""
def __init__(self, pattern, condition):
super(SuchThat, self).__init__(pattern)
@ -300,8 +287,7 @@ class SuchThat(Also):
class InRange(Also):
"""Matches only if the value is within the specified range.
"""
"""Matches only if the value is within the specified range."""
def __init__(self, pattern, start, stop):
super(InRange, self).__init__(pattern)
@ -319,8 +305,7 @@ class InRange(Also):
class EqualTo(Also):
"""Matches any object that is equal to the specified object.
"""
"""Matches any object that is equal to the specified object."""
def __init__(self, pattern, obj):
super(EqualTo, self).__init__(pattern)
@ -340,8 +325,7 @@ class EqualTo(Also):
class NotEqualTo(Also):
"""Matches any object that is not equal to the specified object.
"""
"""Matches any object that is not equal to the specified object."""
def __init__(self, pattern, obj):
super(NotEqualTo, self).__init__(pattern)
@ -355,8 +339,7 @@ class NotEqualTo(Also):
class SameAs(Also):
"""Matches one specific object only (i.e. makes '==' behave like 'is').
"""
"""Matches one specific object only (i.e. makes '==' behave like 'is')."""
def __init__(self, pattern, obj):
super(SameAs, self).__init__(pattern)
@ -370,8 +353,7 @@ class SameAs(Also):
class Matching(Also):
"""Matches any string that matches the specified regular expression.
"""
"""Matches any string that matches the specified regular expression."""
def __init__(self, pattern, regex, flags=0):
assert isinstance(regex, bytes) or isinstance(regex, str)

View file

@ -18,8 +18,7 @@ generates those ids sequentially.
def source(path, **kwargs):
"""Matches DAP Source objects.
"""
"""Matches DAP Source objects."""
if isinstance(path, py.path.local):
path = some.path(path)
d = {"path": path}

View file

@ -139,7 +139,6 @@ if sys.platform != "win32":
def long_tmpdir(request, tmpdir):
return tmpdir
else:
import ctypes
@ -149,8 +148,7 @@ else:
@pytest.fixture
def long_tmpdir(request, tmpdir):
"""Like tmpdir, but ensures that it's a long rather than short filename on Win32.
"""
"""Like tmpdir, but ensures that it's a long rather than short filename on Win32."""
path = tmpdir.strpath
buffer = ctypes.create_unicode_buffer(512)
if GetLongPathNameW(path, buffer, len(buffer)):

View file

@ -29,7 +29,7 @@ def pytest_configure(config):
if config.option.debugpy_log_dir:
log.log_dir = config.option.debugpy_log_dir
else:
bits = 64 if sys.maxsize > 2 ** 32 else 32
bits = 64 if sys.maxsize > 2**32 else 32
ver = "{0}.{1}-{bits}".format(*sys.version_info, bits=bits)
log.log_dir = (tests.root / "_logs" / ver).strpath
log.info("debugpy and pydevd logs will be under {0}", log.log_dir)

View file

@ -15,10 +15,11 @@ from django.template import loader
exiting = False
@receiver(request_finished)
def on_request_finished(sender, **kwargs):
if exiting:
os._exit(0)
os._exit(0)
settings.configure(

View file

@ -40,6 +40,7 @@ def exit_app():
exiting = True
return "Done"
@app.teardown_request
def teardown(exception):
if exiting:

View file

@ -133,11 +133,11 @@ def test_matching():
log_repr(pattern)
assert pattern != "abbbc"
pattern = some.bytes.matching(br".(b+).")
pattern = some.bytes.matching(rb".(b+).")
log_repr(pattern)
assert pattern == b"abbbc"
pattern = some.bytes.matching(br"bbb")
pattern = some.bytes.matching(rb"bbb")
log_repr(pattern)
assert pattern != b"abbbc"

View file

@ -15,8 +15,7 @@ from tests.timeline import Timeline, Mark, Event, Request, Response
class MessageFactory(object):
"""A factory for DAP messages that are not bound to a message channel.
"""
"""A factory for DAP messages that are not bound to a message channel."""
def __init__(self):
self._seq_iter = itertools.count(1)

View file

@ -2,6 +2,7 @@
# Licensed under the MIT License. See LICENSE in the project root
# for license information.
def test_vendoring(pyfile):
@pyfile
def import_debugpy():
@ -12,15 +13,15 @@ def test_vendoring(pyfile):
class Dummy2(object):
pass
class Dummy3(object):
def __getattribute__(self, *args, **kwargs):
raise AssertionError('Error')
raise AssertionError("Error")
sys.modules["pydev_dummy"] = Dummy()
sys.modules["pydev_dummy2"] = Dummy2()
sys.modules["pydev_dummy3"] = Dummy3()
sys.modules["_pydev_dummy"] = Dummy()
sys.modules["_pydev_dummy2"] = Dummy2()
sys.modules["_pydev_dummy3"] = Dummy3()

View file

@ -951,7 +951,9 @@ class Occurrence(Expectation):
return hash(id(self))
def __repr__(self):
return ("" if self.observed else "*") + f"{self.index}.{self.describe_circumstances()}"
return (
"" if self.observed else "*"
) + f"{self.index}.{self.describe_circumstances()}"
def describe_circumstances(self):
rest = repr(self.circumstances[1:])