Removing calls to mock.assert_called_once_with (#3896)
If a mock's assert_called_once_with method is misspelled (e.g. asert_called_once_with) then the test will appear as passing. Therefore, this commit removes all instances of assert_called_once_with calls and replaces them with two assertions:
self.assertEqual(mock.call_count, 1)
self.assertEqual(mock.call_args, mock.call(call_args))
This commit is contained in:
committed by
Paulus Schoutsen
parent
10c9132046
commit
4891ca1610
@@ -53,7 +53,10 @@ class TestNX584SensorSetup(unittest.TestCase):
|
||||
mock_nx.assert_has_calls(
|
||||
[mock.call(zone, 'opening') for zone in self.fake_zones])
|
||||
self.assertTrue(add_devices.called)
|
||||
nx584_client.Client.assert_called_once_with('http://localhost:5007')
|
||||
self.assertEqual(nx584_client.Client.call_count, 1)
|
||||
self.assertEqual(
|
||||
nx584_client.Client.call_args, mock.call('http://localhost:5007')
|
||||
)
|
||||
|
||||
@mock.patch('homeassistant.components.binary_sensor.nx584.NX584Watcher')
|
||||
@mock.patch('homeassistant.components.binary_sensor.nx584.NX584ZoneSensor')
|
||||
@@ -73,7 +76,10 @@ class TestNX584SensorSetup(unittest.TestCase):
|
||||
mock.call(self.fake_zones[2], 'motion'),
|
||||
])
|
||||
self.assertTrue(add_devices.called)
|
||||
nx584_client.Client.assert_called_once_with('http://foo:123')
|
||||
self.assertEqual(nx584_client.Client.call_count, 1)
|
||||
self.assertEqual(
|
||||
nx584_client.Client.call_args, mock.call('http://foo:123')
|
||||
)
|
||||
self.assertTrue(mock_watcher.called)
|
||||
|
||||
def _test_assert_graceful_fail(self, config):
|
||||
@@ -174,7 +180,8 @@ class TestNX584Watcher(unittest.TestCase):
|
||||
def run(fake_process):
|
||||
fake_process.side_effect = StopMe
|
||||
self.assertRaises(StopMe, watcher._run)
|
||||
fake_process.assert_called_once_with(fake_events[0])
|
||||
self.assertEqual(fake_process.call_count, 1)
|
||||
self.assertEqual(fake_process.call_args, mock.call(fake_events[0]))
|
||||
|
||||
run()
|
||||
self.assertEqual(3, client.get_events.call_count)
|
||||
|
||||
@@ -44,9 +44,17 @@ class TestBinarySensorTemplate(unittest.TestCase):
|
||||
add_devices = mock.MagicMock()
|
||||
result = template.setup_platform(self.hass, config, add_devices)
|
||||
self.assertTrue(result)
|
||||
mock_template.assert_called_once_with(
|
||||
self.hass, 'test', 'virtual thingy', 'motion', tpl, 'test')
|
||||
add_devices.assert_called_once_with([mock_template.return_value])
|
||||
self.assertEqual(mock_template.call_count, 1)
|
||||
self.assertEqual(
|
||||
mock_template.call_args,
|
||||
mock.call(
|
||||
self.hass, 'test', 'virtual thingy', 'motion', tpl, 'test'
|
||||
)
|
||||
)
|
||||
self.assertEqual(add_devices.call_count, 1)
|
||||
self.assertEqual(
|
||||
add_devices.call_args, mock.call([mock_template.return_value])
|
||||
)
|
||||
|
||||
def test_setup_no_sensors(self):
|
||||
""""Test setup with no sensors."""
|
||||
|
||||
Reference in New Issue
Block a user