Skip to content

Commit daffb67

Browse files
committed
- fix: unittest.skipIf, unittest.skipUnless
- remove PY2 Signed-off-by: Varsha GS <[email protected]>
1 parent ab87ac3 commit daffb67

File tree

14 files changed

+27
-72
lines changed

14 files changed

+27
-72
lines changed

instana/collector/base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
from ..util import every, DictionaryOfStan
1414

1515

16-
if sys.version_info.major == 2:
17-
import Queue as queue
18-
else:
19-
import queue # pylint: disable=import-error
16+
import queue # pylint: disable=import-error
2017

2118

2219
class BaseCollector(object):

instana/propagators/base_propagator.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33

44

55
import sys
6+
import os
67

78
from instana.log import logger
89
from instana.util.ids import header_to_id, header_to_long_id
910
from instana.span_context import SpanContext
1011
from instana.w3c_trace_context.traceparent import Traceparent
1112
from instana.w3c_trace_context.tracestate import Tracestate
12-
import os
13-
14-
PY2 = sys.version_info[0] == 2
15-
PY3 = sys.version_info[0] == 3
1613

1714

1815
# The carrier can be a dict or a list.
@@ -233,7 +230,7 @@ def __extract_instana_headers(self, dc):
233230

234231
level = dc.get(self.LC_HEADER_KEY_L) or dc.get(self.ALT_LC_HEADER_KEY_L) or dc.get(
235232
self.B_HEADER_KEY_L) or dc.get(self.B_ALT_LC_HEADER_KEY_L)
236-
if level and PY3 is True and isinstance(level, bytes):
233+
if level and isinstance(level, bytes):
237234
level = level.decode("utf-8")
238235

239236
synthetic = dc.get(self.LC_HEADER_KEY_SYNTHETIC) or dc.get(self.ALT_LC_HEADER_KEY_SYNTHETIC) or dc.get(
@@ -258,12 +255,12 @@ def __extract_w3c_trace_context_headers(self, dc):
258255
try:
259256
traceparent = dc.get(self.HEADER_KEY_TRACEPARENT) or dc.get(self.ALT_HEADER_KEY_TRACEPARENT) or dc.get(
260257
self.B_HEADER_KEY_TRACEPARENT) or dc.get(self.B_ALT_HEADER_KEY_TRACEPARENT)
261-
if traceparent and PY3 is True and isinstance(traceparent, bytes):
258+
if traceparent and isinstance(traceparent, bytes):
262259
traceparent = traceparent.decode("utf-8")
263260

264261
tracestate = dc.get(self.HEADER_KEY_TRACESTATE) or dc.get(self.ALT_HEADER_KEY_TRACESTATE) or dc.get(
265262
self.B_HEADER_KEY_TRACESTATE) or dc.get(self.B_ALT_HEADER_KEY_TRACESTATE)
266-
if tracestate and PY3 is True and isinstance(tracestate, bytes):
263+
if tracestate and isinstance(tracestate, bytes):
267264
tracestate = tracestate.decode("utf-8")
268265

269266
except Exception:

instana/util/__init__.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# (c) Copyright Instana Inc. 2020
33

44
import json
5-
import sys
65
import time
76

87
from collections import defaultdict
@@ -16,14 +15,6 @@
1615

1716
from ..log import logger
1817

19-
if sys.version_info.major == 2:
20-
string_types = basestring
21-
else:
22-
string_types = str
23-
24-
PY2 = sys.version_info[0] == 2
25-
PY3 = sys.version_info[0] == 3
26-
2718
def nested_dictionary():
2819
return defaultdict(DictionaryOfStan)
2920

instana/util/ids.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# (c) Copyright Instana Inc. 2020
33

44
import os
5-
import sys
65
import time
76
import random
87

@@ -11,13 +10,7 @@
1110

1211
BAD_ID = "BADCAFFE" # Bad Caffe
1312

14-
PY2 = sys.version_info[0] == 2
15-
PY3 = sys.version_info[0] == 3
16-
17-
if PY2:
18-
string_types = basestring
19-
else:
20-
string_types = str
13+
string_types = str
2114

2215

2316
def generate_id():
@@ -45,7 +38,7 @@ def header_to_long_id(header):
4538
:param header: the header to analyze, validate and convert (if needed)
4639
:return: a valid ID to be used internal to the tracer
4740
"""
48-
if PY3 is True and isinstance(header, bytes):
41+
if isinstance(header, bytes):
4942
header = header.decode('utf-8')
5043

5144
if not isinstance(header, string_types):
@@ -74,7 +67,7 @@ def header_to_id(header):
7467
:param header: the header to analyze, validate and convert (if needed)
7568
:return: a valid ID to be used internal to the tracer
7669
"""
77-
if PY3 is True and isinstance(header, bytes):
70+
if isinstance(header, bytes):
7871
header = header.decode('utf-8')
7972

8073
if not isinstance(header, string_types):

tests/clients/test_cassandra-driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
");")
2929

