Skip to content

Commit d843e2f

Browse files
committed
[ci run all] use raw string literals when \ is present
1 parent 8af1567 commit d843e2f

22 files changed

Lines changed: 68 additions & 49 deletions

File tree

cassandra_nodetool/datadog_checks/cassandra_nodetool/cassandra_nodetool.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
class CassandraNodetoolCheck(AgentCheck):
3232

3333
datacenter_name_re = re.compile('^Datacenter: (.*)')
34-
node_status_re = re.compile('^(?P<status>[UD])[NLJM] +(?P<address>\d+\.\d+\.\d+\.\d+) +'
35-
'(?P<load>\d+(\.\d*)?) (?P<load_unit>(K|M|G|T)?i?B) +\d+ +'
36-
'(?P<owns>(\d+(\.\d+)?)|\?)%? +(?P<id>[a-fA-F0-9-]*) +(?P<rack>.*)')
34+
node_status_re = re.compile(r'^(?P<status>[UD])[NLJM] +(?P<address>\d+\.\d+\.\d+\.\d+) +'
35+
r'(?P<load>\d+(\.\d*)?) (?P<load_unit>(K|M|G|T)?i?B) +\d+ +'
36+
r'(?P<owns>(\d+(\.\d+)?)|\?)%? +(?P<id>[a-fA-F0-9-]*) +(?P<rack>.*)')
3737

3838
def __init__(self, name, init_config, agentConfig, instances=None):
3939
AgentCheck.__init__(self, name, init_config, agentConfig, instances)

ceph/datadog_checks/ceph/ceph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ def _osd_pct_used(self, health):
255255
"""Take a single health check string, return (OSD name, percentage used)"""
256256
# Full string looks like: osd.2 is full at 95%
257257
# Near full string: osd.1 is near full at 94%
258-
pct = re.compile('\d+%').findall(health)
259-
osd = re.compile('osd.\d+').findall(health)
258+
pct = re.compile(r'\d+%').findall(health)
259+
osd = re.compile(r'osd.\d+').findall(health)
260260
if len(pct) > 0 and len(osd) > 0:
261261
return osd[0], int(pct[0][:-1])
262262
else:

cisco_aci/datadog_checks/cisco_aci/tags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def _tenant_mapper(self, edpt):
126126
eth_list = self.api.get_eth_list_for_epg(tenant_name, app_name, epg_name)
127127
for eth in eth_list:
128128
eth_attrs = eth.get('fvRsCEpToPathEp', {}).get('attributes', {})
129-
port = re.search('/pathep-\[(.+?)\]', eth_attrs.get('tDn', ''))
129+
port = re.search(r'/pathep-\[(.+?)\]', eth_attrs.get('tDn', ''))
130130
if not port:
131131
continue
132132
eth_tag = 'port:' + port.group(1)

cisco_aci/datadog_checks/cisco_aci/tenant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def collect_events(self, tenant, page=0, page_size=15):
145145
for event in event_list:
146146
ev = event.get('eventRecord', {}).get('attributes', {})
147147
created = ev.get('created')
148-
create_date = re.search('\d{4}-\d{2}-\d{1,2}T\d{2}:\d{2}:\d{2}', created).group(0)
148+
create_date = re.search(r'\d{4}-\d{2}-\d{1,2}T\d{2}:\d{2}:\d{2}', created).group(0)
149149

150150
self.log.debug("ev time: {}".format(created))
151151
strptime = datetime.datetime.strptime(create_date, '%Y-%m-%dT%H:%M:%S')

couchbase/datadog_checks/couchbase/couchbase.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class Couchbase(AgentCheck):
255255
's': 1,
256256
}
257257

258-
seconds_value_pattern = re.compile('(\d+(\.\d+)?)(\D+)')
258+
seconds_value_pattern = re.compile(r'(\d+(\.\d+)?)(\D+)')
259259

260260
class CouchbaseInstanceState(object):
261261
def __init__(self):
@@ -533,10 +533,10 @@ def get_data(self, server, instance):
533533
# Returns input if non-camelCase variable is detected.
534534
def camel_case_to_joined_lower(self, variable):
535535
# replace non-word with _
536-
converted_variable = re.sub('\W+', '_', variable)
536+
converted_variable = re.sub(r'\W+', '_', variable)
537537

538538
# insert _ in front of capital letters and lowercase the string
539-
converted_variable = re.sub('([A-Z])', '_\g<1>', converted_variable).lower()
539+
converted_variable = re.sub('([A-Z])', r'_\g<1>', converted_variable).lower()
540540

