From 6d594b966c8a3362b63a752710009e373091a3f7 Mon Sep 17 00:00:00 2001 From: Paul O'Leary McCann Date: Wed, 25 Jan 2023 15:42:42 +0900 Subject: [PATCH] Add debug config test and restructure The code argument imports the provided file. If it adds item to the registry, that affects global state, which CliRunner doesn't isolate. Since there's no standard way to remove things from the registry, this instead uses subprocess.run to run commands. --- spacy/tests/test_cli_app.py | 48 +++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/spacy/tests/test_cli_app.py b/spacy/tests/test_cli_app.py index 1ed51cd1f..6d4ac1f00 100644 --- a/spacy/tests/test_cli_app.py +++ b/spacy/tests/test_cli_app.py @@ -1,6 +1,7 @@ import os from pathlib import Path import pytest +import subprocess from typer.testing import CliRunner import spacy @@ -199,14 +200,47 @@ def noop_config(): yield cfg -def test_multi_code_debug_data(code_paths, data_paths, noop_config): +def test_multi_code_debug_config(code_paths, data_paths, noop_config): # check that it fails without the code arg - result = CliRunner().invoke(app, ["debug", "data", str(noop_config), *data_paths]) - assert result.exit_code == 1 + result = subprocess.run( + ["python", "-m", "spacy", "debug", "config", str(noop_config), *data_paths] + ) + assert result.returncode == 1 # check that it succeeds with the code arg - code_arg = ["--code", ",".join([str(pp) for pp in code_paths])] - result = CliRunner().invoke( - app, ["debug", "data", str(noop_config), *data_paths, *code_paths] + result = subprocess.run( + [ + "python", + "-m", + "spacy", + "debug", + "config", + str(noop_config), + *data_paths, + *code_paths, + ] ) - assert result.exit_code == 0 + assert result.returncode == 0 + + +def test_multi_code_debug_data(code_paths, data_paths, noop_config): + # check that it fails without the code arg + result = subprocess.run( + ["python", "-m", "spacy", "debug", "data", str(noop_config), *data_paths] + ) + assert result.returncode == 1 + + # check that it succeeds with the code arg + result = subprocess.run( + [ + "python", + "-m", + "spacy", + "debug", + "data", + str(noop_config), + *data_paths, + *code_paths, + ] + ) + assert result.returncode == 0