33# The original PyScaffold license can be found in 'NOTICE.txt'
44
55import sys
6+ from types import ModuleType
7+ from typing import Any , List
68
79import pytest
810
911from validate_pyproject import plugins
10- from validate_pyproject .plugins import ENTRYPOINT_GROUP , ErrorLoadingPlugin
12+ from validate_pyproject .plugins import ErrorLoadingPlugin
1113
1214EXISTING = (
1315 "setuptools" ,
1719
1820if sys .version_info [:2 ] >= (3 , 8 ):
1921 # TODO: Import directly (no need for conditional) when `python_requires = >= 3.8`
20- from importlib . metadata import EntryPoint # pragma: no cover
22+ from importlib import metadata # pragma: no cover
2123else :
22- from importlib_metadata import EntryPoint # pragma: no cover
24+ import importlib_metadata as metadata # pragma: no cover
2325
2426
2527def test_load_from_entry_point__error ():
2628 # This module does not exist, so Python will have some trouble loading it
27- # EntryPoint(name, value, group)
29+ # metadata. EntryPoint(name, value, group)
2830 entry = "mypkg.SOOOOO___fake___:activate"
29- fake = EntryPoint ("fake" , entry , ENTRYPOINT_GROUP )
31+ fake = metadata . EntryPoint ("fake" , entry , "validate_pyproject.tool_schema" )
3032 with pytest .raises (ErrorLoadingPlugin ):
3133 plugins .load_from_entry_point (fake )
3234
@@ -36,7 +38,7 @@ def is_entry_point(ep):
3638
3739
3840def test_iterate_entry_points ():
39- plugin_iter = plugins .iterate_entry_points ()
41+ plugin_iter = plugins .iterate_entry_points ("validate_pyproject.tool_schema" )
4042 assert hasattr (plugin_iter , "__iter__" )
4143 pluging_list = list (plugin_iter )
4244 assert all (is_entry_point (e ) for e in pluging_list )
@@ -47,14 +49,14 @@ def test_iterate_entry_points():
4749
4850def test_list_from_entry_points ():
4951 # Should return a list with all the plugins registered in the entrypoints
50- pluging_list = plugins .list_from_entry_points ()
52+ pluging_list = plugins .list_plugins_from_entry_points ()
5153 orig_len = len (pluging_list )
5254 plugin_names = " " .join (e .tool for e in pluging_list )
5355 for example in EXISTING :
5456 assert example in plugin_names
5557
5658 # a filtering function can be passed to avoid loading plugins that are not needed
57- pluging_list = plugins .list_from_entry_points (
59+ pluging_list = plugins .list_plugins_from_entry_points (
5860 filtering = lambda e : e .name != "setuptools"
5961 )
6062 plugin_names = " " .join (e .tool for e in pluging_list )
@@ -76,3 +78,32 @@ def _fn2(_):
7678
7779 pw = plugins .PluginWrapper ("name" , _fn2 )
7880 assert pw .help_text == "Help for `name`"
81+
82+
83+ def loader (name : str ) -> Any :
84+ return {"example" : "thing" }
85+
86+
87+ def dynamic_ep ():
88+ return {"some#fragment" : loader }
89+
90+
91+ class Select (list ):
92+ def select (self , group : str ) -> List [str ]:
93+ return list (self ) if group == "validate_pyproject.multi_schema" else []
94+
95+
96+ def test_process_checks (monkeypatch : pytest .MonkeyPatch ) -> None :
97+ ep = metadata .EntryPoint (
98+ name = "_" ,
99+ group = "validate_pyproject.multi_schema" ,
100+ value = "test_module:dynamic_ep" ,
101+ )
102+ sys .modules ["test_module" ] = ModuleType ("test_module" )
103+ sys .modules ["test_module" ].dynamic_ep = dynamic_ep # type: ignore[attr-defined]
104+ sys .modules ["test_module" ].loader = loader # type: ignore[attr-defined]
105+ monkeypatch .setattr (plugins , "entry_points" , lambda : Select ([ep ]))
106+ eps = plugins .list_plugins_from_entry_points ()
107+ (ep ,) = eps
108+ assert ep .tool == "some"
109+ assert ep .fragment == "fragment"
0 commit comments