summaryrefslogtreecommitdiff
path: root/testing/test_setuptools_support.py
blob: ce3444e5a1296d6d1e626ecc0b92931b3e3361d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""
integration tests that check setuptools version support
"""
import sys
import os
import subprocess
import pytest

pytestmark = [
    pytest.mark.skipif(
        "sys.version_info >= (3,6,0)",
        reason="integration with old versions no longer needed on py3.6+",
    ),
    pytest.mark.xfail(
        sys.platform == "win32", reason="path behaves unexpected on windows ci"
    ),
]


@pytest.fixture(scope="session")
def get_setuptools_packagedir(request):
    targets = request.config.cache.makedir("setuptools_installs")

    def makeinstall(version):
        target = targets.ensure(version, dir=1)
        subprocess.check_call(
            [
                sys.executable,
                "-m",
                "pip",
                "install",
                "--no-binary",
                "setuptools",
                "setuptools==" + version,
                "-t",
                str(target),
            ]
        )
        return target

    return makeinstall


SCRIPT = """
from __future__ import print_function
import sys
import setuptools
print(setuptools.__version__, 'expected', sys.argv[1])
import setuptools_scm.version
from setuptools_scm.__main__ import main
main()
"""


def check(packagedir, expected_version, **env):

    old_pythonpath = os.environ.get("PYTHONPATH")
    if old_pythonpath:
        pythonpath = "{}:{}".format(old_pythonpath, packagedir)
    else:
        pythonpath = str(packagedir)
    subprocess.check_call(
        [sys.executable, "-c", SCRIPT, expected_version],
        env=dict(os.environ, PYTHONPATH=pythonpath, **env),
    )


def test_old_setuptools_fails(get_setuptools_packagedir):
    packagedir = get_setuptools_packagedir("0.9.8")
    with pytest.raises(subprocess.CalledProcessError):
        check(packagedir, "0.9.8")


def test_old_setuptools_allows_with_warnings(get_setuptools_packagedir):

    packagedir = get_setuptools_packagedir("0.9.8")
    # filter using warning since in the early python startup
    check(packagedir, "0.9.8", PYTHONWARNINGS="once::Warning")


def test_distlib_setuptools_works(get_setuptools_packagedir):
    packagedir = get_setuptools_packagedir("12.0.1")
    check(packagedir, "12.0.1")