File tree Expand file tree Collapse file tree 4 files changed +56
-14
lines changed Expand file tree Collapse file tree 4 files changed +56
-14
lines changed Original file line number Diff line number Diff line change
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
+ )
Original file line number Diff line number Diff line change 3
3
from pathlib import Path
4
4
5
5
import pytest
6
+ from pytest_mock import MockerFixture
6
7
8
+ from tests .mocked_plugins import MockedEntryPoint
7
9
from variantlib .plugins .loader import BasePluginLoader
8
10
from variantlib .plugins .loader import ListPluginLoader
9
11
@@ -26,3 +28,15 @@ def mocked_plugin_loader(
26
28
) -> Generator [BasePluginLoader ]:
27
29
with ListPluginLoader (mocked_plugin_apis ) as loader :
28
30
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
+ ]
Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
3
3
from collections import namedtuple
4
+ from dataclasses import dataclass
4
5
5
6
from variantlib .models .provider import VariantFeatureConfig
6
7
from variantlib .protocols import PluginType
7
8
from variantlib .protocols import VariantFeatureConfigType
8
9
from variantlib .protocols import VariantPropertyType
9
10
10
11
12
+ @dataclass
13
+ class MockedEntryPoint :
14
+ name : str | None
15
+ value : str
16
+ dist : None = None
17
+
18
+
11
19
class MockedPluginA (PluginType ):
12
20
namespace = "test_namespace"
13
21
Original file line number Diff line number Diff line change 5
5
import sys
6
6
from abc import ABC
7
7
from abc import abstractproperty
8
- from dataclasses import dataclass
9
8
from email import message_from_string
10
9
from pathlib import Path
11
10
from typing import Any
@@ -437,20 +436,13 @@ def test_load_plugins_from_metadata(metadata: VariantMetadata):
437
436
assert set (loader .namespaces ) == {"test_namespace" , "second_namespace" }
438
437
439
438
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 :
452
440
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
+ }
454
446
455
447
456
448
def test_install_plugin ():
You can’t perform that action at this time.
0 commit comments