541541
# remove duplicate _
542542
converted_variable = re.sub('_+', '_', converted_variable)

datadog_checks_dev/datadog_checks/dev/tooling/e2e/docker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from ...subprocess import run_command
1212
from ...utils import path_join
1313

14-
MANIFEST_VERSION_PATTERN = 'agent (\d)'
14+
MANIFEST_VERSION_PATTERN = r'agent (\d)'
1515

1616

1717
class DockerInterface(object):

disk/datadog_checks/disk/disk.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,14 @@ def collect_metrics_psutil(self):
136136
self.service_check(
137137
'disk.read_write',
138138
AgentCheck.OK if rwro[0] == 'rw' else AgentCheck.CRITICAL,
139-
tags=tags+['device:%s' % (device_name)]
139+
tags=tags + ['device:{}'.format(device_name)]
140140
)
141141
else:
142142
self.service_check(
143143
'disk.read_write', AgentCheck.UNKNOWN,
144-
tags=tags+['device:%s' % (device_name)]
144+
tags=tags + ['device:{}'.format(device_name)]
145145
)
146146

147-
148147
self.collect_latency_metrics()
149148

150149
def _exclude_disk_psutil(self, part):
@@ -235,9 +234,9 @@ def collect_latency_metrics(self):
235234
read_time_pct = disk.read_time * 100.0 / 1000.0
236235
write_time_pct = disk.write_time * 100.0 / 1000.0
237236
self.rate(self.METRIC_DISK.format('read_time_pct'),
238-
read_time_pct, device_name=disk_name, tags=self._custom_tags)
237+
read_time_pct, device_name=disk_name, tags=self._custom_tags)
239238
self.rate(self.METRIC_DISK.format('write_time_pct'),
240-
write_time_pct, device_name=disk_name, tags=self._custom_tags)
239+
write_time_pct, device_name=disk_name, tags=self._custom_tags)
241240
except AttributeError as e:
242241
# Some OS don't return read_time/write_time fields
243242
# http://psutil.readthedocs.io/en/latest/#psutil.disk_io_counters

disk/tests/test_check.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def aggregator():
8787
aggregator.reset()
8888
return aggregator
8989

