diff --git a/pythondap/python/pythondap/cli.py b/pythondap/python/pythondap/cli.py index eb2d4ac..1ea3276 100644 --- a/pythondap/python/pythondap/cli.py +++ b/pythondap/python/pythondap/cli.py @@ -12,7 +12,7 @@ def main(): parser.add_argument("-n", "--configuration") args = parser.parse_args() - ns = DebugSession( + ns = DebugSession( # noqa: F841 breakpoints=args.breakpoint, file=args.file, config_path=args.launch_configuration, diff --git a/pythondap/tests/conftest.py b/pythondap/tests/conftest.py index d663f8f..44e141d 100644 --- a/pythondap/tests/conftest.py +++ b/pythondap/tests/conftest.py @@ -1,4 +1,8 @@ from contextlib import contextmanager +import copy +import io +import json +from os import PathLike import shutil import socket import subprocess as sp @@ -8,6 +12,8 @@ import pytest +from pythondap.session import DebugSession + # vendored from LocalStack def get_free_tcp_port(blocklist: list[int] | None = None) -> int: @@ -84,3 +90,53 @@ def execute(sleep_time: int = 5): child.kill() yield execute + + +LAUNCH_TEMPLATE = { + "version": "0.2.0", + "configurations": [ + { + "name": "PLACEHOLDER", + "type": "debugpy", + "request": "launch", + "program": "PLACEHOLDER", + "justMyCode": False, + }, + ], +} + + +@pytest.fixture +def write_config(): + def inner(outfile: io.StringIO, script_path: PathLike, config_name: str): + template = copy.deepcopy(LAUNCH_TEMPLATE) + template["configurations"][0]["name"] = config_name + template["configurations"][0]["program"] = str(script_path) + json.dump(template, outfile) + + return inner + + +@pytest.fixture +def environment(run_server, tmp_path, write_config): + @contextmanager + def inner(python_code: str, breakpoints: list[int]): + script = tmp_path.joinpath("script.py") + with script.open("w") as outfile: + outfile.write(python_code) + + config_path = tmp_path.joinpath("launch.json") + config_name = "Launch" + with config_path.open("w") as outfile: + write_config(outfile, script, config_name) + + debugger = DebugSession( + breakpoints=breakpoints, + file=str(script), + config_path=str(config_path), + config_name=config_name, + program=script, + ) + yield debugger + + yield inner diff --git a/pythondap/tests/test_hooks.py b/pythondap/tests/test_hooks.py index a5e19a7..167231a 100644 --- a/pythondap/tests/test_hooks.py +++ b/pythondap/tests/test_hooks.py @@ -1,69 +1,9 @@ -from contextlib import contextmanager -import copy -import io -import json -from os import PathLike - -import pytest - -from pythondap.session import DebugSession - - PYTHON_CODE = """a = 10 b = 20 a = a + b print(a) """ -LAUNCH_TEMPLATE = { - "version": "0.2.0", - "configurations": [ - { - "name": "PLACEHOLDER", - "type": "debugpy", - "request": "launch", - "program": "PLACEHOLDER", - "justMyCode": False, - }, - ], -} - - -@pytest.fixture -def write_config(): - def inner(outfile: io.StringIO, script_path: PathLike, config_name: str): - template = copy.deepcopy(LAUNCH_TEMPLATE) - template["configurations"][0]["name"] = config_name - template["configurations"][0]["program"] = str(script_path) - json.dump(template, outfile) - - return inner - - -@pytest.fixture -def environment(run_server, tmp_path, write_config): - @contextmanager - def inner(python_code: str, breakpoints: list[int]): - script = tmp_path.joinpath("script.py") - with script.open("w") as outfile: - outfile.write(python_code) - - config_path = tmp_path.joinpath("launch.json") - config_name = "Launch" - with config_path.open("w") as outfile: - write_config(outfile, script, config_name) - - debugger = DebugSession( - breakpoints=breakpoints, - file=str(script), - config_path=str(config_path), - config_name=config_name, - program=script, - ) - yield debugger - - yield inner - def test_execute(environment): with environment(PYTHON_CODE, breakpoints=[0]) as env: