From 7268c4b94df21e021d46187bd52d174700ad3663 Mon Sep 17 00:00:00 2001 From: Paul O'Leary McCann Date: Tue, 24 Jan 2023 18:41:41 +0900 Subject: [PATCH] Attempt to fix git cleanup on Windows --- spacy/tests/test_cli_app.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/spacy/tests/test_cli_app.py b/spacy/tests/test_cli_app.py index 59dfa3936..7ee48b6ff 100644 --- a/spacy/tests/test_cli_app.py +++ b/spacy/tests/test_cli_app.py @@ -1,8 +1,11 @@ import os from pathlib import Path -from typer.testing import CliRunner -import srsly import pytest +import shutil +import srsly +import stat +from typer.testing import CliRunner +import tempfile from spacy.cli._util import app from .util import make_tempdir @@ -101,12 +104,23 @@ def test_project_run(project_dir): def test_project_clone(): - with make_tempdir() as workspace: + # Git clones create some readonly/hidden files. On Windows, trying to + # delete these gives an error, so we have to handle that specially. + + workspace = Path(tempfile.mkdtemp()) + + def _fix_perms(func, path, exc_info): + os.chmod(path, stat.S_IWUSR) + func(path) + + try: out = workspace / "project" target = "benchmarks/ner_conll03" result = CliRunner().invoke(app, ["project", "clone", target, str(out)]) assert result.exit_code == 0 assert (out / "README.md").is_file() + finally: + shutil.rmtree(str(workspace), ignore_errors=False, onerror=_fix_perms) def test_project_push_pull(project_dir):