Skip to content

Commit b9449d6

Browse files
authored
Remove deprecation warnings (#624)
This removes a few deprecation warnings from tests, including using str instead of bytes, coroutine, and invalid regular expressions. Closes #598
1 parent d8d8a27 commit b9449d6

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

tests/unit/dogstatsd/test_statsd.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def test_service_check(self):
305305
'my_check.name', self.statsd.WARNING,
306306
tags=['key1:val1', 'key2:val2'], timestamp=now,
307307
hostname='i-abcd1234', message=u"♬ †øU \n†øU ¥ºu|m: T0µ ♪")
308-
check = u'_sc|my_check.name|{0}|d:{1}|h:i-abcd1234|#key1:val1,key2:val2|m:{2}'.format(self.statsd.WARNING, now, u"♬ †øU \\n†øU ¥ºu|m\: T0µ ♪")
308+
check = u'_sc|my_check.name|{0}|d:{1}|h:i-abcd1234|#key1:val1,key2:val2|m:{2}'.format(self.statsd.WARNING, now, u"♬ †øU \\n†øU ¥ºu|m\\: T0µ ♪")
309309
assert_equal_telemetry(check, self.recv(2), telemetry=telemetry_metrics(metrics=0, service_checks=1, bytes_sent=len(check)))
310310

311311
def test_service_check_constant_tags(self):
@@ -315,7 +315,7 @@ def test_service_check_constant_tags(self):
315315
'my_check.name', self.statsd.WARNING,
316316
timestamp=now,
317317
hostname='i-abcd1234', message=u"♬ †øU \n†øU ¥ºu|m: T0µ ♪")
318-
check = u'_sc|my_check.name|{0}|d:{1}|h:i-abcd1234|#bar:baz,foo|m:{2}'.format(self.statsd.WARNING, now, u"♬ †øU \\n†øU ¥ºu|m\: T0µ ♪")
318+
check = u'_sc|my_check.name|{0}|d:{1}|h:i-abcd1234|#bar:baz,foo|m:{2}'.format(self.statsd.WARNING, now, u"♬ †øU \\n†øU ¥ºu|m\\: T0µ ♪")
319319
assert_equal_telemetry(check, self.recv(2),
320320
telemetry=telemetry_metrics(metrics=0, service_checks=1, tags="bar:baz,foo", bytes_sent=len(check)))
321321

@@ -325,7 +325,7 @@ def test_service_check_constant_tags(self):
325325
'my_check.name', self.statsd.WARNING,
326326
tags=['key1:val1', 'key2:val2'], timestamp=now,
327327
hostname='i-abcd1234', message=u"♬ †øU \n†øU ¥ºu|m: T0µ ♪")
328-
check = u'_sc|my_check.name|{0}|d:{1}|h:i-abcd1234|#key1:val1,key2:val2,bar:baz,foo|m:{2}'.format(self.statsd.WARNING, now, u"♬ †øU \\n†øU ¥ºu|m\: T0µ ♪")
328+
check = u'_sc|my_check.name|{0}|d:{1}|h:i-abcd1234|#key1:val1,key2:val2,bar:baz,foo|m:{2}'.format(self.statsd.WARNING, now, u"♬ †øU \\n†øU ¥ºu|m\\: T0µ ♪")
329329
assert_equal_telemetry(check, self.recv(2),
330330
telemetry=telemetry_metrics(metrics=0, service_checks=1, tags="bar:baz,foo", bytes_sent=len(check)))
331331

@@ -550,15 +550,18 @@ def test_timed_coroutine(self):
550550
"""
551551
import asyncio
552552

553-
@self.statsd.timed('timed.test')
554-
@asyncio.coroutine
555-
def print_foo():
556-
"""docstring"""
557-
time.sleep(0.5)
558-
print("foo")
553+
source= """
554+
@self.statsd.timed('timed.test')
555+
async def print_foo():
556+
"docstring"
557+
import time
558+
time.sleep(0.5)
559+
print("foo")
560+
"""
561+
exec(source, {}, locals())
559562

560563
loop = asyncio.get_event_loop()
561-
loop.run_until_complete(print_foo())
564+
loop.run_until_complete(locals()['print_foo']())
562565
loop.close()
563566

564567
# Assert

tests/unit/dogwrap/test_dogwrap.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def test_execute(self, mock_popen, mock_poll):
141141
@mock.patch('subprocess.Popen')
142142
def test_execute_exit_code(self, mock_popen, mock_poll):
143143
mock_proc = mock.Mock()
144-
mock_proc.stdout.readline.side_effect = [b'out1\n', b'out2\n', '']
144+
mock_proc.stdout.readline.side_effect = [b'out1\n', b'out2\n', b'']
145145
mock_proc.stderr.readline.side_effect = [b'err1\n', b'']
146146
mock_popen.return_value = mock_proc
147147
mock_poll.return_value = 14
@@ -160,7 +160,7 @@ def test_execute_exit_code(self, mock_popen, mock_poll):
160160
@mock.patch('subprocess.Popen')
161161
def test_execute_cmd_timeout(self, mock_popen, mock_poll):
162162
mock_proc = mock.Mock()
163-
mock_proc.stdout.readline.side_effect = [b'out1\n', b'out2\n', '']
163+
mock_proc.stdout.readline.side_effect = [b'out1\n', b'out2\n', b'']
164164
mock_proc.stderr.readline.side_effect = [b'err1\n', b'']
165165
mock_popen.return_value = mock_proc
166166
mock_poll.side_effect = [Timeout, 1]
@@ -182,7 +182,7 @@ def test_execute_cmd_timeout(self, mock_popen, mock_poll):
182182
@mock.patch('subprocess.Popen')
183183
def test_execute_sigterm_timeout(self, mock_popen, mock_poll):
184184
mock_proc = mock.Mock()
185-
mock_proc.stdout.readline.side_effect = [b'out1\n', b'out2\n', '']
185+
mock_proc.stdout.readline.side_effect = [b'out1\n', b'out2\n', b'']
186186
mock_proc.stderr.readline.side_effect = [b'err1\n', b'']
187187
mock_popen.return_value = mock_proc
188188
mock_poll.side_effect = [Timeout, Timeout, 2]
@@ -205,7 +205,7 @@ def test_execute_sigterm_timeout(self, mock_popen, mock_poll):
205205
@mock.patch('subprocess.Popen')
206206
def test_execute_sigkill_timeout(self, mock_popen, mock_poll):
207207
mock_proc = mock.Mock()
208-
mock_proc.stdout.readline.side_effect = [b'out1\n', b'out2\n', '']
208+
mock_proc.stdout.readline.side_effect = [b'out1\n', b'out2\n', b'']
209209
mock_proc.stderr.readline.side_effect = [b'err1\n', b'']
210210
mock_popen.return_value = mock_proc
211211
mock_poll.side_effect = [Timeout, Timeout, Timeout]
@@ -228,7 +228,7 @@ def test_execute_sigkill_timeout(self, mock_popen, mock_poll):
228228
@mock.patch('subprocess.Popen')
229229
def test_execute_oserror(self, mock_popen, mock_poll):
230230
mock_proc = mock.Mock()
231-
mock_proc.stdout.readline.side_effect = [b'out1\n', b'out2\n', '']
231+
mock_proc.stdout.readline.side_effect = [b'out1\n', b'out2\n', b'']
232232
mock_proc.stderr.readline.side_effect = [b'err1\n', b'']
233233
mock_popen.return_value = mock_proc
234234
mock_poll.side_effect = [Timeout, Timeout]

0 commit comments

Comments
 (0)