-
-
Notifications
You must be signed in to change notification settings - Fork 218
/
Copy pathtest_regressions.py
178 lines (145 loc) · 5.54 KB
/
test_regressions.py
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
from __future__ import annotations
import pprint
import subprocess
import sys
import textwrap
from dataclasses import replace
from importlib.metadata import EntryPoint
from importlib.metadata import distribution
from pathlib import Path
import pytest
from setuptools_scm import Configuration
from setuptools_scm._run_cmd import run
from setuptools_scm.git import parse
from setuptools_scm.integration import data_from_mime
from setuptools_scm.version import meta
from .wd_wrapper import WorkDir
def test_data_from_mime_ignores_body() -> None:
assert data_from_mime(
"test",
"version: 1.0\r\n\r\nversion: bad",
) == {"version": "1.0"}
def test_pkginfo_noscmroot(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
"""if we are indeed a sdist, the root does not apply"""
monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")
# we should get the version from pkg-info if git is broken
p = tmp_path.joinpath("sub/package")
p.mkdir(parents=True)
tmp_path.joinpath(".git").mkdir()
p.joinpath("setup.py").write_text(
"from setuptools import setup;" 'setup(use_scm_version={"root": ".."})',
encoding="utf-8",
)
res = run([sys.executable, "setup.py", "--version"], p)
assert "setuptools-scm was unable to detect version for" in res.stderr
assert res.returncode == 1
p.joinpath("PKG-INFO").write_text("Version: 1.0", encoding="utf-8")
res = run([sys.executable, "setup.py", "--version"], p)
assert res.stdout == "1.0"
try:
run("git init", p.parent)
except OSError:
pass
else:
res = run([sys.executable, "setup.py", "--version"], p)
assert res.stdout == "0.1.dev0+d20090213"
@pytest.mark.issue(164)
def test_pip_download(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.chdir(tmp_path)
subprocess.check_call([sys.executable, "-m", "pip", "download", "lz4==0.9.0"])
def test_use_scm_version_callable(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""use of callable as use_scm_version argument"""
monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")
p = tmp_path / "sub" / "package"
p.mkdir(parents=True)
p.joinpath("setup.py").write_text(
"""from setuptools import setup
def vcfg():
from setuptools_scm.version import guess_next_dev_version
def vs(v):
return guess_next_dev_version(v)
return {"version_scheme": vs}
setup(use_scm_version=vcfg)
""",
encoding="utf-8",
)
p.joinpath("PKG-INFO").write_text("Version: 1.0", encoding="utf-8")
res = run([sys.executable, "setup.py", "--version"], p)
assert res.stdout == "1.0"
@pytest.mark.skipif(sys.platform != "win32", reason="this bug is only valid on windows")
def test_case_mismatch_on_windows_git(tmp_path: Path) -> None:
"""Case insensitive path checks on Windows"""
camel_case_path = tmp_path / "CapitalizedDir"
camel_case_path.mkdir()
run("git init", camel_case_path)
res = parse(str(camel_case_path).lower(), Configuration())
assert res is not None
def test_fallback_message(wd: WorkDir, monkeypatch: pytest.MonkeyPatch) -> None:
"""Check that no warning/error messages are normally outputted"""
# setup a basic project that would not trigger any (other) warning/errors
pyproject = """\
[build-system]
requires = ["setuptools", "setuptools_scm"]
build-backend = "setuptools.build_meta"
[project]
name = "example"
dynamic = ["version"]
[tool.setuptools_scm]
"""
git_archival = """\
node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
"""
wd.write("pyproject.toml", textwrap.dedent(pyproject))
wd.write(".git_archival.txt", textwrap.dedent(git_archival))
wd.write(".gitattributes", ".git_archival.txt export-subst")
wd.write("README.md", "")
wd("git init")
wd("git config user.email user@host")
wd("git config user.name user")
wd.add_command = "git add ."
wd.commit_command = "git commit -m test-{reason}"
wd.add_and_commit()
wd("git tag v0.1.0")
version = wd.get_version()
assert version == "0.1.0"
# Run build and check messages
monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")
# with caplog.at_level(logging.WARN):
res_build = subprocess.run(
[sys.executable, "-m", "build", "-nx"],
cwd=wd.cwd,
capture_output=True,
)
assert res_build.returncode == 0
# Maybe there is a cleaner way to use caplog?
assert not res_build.stderr
def test_entrypoints_load() -> None:
d = distribution("setuptools-scm")
eps = d.entry_points
failed: list[tuple[EntryPoint, Exception]] = []
for ep in eps:
try:
ep.load()
except Exception as e:
failed.append((ep, e))
if failed:
pytest.fail(pprint.pformat(failed))
def test_write_to_absolute_path_passes_when_subdir_of_root(tmp_path: Path) -> None:
c = Configuration(root=tmp_path, write_to=tmp_path / "VERSION.py")
v = meta("1.0", config=c)
from setuptools_scm._get_version_impl import write_version_files
with pytest.warns(DeprecationWarning, match=".*write_to=.* is a absolute.*"):
write_version_files(c, "1.0", v)
write_version_files(replace(c, write_to="VERSION.py"), "1.0", v)
subdir = tmp_path / "subdir"
subdir.mkdir()
with pytest.raises(
# todo: python version specific error list
ValueError,
match=".*VERSION.py' .* .*subdir.*",
):
write_version_files(replace(c, root=subdir), "1.0", v)