Repository: pypa/virtualenv

Issue:
Add the tests/ directory to the tarball.
Users should now be able to run "python setup.py test".

---

_This was automatically migrated from pypa/virtualenv#561 to reparent it to the `master` branch. Please see original pull request for any previous discussion._

_Original Submitter: @Steap_



Discussion:

Resolving patch:
diff --git a/bin/rebuild-script.py b/tasks/update_embedded.py
similarity index 100%
rename from bin/rebuild-script.py
rename to tasks/update_embedded.py
diff --git a/bin/rebuild-support.py b/tasks/upgrade_wheels.py
similarity index 100%
rename from bin/rebuild-support.py
rename to tasks/upgrade_wheels.py


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -2,11 +2,19 @@
 
 import os
 import subprocess
+import sys
 
 import pytest
 
 import virtualenv
 
+try:
+    from pathlib import Path
+except ImportError:
+    from pathlib2 import Path
+
+ROOT_DIR = Path(__file__).parents[1]
+
 
 @pytest.fixture(scope="session")
 def clean_python(tmp_path_factory):
@@ -32,3 +40,57 @@ def clean_python(tmp_path_factory):
         os.chdir(str(prev_cwd))
 
     yield home_dir, bin_dir, pydoc_test
+
+
+@pytest.fixture()
+def sdist(tmp_path):
+    """make assertions on what we package"""
+    import tarfile
+
+    path = os.environ.get("TOX_PACKAGE")
+    if path is not None:
+        dest_path = tmp_path / "sdist"
+        dest_path.mkdir()
+        prev = os.getcwd()
+        try:
+            os.chdir(str(dest_path))
+            tar = tarfile.open(path, "r:gz")
+            tar.extractall()
+            return next(dest_path.iterdir())
+        finally:
+            os.chdir(prev)
+    return None
+
+
+@pytest.fixture(scope="session")
+def wheel(tmp_path_factory):
+    """test that we can create a virtual environment by feeding to a clean python the wheels content"""
+    dest_path = tmp_path_factory.mktemp("wheel")
+    env = os.environ.copy()
+    if virtualenv.IS_JYTHON:
+        env[str("PIP_NO_CACHE_DIR")] = str("off")
+    try:
+        subprocess.check_output(
+            [sys.executable, "-m", "pip", "wheel", "-w", str(dest_path), "--no-deps", str(ROOT_DIR)],
+            universal_newlines=True,
+            stderr=subprocess.STDOUT,
+            env=env,
+        )
+    except subprocess.CalledProcessError as exception:
+        assert not exception.returncode, exception.output
+
+    wheels = list(dest_path.glob("*.whl"))
+    assert len(wheels) == 1
+    wheel = wheels[0]
+    return wheel
+
+
+@pytest.fixture()
+def extracted_wheel(tmp_path, wheel):
+    dest_path = tmp_path / "wheel-extracted"
+
+    import zipfile
+
+    with zipfile.ZipFile(str(wheel), "r") as zip_ref:
+        zip_ref.extractall(str(dest_path))
+    return dest_path
diff --git a/tests/test_from_source.py b/tests/test_from_source.py
--- a/tests/test_from_source.py
+++ b/tests/test_from_source.py
@@ -3,7 +3,6 @@
 
 import os
 import subprocess
-import sys
 
 import pytest
 
@@ -36,15 +35,9 @@ def test_use_from_source_tree(tmp_path, clean_python, monkeypatch):
 
 
 @pytest.mark.skipif(os.environ.get("TOX_PACKAGE") is None, reason="needs tox provisioned sdist")
-def test_use_from_source_sdist(tmp_path, clean_python, monkeypatch):
+def test_use_from_source_sdist(sdist, tmp_path, clean_python, monkeypatch):
     """test that we can create a virtual environment by feeding to a clean python the sdist content"""
-    monkeypatch.chdir(tmp_path)
-    import tarfile
-
-    tar = tarfile.open(os.environ.get("TOX_PACKAGE"), "r:gz")
-    tar.extractall()
-
-    virtualenv_file = next(tmp_path.iterdir()) / "virtualenv.py"
+    virtualenv_file = sdist / "virtualenv.py"
     assert virtualenv_file.exists()
 
     try:
