Use full path to unittest.mock in tests.py

This commit is contained in:
Dave Shawley 2019-09-02 08:30:00 -04:00
parent 8d73f5bbf5
commit f24bc7c065

View file

@ -1,8 +1,7 @@
import asyncio import asyncio
import itertools import itertools
import socket import socket
import unittest import unittest.mock
from unittest import mock
from tornado import iostream, testing, web from tornado import iostream, testing, web
@ -48,7 +47,7 @@ class MisconfiguredStatsdMetricCollectionTests(testing.AsyncHTTPTestCase):
def test_bad_protocol_raises_ValueError(self): def test_bad_protocol_raises_ValueError(self):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
statsd.StatsDCollector(host='127.0.0.1', statsd.StatsDCollector(host='127.0.0.1',
port=8125, port='8125',
protocol='bad_protocol') protocol='bad_protocol')
@ -75,13 +74,13 @@ class TCPStatsdMetricCollectionTests(testing.AsyncHTTPTestCase):
'protocol': 'tcp', 'protocol': 'tcp',
'prepend_metric_type': True}) 'prepend_metric_type': True})
@mock.patch.object(iostream.IOStream, 'write') @unittest.mock.patch.object(iostream.IOStream, 'write')
def test_write_not_executed_when_connection_is_closed(self, mock_write): def test_write_not_executed_when_connection_is_closed(self, mock_write):
self.application.statsd._sock.close() self.application.statsd._sock.close()
self.application.statsd.send('foo', 500, 'c') self.application.statsd.send('foo', 500, 'c')
mock_write.assert_not_called() mock_write.assert_not_called()
@mock.patch.object(iostream.IOStream, 'write') @unittest.mock.patch.object(iostream.IOStream, 'write')
def test_expected_counters_data_written(self, mock_sock): def test_expected_counters_data_written(self, mock_sock):
path = ('foo', 'bar') path = ('foo', 'bar')
value = 500 value = 500
@ -94,7 +93,7 @@ class TCPStatsdMetricCollectionTests(testing.AsyncHTTPTestCase):
self.application.statsd.send(path, value, metric_type) self.application.statsd.send(path, value, metric_type)
mock_sock.assert_called_once_with(expected.encode()) mock_sock.assert_called_once_with(expected.encode())
@mock.patch.object(iostream.IOStream, 'write') @unittest.mock.patch.object(iostream.IOStream, 'write')
def test_expected_timers_data_written(self, mock_sock): def test_expected_timers_data_written(self, mock_sock):
path = ('foo', 'bar') path = ('foo', 'bar')
value = 500 value = 500
@ -223,7 +222,7 @@ class UDPStatsdMetricCollectionTests(testing.AsyncHTTPTestCase):
self.statsd.close() self.statsd.close()
super().tearDown() super().tearDown()
@mock.patch.object(socket.socket, 'sendto') @unittest.mock.patch.object(socket.socket, 'sendto')
def test_expected_counters_data_written(self, mock_sock): def test_expected_counters_data_written(self, mock_sock):
path = ('foo', 'bar') path = ('foo', 'bar')
value = 500 value = 500
@ -238,7 +237,7 @@ class UDPStatsdMetricCollectionTests(testing.AsyncHTTPTestCase):
expected.encode(), expected.encode(),
(self.statsd.sockaddr[0], self.statsd.sockaddr[1])) (self.statsd.sockaddr[0], self.statsd.sockaddr[1]))
@mock.patch.object(socket.socket, 'sendto') @unittest.mock.patch.object(socket.socket, 'sendto')
def test_expected_timers_data_written(self, mock_sock): def test_expected_timers_data_written(self, mock_sock):
path = ('foo', 'bar') path = ('foo', 'bar')
value = 500 value = 500