mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-07 21:54:54 +03:00
Add test for run_commands
This commit is contained in:
parent
e13e11e1d8
commit
0989ccdc8a
|
@ -25,6 +25,7 @@ def project_update_dvc_cli(
|
|||
project_dir: Path = Arg(Path.cwd(), help="Location of project directory. Defaults to current working directory.", exists=True, file_okay=False),
|
||||
workflow: Optional[str] = Arg(None, help=f"Name of workflow defined in {PROJECT_FILE}. Defaults to first workflow if not set."),
|
||||
verbose: bool = Opt(False, "--verbose", "-V", help="Print more info"),
|
||||
quiet: bool = Opt(False, "--quiet", "-q", help="Print less info"),
|
||||
force: bool = Opt(False, "--force", "-F", help="Force update DVC config"),
|
||||
# fmt: on
|
||||
):
|
||||
|
@ -36,7 +37,7 @@ def project_update_dvc_cli(
|
|||
|
||||
DOCS: https://spacy.io/api/cli#project-dvc
|
||||
"""
|
||||
project_update_dvc(project_dir, workflow, verbose=verbose, force=force)
|
||||
project_update_dvc(project_dir, workflow, verbose=verbose, quiet=quiet, force=force)
|
||||
|
||||
|
||||
def project_update_dvc(
|
||||
|
@ -44,6 +45,7 @@ def project_update_dvc(
|
|||
workflow: Optional[str] = None,
|
||||
*,
|
||||
verbose: bool = False,
|
||||
quiet: bool = False,
|
||||
force: bool = False,
|
||||
) -> None:
|
||||
"""Update the auto-generated Data Version Control (DVC) config file. A DVC
|
||||
|
@ -54,11 +56,12 @@ def project_update_dvc(
|
|||
workflow (Optional[str]): Optional name of workflow defined in project.yml.
|
||||
If not set, the first workflow will be used.
|
||||
verbose (bool): Print more info.
|
||||
quiet (bool): Print less info.
|
||||
force (bool): Force update DVC config.
|
||||
"""
|
||||
config = load_project_config(project_dir)
|
||||
updated = update_dvc_config(
|
||||
project_dir, config, workflow, verbose=verbose, force=force
|
||||
project_dir, config, workflow, verbose=verbose, quiet=quiet, force=force
|
||||
)
|
||||
help_msg = "To execute the workflow with DVC, run: dvc repro"
|
||||
if updated:
|
||||
|
@ -72,7 +75,7 @@ def update_dvc_config(
|
|||
config: Dict[str, Any],
|
||||
workflow: Optional[str] = None,
|
||||
verbose: bool = False,
|
||||
silent: bool = False,
|
||||
quiet: bool = False,
|
||||
force: bool = False,
|
||||
) -> bool:
|
||||
"""Re-run the DVC commands in dry mode and update dvc.yaml file in the
|
||||
|
@ -83,7 +86,7 @@ def update_dvc_config(
|
|||
path (Path): The path to the project directory.
|
||||
config (Dict[str, Any]): The loaded project.yml.
|
||||
verbose (bool): Whether to print additional info (via DVC).
|
||||
silent (bool): Don't output anything (via DVC).
|
||||
quiet (bool): Don't output anything (via DVC).
|
||||
force (bool): Force update, even if hashes match.
|
||||
RETURNS (bool): Whether the DVC config file was updated.
|
||||
"""
|
||||
|
@ -107,10 +110,13 @@ def update_dvc_config(
|
|||
config_commands = {cmd["name"]: cmd for cmd in config.get("commands", [])}
|
||||
|
||||
# some flags that apply to every command
|
||||
if verbose and quiet:
|
||||
# don't allow contradictions
|
||||
msg.fail("Can't set both --verbose and --quiet", exits=1)
|
||||
flags = []
|
||||
if verbose:
|
||||
flags.append("--verbose")
|
||||
if silent:
|
||||
if quiet:
|
||||
flags.append("--quiet")
|
||||
|
||||
for name in workflows[workflow]:
|
||||
|
|
|
@ -25,6 +25,7 @@ from spacy.cli.download import get_compatibility, get_version
|
|||
from spacy.cli.init_config import RECOMMENDATIONS, init_config, fill_config
|
||||
from spacy.cli.package import get_third_party_dependencies
|
||||
from spacy.cli.package import _is_permitted_package_name
|
||||
from spacy.cli.project.run import run_commands
|
||||
from spacy.cli.validate import get_model_pkgs
|
||||
from spacy.compat import is_windows
|
||||
from spacy.lang.en import English
|
||||
|
@ -880,6 +881,8 @@ def test_shell_quoting(tmp_path):
|
|||
ls_cmd = "dir" if is_windows else "ls"
|
||||
ret = run_command(f'{ls_cmd} "a b/c"')
|
||||
assert ret.returncode == 0
|
||||
# check outside the commands
|
||||
assert os.path.isdir(tmp_path / "a b" / "c")
|
||||
# since this is a temp dir, we don't have to delete it explicitly
|
||||
except:
|
||||
# we failed, so make sure the test fails.
|
||||
|
@ -887,3 +890,20 @@ def test_shell_quoting(tmp_path):
|
|||
finally:
|
||||
# restore the original cwd so other tests are unaffected
|
||||
os.chdir(cwd)
|
||||
|
||||
|
||||
def test_run_commands(tmp_path):
|
||||
# minimal test
|
||||
cwd = os.getcwd()
|
||||
os.chdir(tmp_path)
|
||||
try:
|
||||
ls_cmd = "dir" if is_windows else "ls"
|
||||
run_commands(["mkdir x", f"{ls_cmd} x"])
|
||||
# check outside the commands
|
||||
assert os.path.isdir(tmp_path / "x")
|
||||
except:
|
||||
# we failed, so make sure the test fails.
|
||||
raise
|
||||
finally:
|
||||
# restore the original cwd so other tests are unaffected
|
||||
os.chdir(cwd)
|
||||
|
|
Loading…
Reference in New Issue
Block a user