@@ -58,34 +51,15 @@ def test_use_from_source_sdist(tmp_path, clean_python, monkeypatch):
         assert not exception.returncode, exception.output
 
 
-def test_use_from_wheel(tmp_path, clean_python, monkeypatch):
+def test_use_from_wheel(tmp_path, extracted_wheel, clean_python, monkeypatch):
     """test that we can create a virtual environment by feeding to a clean python the wheels content"""
+    virtualenv_file = extracted_wheel / "virtualenv.py"
     try:
-        env = os.environ.copy()
-        if virtualenv.IS_JYTHON:
-            env[str("PIP_NO_CACHE_DIR")] = str("off")
+        monkeypatch.chdir(tmp_path)
         subprocess.check_output(
-            [sys.executable, "-m", "pip", "wheel", "-w", str(tmp_path), "--no-deps", str(ROOT_DIR)],
+            [str(Path(clean_python[1]) / virtualenv.EXPECTED_EXE), str(virtualenv_file), "--no-download", "env"],
             universal_newlines=True,
             stderr=subprocess.STDOUT,
-            env=env,
         )
-        wheels = list(tmp_path.glob("*.whl"))
-        assert len(wheels) == 1
-        wheel = wheels[0]
-        import zipfile
-
-        with zipfile.ZipFile(str(wheel), "r") as zip_ref:
-            zip_ref.extractall(str(tmp_path / "out"))
-        virtualenv_file = tmp_path / "out" / "virtualenv.py"
-        try:
-            monkeypatch.chdir(tmp_path)
-            subprocess.check_output(
-                [str(Path(clean_python[1]) / virtualenv.EXPECTED_EXE), str(virtualenv_file), "--no-download", "env"],
-                universal_newlines=True,
-                stderr=subprocess.STDOUT,
-            )
-        except subprocess.CalledProcessError as exception:
-            assert not exception.returncode, exception.output
     except subprocess.CalledProcessError as exception:
         assert not exception.returncode, exception.output
diff --git a/tests/test_source_content.py b/tests/test_source_content.py
new file mode 100644
--- /dev/null
+++ b/tests/test_source_content.py
@@ -0,0 +1,62 @@
+import os
+
+import pytest
+
+import virtualenv
+
+
+@pytest.mark.skipif(os.environ.get("TOX_PACKAGE") is None, reason="needs tox provisioned sdist")
+def test_sdist_contains(sdist):
+    """make assertions on what we package"""
+    content = set(sdist.iterdir())
+
+    names = {i.name for i in content}
+
+    must_have = {
+        # sources
+        "virtualenv.py",
+        "virtualenv_embedded",
+        "virtualenv_support",
+        "setup.py",
+        "setup.cfg",
+        "scripts",
+        "MANIFEST.in",
+        "pyproject.toml",
+        # test files
+        "tests",
+        # documentation
+        "docs",
+        "README.rst",
+        # helpers
+        "tasks",
+        "tox.ini",
+        # meta-data
+        "AUTHORS.txt",
+        "LICENSE.txt",
+    }
+
+    assert not (must_have - names)
+
+    assert not (names - must_have - {"PKG-INFO", "virtualenv.egg-info"})
+
+
+def test_wheel_contains(extracted_wheel):
+    content = set(extracted_wheel.iterdir())
+
+    names = {i.name for i in content}
+    must_have = {
+        # sources
+        "virtualenv.py",
+        "virtualenv_support",
+        "virtualenv-{}.dist-info".format(virtualenv.__version__),
+    }
+    assert must_have == names
+
+    support = {i.name for i in (extracted_wheel / "virtualenv_support").iterdir()}
+    assert "__init__.py" in support
+    for package in ("pip", "wheel", "setuptools"):
+        assert any(package in i for i in support)
+
+    meta = {i.name for i in (extracted_wheel / "virtualenv-{}.dist-info".format(virtualenv.__version__)).iterdir()}
+    assert "LICENSE.txt" in meta
+    assert "AUTHORS.txt" in meta