|
| 1 | +import os |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | + |
| 7 | +@pytest.mark.install |
| 8 | +@pytest.mark.needs_internet |
| 9 | +@pytest.mark.skipif( |
| 10 | + os.name == "nt", |
| 11 | + reason="This test is not for Windows", |
| 12 | +) |
| 13 | +def test_install_path_with_spaces(pipenv_instance_pypi): |
| 14 | + with pipenv_instance_pypi() as p: |
| 15 | + # Create a test directory with spaces in the name |
| 16 | + test_dir = Path(p.path) / "test dir with spaces" |
| 17 | + test_dir.mkdir() |
| 18 | + |
| 19 | + # Create a simple package in the directory with spaces |
| 20 | + package_dir = test_dir / "simple_package" |
| 21 | + package_dir.mkdir() |
| 22 | + |
| 23 | + # Create a simple setup.py file |
| 24 | + with open(package_dir / "setup.py", "w") as f: |
| 25 | + f.write(""" |
| 26 | +from setuptools import setup |
| 27 | +
|
| 28 | +setup( |
| 29 | + name="simple-package", |
| 30 | + version="0.1.0", |
| 31 | +) |
| 32 | +""") |
| 33 | + |
| 34 | + # Create the package module |
| 35 | + with open(package_dir / "simple_package.py", "w") as f: |
| 36 | + f.write(""" |
| 37 | +def hello(): |
| 38 | + return "Hello from simple package!" |
| 39 | +""") |
| 40 | + |
| 41 | + # Install the package using a path with spaces |
| 42 | + # Use both escaped spaces and quoted path to test both scenarios |
| 43 | + c = p.pipenv(f'install "{package_dir}"') |
| 44 | + assert c.returncode == 0 |
| 45 | + |
| 46 | + # Verify the package was installed correctly |
| 47 | + c = p.pipenv('run python -c "import simple_package; print(simple_package.hello())"') |
| 48 | + assert c.returncode == 0 |
| 49 | + assert "Hello from simple package!" in c.stdout |
| 50 | + |
| 51 | + # Test with escaped spaces |
| 52 | + p.pipenv("uninstall simple-package") |
| 53 | + escaped_path = package_dir.as_posix().replace(" ", "\\ ") |
| 54 | + c = p.pipenv(f'install {escaped_path}') |
| 55 | + assert c.returncode == 0 |
| 56 | + |
| 57 | + # Verify the package was installed correctly |
| 58 | + c = p.pipenv('run python -c "import simple_package; print(simple_package.hello())"') |
| 59 | + assert c.returncode == 0 |
| 60 | + assert "Hello from simple package!" in c.stdout |
0 commit comments