Skip to content

Commit db6993c

Browse files
authored
Remove use of 'six' package from most tests (and haproxy and istio) (#18593)
* Remove use of 'six' package from most tests * fix redisdb test
1 parent 333a5ec commit db6993c

File tree

50 files changed

+127
-219
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+127
-219
lines changed

amazon_msk/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# All rights reserved
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44
import json
5+
from urllib.parse import urlparse
56

67
import mock
78
import pytest
8-
from six.moves.urllib.parse import urlparse
99

1010
from datadog_checks.dev import docker_run
1111
from datadog_checks.dev.http import MockResponse

clickhouse/tests/test_unit.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import mock
55
import pytest
66
from clickhouse_driver.errors import Error, NetworkError
7-
from six import PY3
87

98
from datadog_checks.clickhouse import ClickhouseCheck, queries
109

@@ -65,9 +64,7 @@ def test_error_query(instance, dd_run_check):
6564
ids=['SystemMetrics', 'SystemEvents'],
6665
)
6766
def test_latest_metrics_supported(metrics, ignored_columns, metric_source_url):
68-
# While we're here, also check key order
69-
if PY3:
70-
assert list(metrics) == sorted(metrics)
67+
assert list(metrics) == sorted(metrics)
7168

7269
described_metrics = parse_described_metrics(metric_source_url)
7370

consul/tests/consul_mocks.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44
import random
55

