|
| 1 | +import shutil |
| 2 | +from collections.abc import Generator |
| 3 | +from pathlib import Path |
| 4 | +from tempfile import TemporaryDirectory |
| 5 | + |
| 6 | +import pytest |
| 7 | + |
| 8 | +from usethis._integrations.uv.call import call_uv_subprocess |
| 9 | +from usethis._subprocess import call_subprocess |
| 10 | +from usethis._test import change_cwd |
| 11 | + |
| 12 | + |
| 13 | +@pytest.fixture |
| 14 | +def usethis_installed_dir( |
| 15 | + uv_init_dir: Path, usethis_dev_dir: Path |
| 16 | +) -> Generator[Path, None, None]: |
| 17 | + with TemporaryDirectory() as tmp_path: |
| 18 | + # Make a copy of the current usethis codebase to avoid interacting with pytest |
| 19 | + copy_usethis_dev_dir = Path(tmp_path) / "usethis-python" |
| 20 | + shutil.copytree( |
| 21 | + usethis_dev_dir, |
| 22 | + copy_usethis_dev_dir, |
| 23 | + # The git repo is too big and we don't need it |
| 24 | + ignore=shutil.ignore_patterns(".git"), |
| 25 | + ) |
| 26 | + |
| 27 | + with change_cwd(copy_usethis_dev_dir): |
| 28 | + # Initialize a git repository so the package can be built (since it relies |
| 29 | + # on vcs) |
| 30 | + call_subprocess(["git", "init"]) |
| 31 | + call_subprocess(["git", "add", "."]) |
| 32 | + call_subprocess(["git", "commit", "-m", "Initial commit"]) |
| 33 | + |
| 34 | + with change_cwd(uv_init_dir): |
| 35 | + # Install usethis in a virtual environment |
| 36 | + call_uv_subprocess(["add", f"{copy_usethis_dev_dir.as_posix()}"]) |
| 37 | + |
| 38 | + yield uv_init_dir |
| 39 | + |
| 40 | + |
| 41 | +class TestInstalledInOwnVenv: |
| 42 | + def test_help(self, usethis_installed_dir): |
| 43 | + with change_cwd(usethis_installed_dir): |
| 44 | + # Should run without error |
| 45 | + call_subprocess(["usethis", "--help"]) |
| 46 | + |
| 47 | + def test_add_pytest(self, usethis_installed_dir): |
| 48 | + with change_cwd(usethis_installed_dir): |
| 49 | + # Should run without error |
| 50 | + call_subprocess(["usethis", "tool", "pytest"]) |
0 commit comments