Skip to content

Commit a76b6e8

Browse files
committed
Add a test for analyze-platform command
1 parent 4706313 commit a76b6e8

File tree

4 files changed

+56
-14
lines changed

4 files changed

+56
-14
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING
4+
5+
from variantlib.commands.main import main
6+
7+
if TYPE_CHECKING:
8+
import pytest
9+
10+
11+
def test_analyze_platform(
12+
capsys: pytest.CaptureFixture[str],
13+
mocked_entry_points: None,
14+
) -> None:
15+
main(["analyze-platform"])
16+
assert (
17+
capsys.readouterr().out
18+
== """
19+
#################### Provider Config: `test_namespace` ####################
20+
\t- Variant Config [001]: name1 :: ['val1a', 'val1b']
21+
\t- Variant Config [002]: name2 :: ['val2a', 'val2b', 'val2c']
22+
###########################################################################
23+
24+
#################### Provider Config: `second_namespace` ####################
25+
\t- Variant Config [001]: name3 :: ['val3a']
26+
#############################################################################
27+
"""
28+
)

tests/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
from pathlib import Path
44

55
import pytest
6+
from pytest_mock import MockerFixture
67

8+
from tests.mocked_plugins import MockedEntryPoint
79
from variantlib.plugins.loader import BasePluginLoader
810
from variantlib.plugins.loader import ListPluginLoader
911

@@ -26,3 +28,15 @@ def mocked_plugin_loader(
2628
) -> Generator[BasePluginLoader]:
2729
with ListPluginLoader(mocked_plugin_apis) as loader:
2830
yield loader
31+
32+
33+
@pytest.fixture
34+
def mocked_entry_points(
35+
mocker: MockerFixture,
36+
mocked_plugin_apis: list[str],
37+
) -> None:
38+
mocker.patch("variantlib.plugins.loader.entry_points")().select.return_value = [
39+
MockedEntryPoint("test", "tests.mocked_plugins:MockedPluginA"),
40+
MockedEntryPoint("second", "tests.mocked_plugins:MockedPluginB"),
41+
MockedEntryPoint("third", "tests.mocked_plugins:MockedPluginC"),
42+
]

tests/mocked_plugins.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
from __future__ import annotations
22

33
from collections import namedtuple
4+
from dataclasses import dataclass
45

56
from variantlib.models.provider import VariantFeatureConfig
67
from variantlib.protocols import PluginType
78
from variantlib.protocols import VariantFeatureConfigType
89
from variantlib.protocols import VariantPropertyType
910

1011

12+
@dataclass
13+
class MockedEntryPoint:
14+
name: str | None
15+
value: str
16+
dist: None = None
17+
18+
1119
class MockedPluginA(PluginType):
1220
namespace = "test_namespace"
1321

tests/plugins/test_loader.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import sys
66
from abc import ABC
77
from abc import abstractproperty
8-
from dataclasses import dataclass
98
from email import message_from_string
109
from pathlib import Path
1110
from typing import Any
@@ -437,20 +436,13 @@ def test_load_plugins_from_metadata(metadata: VariantMetadata):
437436
assert set(loader.namespaces) == {"test_namespace", "second_namespace"}
438437

439438

440-
@dataclass
441-
class MockedEntryPoint:
442-
name: str | None
443-
value: str
444-
dist: None = None
445-
446-
447-
def test_load_plugins_from_entry_points(mocker):
448-
mocker.patch("variantlib.plugins.loader.entry_points")().select.return_value = [
449-
MockedEntryPoint("test", "tests.mocked_plugins:MockedPluginA"),
450-
MockedEntryPoint("second", "tests.mocked_plugins:MockedPluginB"),
451-
]
439+
def test_load_plugins_from_entry_points(mocked_entry_points: None) -> None:
452440
with EntryPointPluginLoader() as loader:
453-
assert set(loader.namespaces) == {"test_namespace", "second_namespace"}
441+
assert set(loader.namespaces) == {
442+
"test_namespace",
443+
"second_namespace",
444+
"incompatible_namespace",
445+
}
454446

455447

456448
def test_install_plugin():

0 commit comments

Comments
 (0)