Skip to content

Commit 4eb116a

Browse files
committed
Clean variant command tests up
Use a dedicated test package instead of reusing the plugin package, as suggested by Jonathan Dekhtiar. Put a fixed `/dev/null` plugin path in metadata to avoid checksum mismatches (and make updating artifacts easier), and mock the plugin loader instead.
1 parent cb3c8c2 commit 4eb116a

14 files changed

+60
-73
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[build-system]
2+
requires = ["flit_core >=3.11,<4"]
3+
build-backend = "flit_core.buildapi"
4+
5+
[project]
6+
name = "test-package"
7+
version = "0"
8+
description = "Installable package for testing"
9+
requires-python = ">=3.9"

tests/artifacts/test-package/test_package.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
925 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

tests/commands/test_analyze_wheel.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,28 @@
55
from variantlib.commands.main import main
66

77
if TYPE_CHECKING:
8-
from pathlib import Path
9-
108
import pytest
119

1210

1311
def test_analyze_wheel_regular(
1412
caplog: pytest.LogCaptureFixture,
1513
capsys: pytest.CaptureFixture[str],
1614
mocked_entry_points: None,
17-
test_plugin_package_wheel_path: Path,
1815
) -> None:
19-
main(["analyze-wheel", "-i", str(test_plugin_package_wheel_path)])
16+
main(["analyze-wheel", "-i", "tests/artifacts/test_package-0-py3-none-any.whl"])
2017
assert capsys.readouterr().out == ""
2118
assert "Standard Wheel" in caplog.text
2219

2320

2421
def test_analyze_wheel_null_variant(
2522
capsys: pytest.CaptureFixture[str],
2623
mocked_entry_points: None,
27-
test_plugin_package_wheel_path: Path,
2824
) -> None:
2925
main(
3026
[
3127
"analyze-wheel",
3228
"-i",
33-
"tests/artifacts/test_plugin_package-0-py3-none-any-00000000.whl",
29+
"tests/artifacts/test_package-0-py3-none-any-00000000.whl",
3430
]
3531
)
3632
assert (
@@ -45,13 +41,12 @@ def test_analyze_wheel_null_variant(
4541
def test_analyze_wheel_variant(
4642
capsys: pytest.CaptureFixture[str],
4743
mocked_entry_points: None,
48-
test_plugin_package_wheel_path: Path,
4944
) -> None:
5045
main(
5146
[
5247
"analyze-wheel",
5348
"-i",
54-
"tests/artifacts/test_plugin_package-0-py3-none-any-5d8be4b9.whl",
49+
"tests/artifacts/test_package-0-py3-none-any-5d8be4b9.whl",
5550
]
5651
)
5752
assert (

tests/commands/test_generate_index_json.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,16 @@ def test_generate_index_json(
1111
tmp_path: Path,
1212
) -> None:
1313
filenames = [
14-
"test_plugin_package-0-py3-none-any.whl",
15-
"test_plugin_package-0-py3-none-any-00000000.whl",
16-
"test_plugin_package-0-py3-none-any-5d8be4b9.whl",
17-
"test_plugin_package-0-py3-none-any-ac31c899.whl",
14+
"test_package-0-py3-none-any.whl",
15+
"test_package-0-py3-none-any-00000000.whl",
16+
"test_package-0-py3-none-any-5d8be4b9.whl",
1817
]
1918
artifact_dir = Path("tests/artifacts")
2019
for filename in filenames:
2120
copy(artifact_dir / filename, tmp_path / filename)
2221

2322
main(["generate-index-json", "-d", str(tmp_path)])
24-
assert json.loads(
25-
(tmp_path / "test_plugin_package-0-variants.json").read_text()
26-
) == {
23+
assert json.loads((tmp_path / "test_package-0-variants.json").read_text()) == {
2724
"$schema": "https://variants-schema.wheelnext.dev/",
2825
"default-priorities": {
2926
"feature": {},
@@ -35,10 +32,7 @@ def test_generate_index_json(
3532
"providers": {
3633
"installable_plugin": {
3734
"plugin-api": "test_plugin_package",
38-
"requires": [
39-
"test-plugin-package @ "
40-
"file://{plugin_path}/test_plugin_package-0-py3-none-any.whl",
41-
],
35+
"requires": ["test-plugin-package @ file:///dev/null"],
4236
},
4337
},
4438
"variants": {
@@ -49,10 +43,5 @@ def test_generate_index_json(
4943
"feat2": "val2b",
5044
},
5145
},
52-
"ac31c899": {
53-
"foo": {
54-
"bar": "baz",
55-
},
56-
},
5746
},
5847
}

0 commit comments

Comments
 (0)