1313# limitations under the License.
1414from importlib .metadata import PackageNotFoundError
1515from unittest import TestCase
16- from unittest .mock import patch , call
16+ from unittest .mock import call , patch
1717
1818from kafka import KafkaConsumer , KafkaProducer
1919from wrapt import BoundFunctionWrapper
2525 _instruments_kafka_python_ng ,
2626)
2727
28+
2829class TestKafka (TestCase ):
2930 def test_instrument_api (self ) -> None :
3031 instrumentation = KafkaInstrumentor ()
@@ -53,12 +54,12 @@ def _distribution(name):
5354 mock_distribution .side_effect = _distribution
5455 package_to_instrument = instrumentation .instrumentation_dependencies ()
5556
56- assert mock_distribution .call_count == 2
57- assert mock_distribution .mock_calls == [
57+ self . assertEqual ( mock_distribution .call_count , 2 )
58+ self . assertEqual ( mock_distribution .mock_calls , [
5859 call ("kafka-python-ng" ),
5960 call ("kafka-python" ),
60- ]
61- assert package_to_instrument == (_instruments_kafka_python ,)
61+ ])
62+ self . assertEqual ( package_to_instrument , (_instruments_kafka_python ,) )
6263
6364 @patch ("opentelemetry.instrumentation.kafka.distribution" )
6465 def test_instrumentation_dependencies_kafka_python_ng_installed (self , mock_distribution ) -> None :
@@ -72,11 +73,11 @@ def _distribution(name):
7273 mock_distribution .side_effect = _distribution
7374 package_to_instrument = instrumentation .instrumentation_dependencies ()
7475
75- assert mock_distribution .call_count == 1
76- assert mock_distribution .mock_calls == [
76+ self . assertEqual ( mock_distribution .call_count , 1 )
77+ self . assertEqual ( mock_distribution .mock_calls , [
7778 call ("kafka-python-ng" )
78- ]
79- assert package_to_instrument == (_instruments_kafka_python_ng ,)
79+ ])
80+ self . assertEqual ( package_to_instrument , (_instruments_kafka_python_ng ,) )
8081
8182 @patch ("opentelemetry.instrumentation.kafka.distribution" )
8283 def test_instrumentation_dependencies_both_installed (self , mock_distribution ) -> None :
@@ -91,11 +92,11 @@ def _distribution(name):
9192 mock_distribution .side_effect = _distribution
9293 package_to_instrument = instrumentation .instrumentation_dependencies ()
9394
94- assert mock_distribution .call_count == 1
95- assert mock_distribution .mock_calls == [
95+ self . assertEqual ( mock_distribution .call_count , 1 )
96+ self . assertEqual ( mock_distribution .mock_calls , [
9697 call ("kafka-python-ng" )
97- ]
98- assert package_to_instrument == (_instruments_kafka_python_ng ,)
98+ ])
99+ self . assertEqual ( package_to_instrument , (_instruments_kafka_python_ng ,) )
99100
100101 @patch ("opentelemetry.instrumentation.kafka.distribution" )
101102 def test_instrumentation_dependencies_none_installed (self , mock_distribution ) -> None :
@@ -117,3 +118,10 @@ def _distribution(name):
117118 call ("kafka-python" ),
118119 ]
119120 assert package_to_instrument == _instruments
121+
122+ self .assertEqual (mock_distribution .call_count , 2 )
123+ self .assertEqual (mock_distribution .mock_calls , [
124+ call ("kafka-python-ng" ),
125+ call ("kafka-python" ),
126+ ])
127+ self .assertEqual (package_to_instrument , _instruments )
0 commit comments