3030

31-
@unittest.mark.skipif(not os.environ.get("CASSANDRA_TEST"), reason="")
31+
@unittest.skipUnless(os.environ.get("CASSANDRA_TEST"), reason="")
3232
class TestCassandra(unittest.TestCase):
3333
def setUp(self):
3434
""" Clear all spans before a test run """

tests/clients/test_couchbase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
pass
2727

2828

29-
@unittest.mark.skipif(not os.environ.get("COUCHBASE_TEST"), reason="")
29+
@unittest.skipIf(not os.environ.get("COUCHBASE_TEST"), reason="")
3030
class TestStandardCouchDB(unittest.TestCase):
3131
def setup_class(self):
3232
""" Clear all spans before a test run """

tests/clients/test_google-cloud-storage.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def setUp(self):
2121
self.recorder = tracer.recorder
2222
self.recorder.clear_spans()
2323

24-
@unittest.mark.skipif(sys.platform == "darwin", reason="Raises not Implemented exception in OSX")
24+
@unittest.skipIf(sys.platform == "darwin", reason="Raises not Implemented exception in OSX")
2525
@patch('requests.Session.request')
2626
def test_buckets_list(self, mock_requests):
2727
mock_requests.return_value = self._mock_response(
@@ -510,7 +510,7 @@ def test_objects_insert(self, mock_requests):
510510
self.assertEqual('test bucket', gcs_span.data["gcs"]["bucket"])
511511
self.assertEqual('test object', gcs_span.data["gcs"]["object"])
512512

513-
@unittest.mark.skipif(sys.platform == "darwin", reason="Raises not Implemented exception in OSX")
513+
@unittest.skipIf(sys.platform == "darwin", reason="Raises not Implemented exception in OSX")
514514
@patch('requests.Session.request')
515515
def test_objects_list(self, mock_requests):
516516
mock_requests.return_value = self._mock_response(
@@ -784,7 +784,7 @@ def test_object_hmac_keys_get(self, mock_requests):
784784
self.assertEqual('test-project', gcs_span.data["gcs"]["projectId"])
785785
self.assertEqual('test key', gcs_span.data["gcs"]["accessId"])
786786

787-
@unittest.mark.skipif(sys.platform == "darwin", reason="Raises not Implemented exception in OSX")
787+
@unittest.skipIf(sys.platform == "darwin", reason="Raises not Implemented exception in OSX")
788788
@patch('requests.Session.request')
789789
def test_object_hmac_keys_list(self, mock_requests):
790790
mock_requests.return_value = self._mock_response(

tests/clients/test_pymongo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
logger = logging.getLogger(__name__)
1515

16-
pymongoversion = unittest.mark.skipif(
16+
pymongoversion = unittest.skipIf(
1717
pymongo.version_tuple >= (4, 0), reason="map reduce is removed in pymongo 4.0"
1818
)
1919

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727

2828
# Python 3.10 support is incomplete yet
2929
# TODO: Remove this once we start supporting Tornado >= 6.0
30-
if sys.version_info.minor >= 10:
30+
if sys.version_info >= (3, 10):
3131
collect_ignore_glob.append("*test_tornado*")
3232
# Furthermore on Python 3.11 the above TC is skipped:
3333
# tests/opentracing/test_ot_span.py::TestOTSpan::test_stacks
3434
# TODO: Remove that once we find a workaround or DROP opentracing!
3535

36-
if sys.version_info.minor >= 12:
36+
if sys.version_info >= (3, 12):
3737
# Currently the dependencies of sanic and aiohttp are not installable on 3.12
3838
# PyLongObject’ {aka ‘struct _longobject’} has no member named ‘ob_digit’
3939
collect_ignore_glob.append("*test_sanic*")

tests/frameworks/test_flask.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# (c) Copyright IBM Corp. 2021
22
# (c) Copyright Instana Inc. 2020
33

4-
import sys
54
import unittest
65
import urllib3
76
import flask
@@ -713,10 +712,7 @@ def test_exception(self):
713712
# error log
714713
self.assertEqual("log", log_span.n)
715714
self.assertEqual('Exception on /exception [GET]', log_span.data["log"]['message'])
716-
if sys.version_info < (3, 0):
717-
self.assertEqual("<type 'exceptions.Exception'> fake error", log_span.data["log"]['parameters'])
718-
else:
719-
self.assertEqual("<class 'Exception'> fake error", log_span.data["log"]['parameters'])
715+
self.assertEqual("<class 'Exception'> fake error", log_span.data["log"]['parameters'])
720716

721717

722718
# wsgis

0 commit comments

Comments
 (0)