6-
from six import iteritems
7-
86
MOCK_CONFIG = {'url': 'http://localhost:8500', 'catalog_checks': True}
97
MOCK_CONFIG_DISABLE_SERVICE_TAG = {
108
'url': 'http://localhost:8500',
@@ -30,7 +28,7 @@
3028

3129

3230
def mock_check(check, mocks):
33-
for f_name, m in iteritems(mocks):
31+
for f_name, m in mocks.items():
3432
if not hasattr(check, f_name):
3533
continue
3634
else:

datadog_checks_base/tests/test_metadata.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import mock
1010
import pytest
11-
from six import PY3
1211

1312
from datadog_checks.base import AgentCheck, ensure_bytes, ensure_unicode
1413

@@ -57,12 +56,8 @@ class NewAgentCheck(AgentCheck):
5756
def test_encoding(self):
5857
check = AgentCheck('test', {}, [{}])
5958
check.check_id = 'test:123'
60-
if PY3:
61-
constructor = ensure_bytes
62-
finalizer = ensure_unicode
63-
else:
64-
constructor = ensure_unicode
65-
finalizer = ensure_bytes
59+
constructor = ensure_bytes
60+
finalizer = ensure_unicode
6661

6762
name = constructor(u'nam\u00E9')
6863
value = constructor(u'valu\u00E9')

datadog_checks_dev/tests/test_conditions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44
import os
55
import sys
6+
from urllib.response import addinfourl
67

78
import pytest
8-
from six.moves.urllib.response import addinfourl
99

1010
from datadog_checks.dev.conditions import CheckCommandOutput, CheckDockerLogs, CheckEndpoints, WaitFor
1111
from datadog_checks.dev.errors import RetryError

disk/tests/test_unit.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import mock
88
import pytest
9-
from six import iteritems
109

1110
from datadog_checks.base.utils.platform import Platform
1211
from datadog_checks.base.utils.timeout import TimeoutException
@@ -65,10 +64,10 @@ def test_default(aggregator, gauge_metrics, rate_metrics, count_metrics, dd_run_
6564
else:
6665
tags = []
6766

68-
for name, value in iteritems(gauge_metrics):
67+
for name, value in gauge_metrics.items():
6968
aggregator.assert_metric(name, value=value, count=1, metric_type=aggregator.GAUGE, tags=tags)
7069

71-
for name, value in iteritems(rate_metrics):
70+
for name, value in rate_metrics.items():
7271
aggregator.assert_metric(
7372
name,
7473
value=value,
@@ -77,7 +76,7 @@ def test_default(aggregator, gauge_metrics, rate_metrics, count_metrics, dd_run_
7776
tags=['device:{}'.format(DEFAULT_DEVICE_NAME), 'device_name:{}'.format(DEFAULT_DEVICE_BASE_NAME)],
7877
)
7978

80-
for name, value in iteritems(count_metrics):
79+
for name, value in count_metrics.items():
8180
aggregator.assert_metric(
8281
name,
8382
value=value,
@@ -110,14 +109,14 @@ def test_use_mount(aggregator, instance_basic_mount, gauge_metrics, rate_metrics
110109
c = Disk('disk', {}, [instance_basic_mount])
111110
dd_run_check(c)
112111

113-
for name, value in iteritems(gauge_metrics):
112+
for name, value in gauge_metrics.items():
114113
aggregator.assert_metric(
115114
name,
116115
value=value,
117116
tags=['device:{}'.format(DEFAULT_MOUNT_POINT), 'device_name:{}'.format(DEFAULT_DEVICE_BASE_NAME)],
118117
)
119118

120-
for name, value in chain(iteritems(rate_metrics), iteritems(count_metrics)):
119+
for name, value in chain(rate_metrics.items(), count_metrics.items()):
121120
aggregator.assert_metric(
122121
name,
123122
value=value,
@@ -155,7 +154,7 @@ def test_device_tagging(aggregator, gauge_metrics, rate_metrics, count_metrics,
155154
'device_label:mylab',
156155
]
157156

158-
for name, value in chain(iteritems(gauge_metrics), iteritems(rate_metrics), iteritems(count_metrics)):
157+
for name, value in chain(gauge_metrics.items(), rate_metrics.items(), count_metrics.items()):
159158
aggregator.assert_metric(
160159
name,
161160
value=value,

dns_check/tests/mocks.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Licensed under Simplified BSD License (see LICENSE)
44

55
from dns.resolver import NXDOMAIN
6-
from six import PY3
76

87

98
class MockDNSAnswer:
@@ -18,7 +17,7 @@ def __init__(self, address):
1817
else:
1918
items = [MockDNSAnswer.MockItem(address)]
2019

21-
self.items = {item: None for item in items} if PY3 else items
20+
self.items = {item: None for item in items}
2221

2322
class MockItem:
2423
def __init__(self, address):

elastic/tests/test_integration.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import pytest
77
import requests
88
from packaging import version
9-
from six import iteritems
109

1110
from datadog_checks.dev.utils import get_metadata_metrics
1211
from datadog_checks.elastic import ESCheck
@@ -276,7 +275,7 @@ def test_node_name_as_host(dd_environment, instance_normalize_hostname, aggregat
276275
elastic_check.check(None)
277276
node_name = node_tags[-1].split(':')[1]
278277

279-
for m_name, _ in iteritems(STATS_METRICS):
278+
for m_name in STATS_METRICS:
280279
aggregator.assert_metric(m_name, count=1, tags=node_tags, hostname=node_name)
281280

282281

@@ -288,7 +287,7 @@ def test_pshard_metrics(dd_environment, aggregator):
288287
elastic_check.check(None)
289288

290289
pshard_stats_metrics = pshard_stats_for_version(es_version)
291-
for m_name, desc in iteritems(pshard_stats_metrics):
290+
for m_name, desc in pshard_stats_metrics.items():
292291
if desc[0] == 'gauge':
293292
aggregator.assert_metric(m_name)
294293

@@ -310,7 +309,7 @@ def test_detailed_index_stats(dd_environment, aggregator):
310309
es_version = elastic_check._get_es_version()
311310
elastic_check.check(None)
312311
pshard_stats_metrics = pshard_stats_for_version(es_version)
313-
for m_name, desc in iteritems(pshard_stats_metrics):
312+
for m_name, desc in pshard_stats_metrics.items():
314313
if desc[0] == 'gauge' and desc[1].startswith('_all.'):
315314
aggregator.assert_metric(m_name)
316315

esxi/tests/ssh_tunnel.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@
44
from __future__ import absolute_import
55

66
import os
7+
import subprocess
78
from contextlib import contextmanager
89

910
import psutil
10-
from six import PY3
1111

1212
from datadog_checks.dev.conditions import WaitForPortListening
1313
from datadog_checks.dev.env import environment_run
1414
from datadog_checks.dev.structures import LazyFunction, TempDir
1515
from datadog_checks.dev.utils import ON_WINDOWS, find_free_port, get_ip
1616

17-
if PY3:
18-
import subprocess
19-
else:
20-
import subprocess32 as subprocess
21-
2217
PID_FILE = 'ssh.pid'
2318

2419

go_expvar/tests/test_integration.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import logging
66

77
import pytest
8-
from six import iteritems
98

109
from . import common
1110

@@ -25,7 +24,7 @@ def test_go_expvar(check, aggregator):
2524
aggregator.assert_metric(gauge, count=1, tags=shared_tags)
2625
for rate in common.CHECK_RATES:
2726
aggregator.assert_metric(rate, count=1, tags=shared_tags)
28-
for rate, value in iteritems(CHECK_RATES_CUSTOM):
27+
for rate, value in CHECK_RATES_CUSTOM.items():
2928
aggregator.assert_metric(rate, count=1, value=value, tags=shared_tags)
3029
for count in common.CHECK_COUNT:
3130
aggregator.assert_metric(count, count=1, metric_type=3, tags=shared_tags)

go_expvar/tests/test_unit.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import logging
77

88
import pytest
9-
from six import iteritems
109

1110
from . import common
1211

@@ -83,7 +82,7 @@ def test_go_expvar_mocked(go_expvar_mock, check, aggregator):
8382
aggregator.assert_metric(
8483
gauge.format(common.CHECK_NAME), metric_type=aggregator.GAUGE, count=1, tags=shared_tags
8584
)
86-
for gauge, tags in iteritems(CHECK_GAUGES_CUSTOM_MOCK):
85+
for gauge, tags in CHECK_GAUGES_CUSTOM_MOCK.items():
8786
aggregator.assert_metric(
8887
gauge.format(common.CHECK_NAME), metric_type=aggregator.GAUGE, count=1, tags=shared_tags + tags
8988
)
@@ -145,7 +144,7 @@ def test_go_expvar_mocked_namespace(go_expvar_mock, check, aggregator):
145144

146145
for gauge in CHECK_GAUGES:
147146
aggregator.assert_metric(gauge.format(metric_namespace), count=1, tags=shared_tags)
148-
for gauge, tags in iteritems(CHECK_GAUGES_CUSTOM_MOCK):
147+
for gauge, tags in CHECK_GAUGES_CUSTOM_MOCK.items():
149148
aggregator.assert_metric(gauge.format(metric_namespace), count=1, tags=shared_tags + tags)
150149

151150
for rate in CHECK_RATES:

haproxy/datadog_checks/haproxy/legacy/haproxy.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
import socket
1010
import time
1111
from collections import defaultdict, namedtuple
12-
13-
from six import PY2, iteritems
14-
from six.moves.urllib.parse import urlparse
12+
from urllib.parse import urlparse
1513

1614
from datadog_checks.base import AgentCheck, is_affirmative, to_string
1715
from datadog_checks.base.errors import CheckException
@@ -115,20 +113,15 @@ def _fetch_url_data(self):
115113

116114
@staticmethod
117115
def _decode_response(response):
118-
# it only needs additional decoding in py3, so skip it if it's py2
119-
if PY2:
120-
return response.content.splitlines()
121-
else:
122-
content = response.content
123-
124-
# If the content is a string, it can't be decoded again
125-
# But if it's bytes, it can be decoded.
126-
# So, check if it has the decode method
127-
decode_fn = getattr(content, "decode", None)
128-
if callable(decode_fn):
129-
content = content.decode('utf-8')
116+
content = response.content
117+
# If the content is a string, it can't be decoded again
118+
# But if it's bytes, it can be decoded.
119+
# So, check if it has the decode method
120+
decode_fn = getattr(content, "decode", None)
121+
if callable(decode_fn):
122+
content = content.decode('utf-8')
130123

131-
return content.splitlines()
124+
return content.splitlines()
132125

133126
@staticmethod
134127
def _parse_uptime(uptime):
@@ -443,7 +436,7 @@ def _tag_from_regex(self, service_name):
443436

444437
# match.groupdict() returns tags dictionary in the form of {'name': 'value'}
445438
# convert it to Datadog tag LIST: ['name:value']
446-
return ["%s:%s" % (name, value) for name, value in iteritems(match.groupdict())]
439+
return ["%s:%s" % (name, value) for name, value in match.groupdict().items()]
447440

448441
@staticmethod
449442
def _normalize_status(status):
@@ -463,7 +456,7 @@ def _process_backend_hosts_metric(self, active_tag=None):
463456
agg_statuses = defaultdict(lambda: {status: 0 for status in Services.COLLATED_STATUSES})
464457
active_tag = [] if active_tag is None else active_tag
465458

466-
for host_status, count in iteritems(self.hosts_statuses):
459+
for host_status, count in self.hosts_statuses.items():
467460
try:
468461
service, back_or_front, hostname, status = host_status
469462
except ValueError:
@@ -512,7 +505,7 @@ def _process_status_metric(
512505
reported_statuses_dict[reported_status] = 0
513506
statuses_counter = defaultdict(lambda: copy.copy(reported_statuses_dict))
514507

515-
for host_status, count in iteritems(self.hosts_statuses):
508+
for host_status, count in self.hosts_statuses.items():
516509
hostname = None
517510
try:
518511
service, _, hostname, status = host_status
@@ -555,13 +548,13 @@ def _process_status_metric(
555548
status_key = Services.STATUS_TO_COLLATED.get(status, Services.UNAVAILABLE)
556549
agg_statuses_counter[tuple(agg_tags)][status_key] += count
557550

558-
for tags, count_per_status in iteritems(statuses_counter):
559-
for status, count in iteritems(count_per_status):
551+
for tags, count_per_status in statuses_counter.items():
552+
for status, count in count_per_status.items():
560553
self.gauge('haproxy.count_per_status', count, tags=tags + ('status:%s' % status,))
561554

562555
# Send aggregates
563-
for service_tags, service_agg_statuses in iteritems(agg_statuses_counter):
564-
for status, count in iteritems(service_agg_statuses):
556+
for service_tags, service_agg_statuses in agg_statuses_counter.items():
557+
for status, count in service_agg_statuses.items():
565558
self.gauge("haproxy.count_per_status", count, tags=service_tags + ('status:%s' % status,))
566559

567560
def _process_metrics(self, data, custom_tags=None, active_tag=None):

hdfs_datanode/tests/test_hdfs_datanode.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44
import mock
55
import pytest
6-
from six import iteritems
76

87
from datadog_checks.hdfs_datanode import HDFSDataNode
98

@@ -38,7 +37,7 @@ def test_check(aggregator, mocked_request):
3837
HDFSDataNode.JMX_SERVICE_CHECK, status=HDFSDataNode.OK, tags=HDFS_DATANODE_METRIC_TAGS + CUSTOM_TAGS, count=1
3938
)
4039

41-
for metric, value in iteritems(HDFS_DATANODE_METRICS_VALUES):
40+
for metric, value in HDFS_DATANODE_METRICS_VALUES.items():
4241
aggregator.assert_metric(metric, value=value, tags=HDFS_DATANODE_METRIC_TAGS + CUSTOM_TAGS, count=1)
4342

4443

hdfs_namenode/tests/test_hdfs_namenode.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44
import mock
55
import pytest
6-
from six import iteritems
76

87
from datadog_checks.hdfs_namenode import HDFSNameNode
98

@@ -34,13 +33,13 @@ def test_check(aggregator, dd_run_check, mocked_request):
3433
HDFSNameNode.JMX_SERVICE_CHECK, HDFSNameNode.OK, tags=HDFS_NAMESYSTEM_METRIC_TAGS + CUSTOM_TAGS, count=1
3534
)
3635

37-
for metric, value in iteritems(HDFS_NAMESYSTEM_STATE_METRICS_VALUES):
36+
for metric, value in HDFS_NAMESYSTEM_STATE_METRICS_VALUES.items():
3837
aggregator.assert_metric(metric, value=value, tags=HDFS_NAMESYSTEM_METRIC_TAGS + CUSTOM_TAGS, count=1)
3938

40-
for metric, value in iteritems(HDFS_NAMESYSTEM_METRICS_VALUES):
39+
for metric, value in HDFS_NAMESYSTEM_METRICS_VALUES.items():
4140
aggregator.assert_metric(metric, value=value, tags=HDFS_NAMESYSTEM_METRIC_TAGS + CUSTOM_TAGS, count=1)
4241

43-
for metric, value in iteritems(HDFS_NAMESYSTEM_MUTUAL_METRICS_VALUES):
42+
for metric, value in HDFS_NAMESYSTEM_MUTUAL_METRICS_VALUES.items():
4443
aggregator.assert_metric(metric, value=value, tags=HDFS_NAMESYSTEM_METRIC_TAGS + CUSTOM_TAGS, count=2)
4544

4645
aggregator.assert_all_metrics_covered()

ibm_mq/tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import re
88

99
import pytest
10-
from six.moves import range
1110

1211
from datadog_checks.dev import docker_run
1312
from datadog_checks.dev.conditions import CheckDockerLogs, WaitFor

0 commit comments

Comments
 (0)