@@ -121,7 +121,7 @@ def read_text(self, filename):
121121 def requires (self ):
122122 return [
123123 'foo ~= 1.0; extra == "instruments_either"' ,
124- 'bar ~= 1.0; extra == "instruments_either"'
124+ 'bar ~= 1.0; extra == "instruments_either"' ,
125125 ]
126126
127127 dist = MockDistribution ()
@@ -136,7 +136,6 @@ def version_side_effect(package_name):
136136
137137 version_mock .side_effect = version_side_effect
138138 conflict = get_dist_dependency_conflicts (dist )
139- print ("CONFLICT" , conflict )
140139 self .assertIsNone (conflict )
141140
142141 @patch ("opentelemetry.instrumentation.dependencies.version" )
@@ -152,7 +151,7 @@ def read_text(self, filename):
152151 def requires (self ):
153152 return [
154153 'foo ~= 1.0; extra == "instruments_either"' ,
155- 'bar ~= 1.0; extra == "instruments_either"'
154+ 'bar ~= 1.0; extra == "instruments_either"' ,
156155 ]
157156
158157 dist = MockDistribution ()
@@ -164,6 +163,120 @@ def requires(self):
164163 self .assertTrue (isinstance (conflict , DependencyConflict ))
165164 self .assertEqual (
166165 str (conflict ),
167- # TODO: fix tests of either conflict
168166 '''DependencyConflict: requested any of the following: "['foo~=1.0; extra == "instruments-either"', 'bar~=1.0; extra == "instruments-either"']" but found: "[]"''' ,
169167 )
168+
169+ # Tests when both "and" and "either" dependencies are specified and both pass.
170+ @patch ("opentelemetry.instrumentation.dependencies.version" )
171+ def test_get_dist_dependency_conflicts_either_and (self , version_mock ):
172+ class MockDistribution (Distribution ):
173+ def locate_file (self , path ):
174+ pass
175+
176+ def read_text (self , filename ):
177+ pass
178+
179+ @property
180+ def requires (self ):
181+ # This indicates the instrumentation requires (foo and (bar or baz)))
182+ return [
183+ 'foo ~= 1.0; extra == "instruments"' ,
184+ 'bar ~= 2.0; extra == "instruments_either"' ,
185+ 'baz ~= 3.0; extra == "instruments_either"' ,
186+ ]
187+
188+ dist = MockDistribution ()
189+
190+ def version_side_effect (package_name ):
191+ if package_name == "foo" :
192+ return "1.2.0"
193+ elif package_name == "bar" :
194+ raise PackageNotFoundError ("bar not found" )
195+ elif package_name == "baz" :
196+ return "3.7.0"
197+ else :
198+ raise PackageNotFoundError (f"{ package_name } not found" )
199+
200+ version_mock .side_effect = version_side_effect
201+ conflict = get_dist_dependency_conflicts (dist )
202+ self .assertIsNone (conflict )
203+
204+ # Tests when both "and" and "either" dependencies are specified but the "and" dependencies fail to resolve.
205+ @patch ("opentelemetry.instrumentation.dependencies.version" )
206+ def test_get_dist_dependency_conflicts_either_and_failed (self , version_mock ):
207+ class MockDistribution (Distribution ):
208+ def locate_file (self , path ):
209+ pass
210+
211+ def read_text (self , filename ):
212+ pass
213+
214+ @property
215+ def requires (self ):
216+ # This indicates the instrumentation requires (foo and (bar or baz)))
217+ return [
218+ 'foo ~= 1.0; extra == "instruments"' ,
219+ 'bar ~= 2.0; extra == "instruments_either"' ,
220+ 'baz ~= 3.0; extra == "instruments_either"' ,
221+ ]
222+
223+ dist = MockDistribution ()
224+
225+ def version_side_effect (package_name ):
226+ if package_name == "foo" :
227+ raise PackageNotFoundError ("foo not found" )
228+ elif package_name == "bar" :
229+ raise PackageNotFoundError ("bar not found" )
230+ elif package_name == "baz" :
231+ return "3.7.0"
232+ else :
233+ raise PackageNotFoundError (f"{ package_name } not found" )
234+
235+ version_mock .side_effect = version_side_effect
236+ conflict = get_dist_dependency_conflicts (dist )
237+ self .assertTrue (conflict is not None )
238+ self .assertTrue (isinstance (conflict , DependencyConflict ))
239+ self .assertEqual (
240+ str (conflict ),
241+ 'DependencyConflict: requested: "foo~=1.0; extra == "instruments"" but found: "None"' ,
242+ )
243+
244+ # Tests when both "and" and "either" dependencies are specified but the "either" dependencies fail to resolve.
245+ @patch ("opentelemetry.instrumentation.dependencies.version" )
246+ def test_get_dist_dependency_conflicts_and_either_failed (self , version_mock ):
247+ class MockDistribution (Distribution ):
248+ def locate_file (self , path ):
249+ pass
250+
251+ def read_text (self , filename ):
252+ pass
253+
254+ @property
255+ def requires (self ):
256+ # This indicates the instrumentation requires (foo and (bar or baz)))
257+ return [
258+ 'foo ~= 1.0; extra == "instruments"' ,
259+ 'bar ~= 2.0; extra == "instruments_either"' ,
260+ 'baz ~= 3.0; extra == "instruments_either"' ,
261+ ]
262+
263+ dist = MockDistribution ()
264+
265+ def version_side_effect (package_name ):
266+ if package_name == "foo" :
267+ return "1.7.0"
268+ elif package_name == "bar" :
269+ raise PackageNotFoundError ("bar not found" )
270+ elif package_name == "baz" :
271+ raise PackageNotFoundError ("baz not found" )
272+ else :
273+ raise PackageNotFoundError (f"{ package_name } not found" )
274+
275+ version_mock .side_effect = version_side_effect
276+ conflict = get_dist_dependency_conflicts (dist )
277+ self .assertTrue (conflict is not None )
278+ self .assertTrue (isinstance (conflict , DependencyConflict ))
279+ self .assertEqual (
280+ str (conflict ),
281+ '''DependencyConflict: requested any of the following: "['bar~=2.0; extra == "instruments-either"', 'baz~=3.0; extra == "instruments-either"']" but found: "[]"''' ,
282+ )
0 commit comments