90+
9091
@pytest.fixture(scope="module")
9192
def psutil_mocks():
9293
p1 = mock.patch('psutil.disk_partitions', return_value=[MockPart()],
@@ -104,6 +105,7 @@ def psutil_mocks():
104105
p3.stop()
105106
p4.stop()
106107

108+
107109
def test_bad_config():
108110
"""
109111
Check creation will fail if more than one `instance` is passed to the
@@ -112,6 +114,7 @@ def test_bad_config():
112114
with pytest.raises(Exception):
113115
Disk('disk', None, {}, [{}, {}])
114116

117+
115118
def test_default_options():
116119
check = Disk('disk', None, {}, [{}])
117120

@@ -124,6 +127,7 @@ def test_default_options():
124127
assert check._device_tag_re == []
125128
assert check._service_check_rw is False
126129

130+
127131
def test_disk_check(aggregator):
128132
"""
129133
Basic check to see if all metrics are there
@@ -135,6 +139,7 @@ def test_disk_check(aggregator):
135139

136140
assert aggregator.metrics_asserted_pct == 100.0
137141

142+
138143
def test__exclude_disk_psutil():
139144
"""
140145
Test exclusion logic
@@ -177,6 +182,7 @@ def test__exclude_disk_psutil():
177182
assert c._exclude_disk_psutil(MockPart(device='sdz', mountpoint='/run')) is True
178183
assert c._exclude_disk_psutil(MockPart(device='sdz', mountpoint='/run/shm')) is False
179184

185+
180186
def test_device_exclusion_logic_no_name():
181187
"""
182188
Same as above but with default configuration values and device='' to expose a bug in #2359
@@ -191,6 +197,7 @@ def test_device_exclusion_logic_no_name():
191197
assert c._exclude_disk_psutil(MockPart(device='', mountpoint='/run')) is True
192198
assert c._exclude_disk_psutil(MockPart(device='', mountpoint='/run/shm')) is False
193199

200+
194201
def test_psutil(aggregator, psutil_mocks):
195202
"""
196203
Mock psutil and run the check
@@ -210,6 +217,7 @@ def test_psutil(aggregator, psutil_mocks):
210217

211218
assert aggregator.metrics_asserted_pct == 100.0
212219

220+
213221
def test_use_mount(aggregator, psutil_mocks):
214222
"""
215223
Same as above, using mount to tag
@@ -226,6 +234,7 @@ def test_use_mount(aggregator, psutil_mocks):
226234

227235
assert aggregator.metrics_asserted_pct == 100.0
228236

237+
229238
def test_psutil_rw(aggregator, psutil_mocks):
230239
"""
231240
Check for 'ro' option in the mounts
@@ -236,6 +245,7 @@ def test_psutil_rw(aggregator, psutil_mocks):
236245

237246
aggregator.assert_service_check('disk.read_write', status=Disk.CRITICAL)
238247

248+
239249
def mock_df_output(fname):
240250
"""
241251
Load fixtures from tests/fixtures/ folder and return a tuple matching the
@@ -244,6 +254,7 @@ def mock_df_output(fname):
244254
with open(os.path.join(HERE, 'fixtures', fname)) as f:
245255
return f.read(), '', ''
246256

257+
247258
def test_no_psutil_debian(aggregator):
248259
p1 = mock.patch('os.statvfs', return_value=MockInodesMetrics(), __name__="statvfs")
249260
p2 = mock.patch('datadog_checks.disk.disk.get_subprocess_output',
@@ -262,6 +273,7 @@ def test_no_psutil_debian(aggregator):
262273
aggregator.assert_metric(name, tags=['device:udev'])
263274
assert aggregator.metrics_asserted_pct == 100.0
264275

276+
265277
def test_no_psutil_freebsd(aggregator):
266278
p1 = mock.patch('os.statvfs', return_value=MockInodesMetrics(), __name__="statvfs")
267279
p2 = mock.patch('datadog_checks.disk.disk.get_subprocess_output',
@@ -278,6 +290,7 @@ def test_no_psutil_freebsd(aggregator):
278290
aggregator.assert_metric(name, value=value, tags=['device:zroot'])
279291
assert aggregator.metrics_asserted_pct == 100.0
280292

293+
281294
def test_no_psutil_centos(aggregator):
282295
p1 = mock.patch('os.statvfs', return_value=MockInodesMetrics(), __name__="statvfs")
283296
p2 = mock.patch('datadog_checks.disk.disk.get_subprocess_output',
@@ -295,6 +308,7 @@ def test_no_psutil_centos(aggregator):
295308
aggregator.assert_metric(name, tags=['device:{}'.format(device)])
296309
assert aggregator.metrics_asserted_pct == 100.0
297310

311+
298312
def test_legacy_option():
299313
"""
300314
Ensure check option overrides datadog.conf
@@ -305,6 +319,7 @@ def test_legacy_option():
305319
c = Disk('disk', None, {'use_mount': 'yes'}, [{'use_mount': 'no'}])
306320
assert c._use_mount is False
307321

322+
308323
def test_ignore_empty_regex():
309324
"""
310325
Ignore empty regex as they match all strings
@@ -313,8 +328,9 @@ def test_ignore_empty_regex():
313328
check = Disk('disk', None, {'device_blacklist_re': ''}, [{}])
314329
assert check._excluded_disk_re == re.compile('^$')
315330

331+
316332
def test_device_tagging(aggregator, psutil_mocks):
317-
instances = [{'use_mount': 'no', 'device_tag_re': {"/dev/sda.*": "type:dev,tag:two"}, 'tags':["optional:tags1"]}]
333+
instances = [{'use_mount': 'no', 'device_tag_re': {"/dev/sda.*": "type:dev,tag:two"}, 'tags': ["optional:tags1"]}]
318334
c = Disk('disk', None, {}, instances)
319335
c.check(instances[0])
320336

disk/tox.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ commands =
2121
skip_install = true
2222
deps = flake8
2323
commands = flake8 .
24+
25+
[flake8]
26+
ignore = F401,F403,W504
27+
exclude = .eggs,.tox,build
28+
max-line-length = 120

go_expvar/tests/test_unit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def test_alias_tag_path(go_expvar_mock, check, aggregator):
238238
"expvar_url": common.URL_WITH_PATH,
239239
"metrics": [
240240
{
241-
"path": "array/\d+/key",
241+
"path": r"array/\d+/key",
242242
"alias": "array.dict.key",
243243
"type": "gauge",
244244
}

0 commit comments

Comments
 (0)