1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root
# for license information.
"""Patterns that are specific to the Debug Adapter Protocol.
"""
import py.path
from tests import code
from tests.patterns import some, _impl
id = some.int.in_range(0, 10000)
"""Matches a DAP "id", assuming some reasonable range for an implementation that
generates those ids sequentially.
"""
def source(path, **kwargs):
"""Matches DAP Source objects."""
if isinstance(path, py.path.local):
path = some.path(path)
d = {"path": path}
d.update(kwargs)
return some.dict.containing(d)
def frame(source, line, column=some.int, **kwargs):
"""Matches DAP Frame objects.
If source is py.path.local, it's automatically wrapped with some.dap.source().
If line is str, it is treated as a line marker, and translated to a line
number via get_marked_line_numbers(source["path"]) if possible.
"""
if isinstance(source, py.path.local):
source = some.dap.source(source)
if isinstance(line, str):
if isinstance(source, dict):
path = source["path"]
elif isinstance(source, _impl.DictContaining):
path = source.items["path"]
else:
path = None
assert isinstance(
path, _impl.Path
), "source must be some.dap.source() to use line markers in some.dap.frame()"
line = code.get_marked_line_numbers(path.path)[line]
d = {"id": some.dap.id, "source": source, "line": line, "column": column}
d.update(kwargs)
return some.dict.containing(d)
|