13
13
# limitations under the License.
14
14
15
15
from unittest import TestCase
16
+ from warnings import catch_warnings , filterwarnings
16
17
17
18
from opentelemetry .metrics import MeterProvider
18
- from opentelemetry .util ._importlib_metadata import entry_points
19
+ from opentelemetry .util ._importlib_metadata import EntryPoint
20
+ from opentelemetry .util ._importlib_metadata import (
21
+ entry_points as entry_points_function , # SelectableGroups,; EntryPoints
22
+ )
19
23
20
24
21
25
class TestEntryPoints (TestCase ):
@@ -24,11 +28,67 @@ def test_entry_points(self):
24
28
self .assertIsInstance (
25
29
next (
26
30
iter (
27
- entry_points (
31
+ entry_points_function (
28
32
group = "opentelemetry_meter_provider" ,
29
33
name = "default_meter_provider" ,
30
34
)
31
35
)
32
36
).load ()(),
33
37
MeterProvider ,
34
38
)
39
+
40
+ def test_uniform_behavior (self ):
41
+ """
42
+ Test that entry_points behaves the same regardless of the Python
43
+ version.
44
+ """
45
+
46
+ selectable_groups = entry_points_function ()
47
+
48
+ # self.assertIsInstance(selectable_groups, SelectableGroups)
49
+
50
+ # Supressing the following warning here:
51
+ # DeprecationWarning: SelectableGroups dict interface is deprecated. Use select.
52
+ # The behavior of the importlib metadata library is hard to understand,
53
+ # this is True: selectable_groups is selectable_groups.select(). So,
54
+ # using select, as the warning says yields the same problem. Also
55
+ # select does not accept any parameters.
56
+
57
+ with catch_warnings ():
58
+ filterwarnings ("ignore" , category = DeprecationWarning )
59
+ entry_points = selectable_groups .select ()[
60
+ "opentelemetry_propagator"
61
+ ]
62
+
63
+ # Supressing the following warning here:
64
+ # DeprecationWarning: DeprecationWarning: Accessing entry points by index is deprecated. Cast to tuple if needed.
65
+ # The behavior of the importlib metadata library is hard to understand,
66
+ # this is True: entry_points == .select(). So, using select, as the
67
+ # warning says yields the same problem. Also select does not accept any
68
+ # parameters.
69
+ with catch_warnings ():
70
+ filterwarnings ("ignore" , category = DeprecationWarning )
71
+
72
+ self .assertIsInstance (entry_points .select ()[0 ], EntryPoint )
73
+
74
+ entry_points = entry_points_function (
75
+ group = "opentelemetry_propagator"
76
+ )
77
+
78
+ self .assertIsInstance (entry_points .select ()[0 ], EntryPoint )
79
+
80
+ entry_points = entry_points_function (
81
+ group = "opentelemetry_propagator" , name = "baggage"
82
+ )
83
+
84
+ self .assertIsInstance (entry_points .select ()[0 ], EntryPoint )
85
+
86
+ entry_points = entry_points_function (group = "abc" )
87
+
88
+ self .assertEqual (entry_points , [])
89
+
90
+ entry_points = entry_points_function (
91
+ group = "opentelemetry_propagator" , name = "abc"
92
+ )
93
+
94
+ self .assertEqual (entry_points , [])
0 commit comments