1717from .environment_context import EnvironmentContext
1818
1919
20- Group1 = EntryPoint ('group1' , 'g1' )
21- Group2 = EntryPoint ('group2' , 'g2' )
20+ Group1 = EntryPoint ('group1' , 'g1' , EXTENSION_POINT_GROUP_NAME )
21+ Group2 = EntryPoint ('group2' , 'g2' , EXTENSION_POINT_GROUP_NAME )
22+ ExtA = EntryPoint ('extA' , 'eA' , Group1 .name )
23+ ExtB = EntryPoint ('extB' , 'eB' , Group1 .name )
2224
2325
2426class Dist ():
2527
26- project_name = 'dist '
28+ version = '0.0.0 '
2729
28- def __init__ (self , group_name , group ):
29- self ._group_name = group_name
30- self ._group = group
30+ def __init__ (self , entry_points ):
31+ self .metadata = { 'Name' : f'dist- { id ( self ) } ' }
32+ self ._entry_points = entry_points
3133
32- def __lt__ (self , other ):
33- return self ._group_name < other ._group_name
34+ @property
35+ def entry_points (self ):
36+ return list (self ._entry_points )
3437
35- def get_entry_map (self ):
36- return self ._group
38+ @property
39+ def name (self ):
40+ return self .metadata ['Name' ]
3741
3842
39- def iter_entry_points (* , group ):
43+ def iter_entry_points (* , group = None ):
4044 if group == EXTENSION_POINT_GROUP_NAME :
4145 return [Group1 , Group2 ]
42- assert group == Group1 .name
43- ep1 = EntryPoint ('extA' , 'eA' )
44- ep2 = EntryPoint ('extB' , 'eB' )
45- return [ep1 , ep2 ]
46+ elif group == Group1 .name :
47+ return [ExtA , ExtB ]
48+ assert not group
49+ return {
50+ EXTENSION_POINT_GROUP_NAME : [Group1 , Group2 ],
51+ Group1 .name : [ExtA , ExtB ],
52+ }
4653
4754
48- def working_set ():
55+ def distributions ():
4956 return [
50- Dist ('group1' , {
51- 'group1' : {ep .name : ep for ep in iter_entry_points (group = 'group1' )}
52- }),
53- Dist ('group2' , {'group2' : {'extC' : EntryPoint ('extC' , 'eC' )}}),
54- Dist ('groupX' , {'groupX' : {'extD' : EntryPoint ('extD' , 'eD' )}}),
57+ Dist (iter_entry_points (group = 'group1' )),
58+ Dist ([EntryPoint ('extC' , 'eC' , Group2 .name )]),
59+ Dist ([EntryPoint ('extD' , 'eD' , 'groupX' )]),
5560 ]
5661
5762
5863def test_all_extension_points ():
5964 with patch (
60- 'colcon_core.extension_point.iter_entry_points ' ,
65+ 'colcon_core.extension_point.entry_points ' ,
6166 side_effect = iter_entry_points
6267 ):
6368 with patch (
64- 'colcon_core.extension_point.WorkingSet ' ,
65- side_effect = working_set
69+ 'colcon_core.extension_point.distributions ' ,
70+ side_effect = distributions
6671 ):
6772 # successfully load a known entry point
6873 extension_points = get_all_extension_points ()
6974 assert set (extension_points .keys ()) == {'group1' , 'group2' }
7075 assert set (extension_points ['group1' ].keys ()) == {'extA' , 'extB' }
71- assert extension_points ['group1' ]['extA' ] == (
72- 'eA' , Dist .project_name , None )
76+ assert extension_points ['group1' ]['extA' ][0 ] == 'eA'
7377
7478
7579def test_extension_point_blocklist ():
7680 # successful loading of extension point without a blocklist
7781 with patch (
78- 'colcon_core.extension_point.iter_entry_points ' ,
82+ 'colcon_core.extension_point.entry_points ' ,
7983 side_effect = iter_entry_points
8084 ):
8185 with patch (
82- 'colcon_core.extension_point.WorkingSet ' ,
83- side_effect = working_set
86+ 'colcon_core.extension_point.distributions ' ,
87+ side_effect = distributions
8488 ):
8589 extension_points = get_extension_points ('group1' )
8690 assert 'extA' in extension_points .keys ()
8791 extension_point = extension_points ['extA' ]
8892 assert extension_point == 'eA'
8993
90- with patch .object (EntryPoint , 'resolve ' , return_value = None ) as resolve :
94+ with patch .object (EntryPoint , 'load ' , return_value = None ) as load :
9195 load_extension_point ('extA' , 'eA' , 'group1' )
92- assert resolve .call_count == 1
96+ assert load .call_count == 1
9397
9498 # successful loading of entry point not in blocklist
95- resolve .reset_mock ()
99+ load .reset_mock ()
96100 with EnvironmentContext (COLCON_EXTENSION_BLOCKLIST = os .pathsep .join ([
97101 'group1.extB' , 'group2.extC' ])
98102 ):
99103 load_extension_point ('extA' , 'eA' , 'group1' )
100- assert resolve .call_count == 1
104+ assert load .call_count == 1
101105
102106 # entry point in a blocked group can't be loaded
103- resolve .reset_mock ()
107+ load .reset_mock ()
104108 with EnvironmentContext (COLCON_EXTENSION_BLOCKLIST = 'group1' ):
105109 with pytest .raises (RuntimeError ) as e :
106110 load_extension_point ('extA' , 'eA' , 'group1' )
107111 assert 'The entry point group name is listed in the environment ' \
108112 'variable' in str (e .value )
109- assert resolve .call_count == 0
113+ assert load .call_count == 0
110114
111115 # entry point listed in the blocklist can't be loaded
112116 with EnvironmentContext (COLCON_EXTENSION_BLOCKLIST = os .pathsep .join ([
@@ -116,10 +120,10 @@ def test_extension_point_blocklist():
116120 load_extension_point ('extA' , 'eA' , 'group1' )
117121 assert 'The entry point name is listed in the environment ' \
118122 'variable' in str (e .value )
119- assert resolve .call_count == 0
123+ assert load .call_count == 0
120124
121125
122- def entry_point_resolve (self , * args , ** kwargs ):
126+ def entry_point_load (self , * args , ** kwargs ):
123127 if self .name == 'exception' :
124128 raise Exception ('entry point raising exception' )
125129 if self .name == 'runtime_error' :
@@ -129,7 +133,7 @@ def entry_point_resolve(self, *args, **kwargs):
129133 return DEFAULT
130134
131135
132- @patch .object (EntryPoint , 'resolve ' , entry_point_resolve )
136+ @patch .object (EntryPoint , 'load ' , entry_point_load )
133137@patch (
134138 'colcon_core.extension_point.get_extension_points' ,
135139 return_value = {'exception' : 'a' , 'runtime_error' : 'b' , 'success' : 'c' }
0 commit comments