Speed up Sonos tests (#4196)

This commit is contained in:
Lewis Juggins 2016-11-04 04:23:37 +00:00 committed by Paulus Schoutsen
parent 61a0976752
commit 6f68752d1e
2 changed files with 20 additions and 10 deletions

@ -1 +1 @@
Subproject commit 896e0427675bb99348de6f1453bd6f8cf48b5c6f Subproject commit 898a8acdc0d61a609536774fcd5e20522bb58b82

View File

@ -1,4 +1,5 @@
"""The tests for the Demo Media player platform.""" """The tests for the Demo Media player platform."""
import socket
import unittest import unittest
import soco.snapshot import soco.snapshot
from unittest import mock from unittest import mock
@ -113,7 +114,8 @@ class TestSonosMediaPlayer(unittest.TestCase):
self.hass.stop() self.hass.stop()
@mock.patch('soco.SoCo', new=SoCoMock) @mock.patch('soco.SoCo', new=SoCoMock)
def test_ensure_setup_discovery(self): @mock.patch('socket.create_connection', side_effect=socket.error())
def test_ensure_setup_discovery(self, *args):
"""Test a single device using the autodiscovery provided by HASS.""" """Test a single device using the autodiscovery provided by HASS."""
sonos.setup_platform(self.hass, {}, mock.MagicMock(), '192.0.2.1') sonos.setup_platform(self.hass, {}, mock.MagicMock(), '192.0.2.1')
@ -122,7 +124,8 @@ class TestSonosMediaPlayer(unittest.TestCase):
self.assertEqual(sonos.DEVICES[0].name, 'Kitchen') self.assertEqual(sonos.DEVICES[0].name, 'Kitchen')
@mock.patch('soco.SoCo', new=SoCoMock) @mock.patch('soco.SoCo', new=SoCoMock)
def test_ensure_setup_config(self): @mock.patch('socket.create_connection', side_effect=socket.error())
def test_ensure_setup_config(self, *args):
"""Test a single address config'd by the HASS config file.""" """Test a single address config'd by the HASS config file."""
sonos.setup_platform(self.hass, sonos.setup_platform(self.hass,
{'hosts': '192.0.2.1'}, {'hosts': '192.0.2.1'},
@ -134,15 +137,17 @@ class TestSonosMediaPlayer(unittest.TestCase):
@mock.patch('soco.SoCo', new=SoCoMock) @mock.patch('soco.SoCo', new=SoCoMock)
@mock.patch.object(soco, 'discover', new=socoDiscoverMock.discover) @mock.patch.object(soco, 'discover', new=socoDiscoverMock.discover)
def test_ensure_setup_sonos_discovery(self): @mock.patch('socket.create_connection', side_effect=socket.error())
def test_ensure_setup_sonos_discovery(self, *args):
"""Test a single device using the autodiscovery provided by Sonos.""" """Test a single device using the autodiscovery provided by Sonos."""
sonos.setup_platform(self.hass, {}, mock.MagicMock()) sonos.setup_platform(self.hass, {}, mock.MagicMock())
self.assertEqual(len(sonos.DEVICES), 1) self.assertEqual(len(sonos.DEVICES), 1)
self.assertEqual(sonos.DEVICES[0].name, 'Kitchen') self.assertEqual(sonos.DEVICES[0].name, 'Kitchen')
@mock.patch('soco.SoCo', new=SoCoMock) @mock.patch('soco.SoCo', new=SoCoMock)
@mock.patch('socket.create_connection', side_effect=socket.error())
@mock.patch.object(SoCoMock, 'partymode') @mock.patch.object(SoCoMock, 'partymode')
def test_sonos_group_players(self, partymodeMock): def test_sonos_group_players(self, partymodeMock, *args):
"""Ensuring soco methods called for sonos_group_players service.""" """Ensuring soco methods called for sonos_group_players service."""
sonos.setup_platform(self.hass, {}, mock.MagicMock(), '192.0.2.1') sonos.setup_platform(self.hass, {}, mock.MagicMock(), '192.0.2.1')
device = sonos.DEVICES[-1] device = sonos.DEVICES[-1]
@ -152,8 +157,9 @@ class TestSonosMediaPlayer(unittest.TestCase):
self.assertEqual(partymodeMock.call_args, mock.call()) self.assertEqual(partymodeMock.call_args, mock.call())
@mock.patch('soco.SoCo', new=SoCoMock) @mock.patch('soco.SoCo', new=SoCoMock)
@mock.patch('socket.create_connection', side_effect=socket.error())
@mock.patch.object(SoCoMock, 'unjoin') @mock.patch.object(SoCoMock, 'unjoin')
def test_sonos_unjoin(self, unjoinMock): def test_sonos_unjoin(self, unjoinMock, *args):
"""Ensuring soco methods called for sonos_unjoin service.""" """Ensuring soco methods called for sonos_unjoin service."""
sonos.setup_platform(self.hass, {}, mock.MagicMock(), '192.0.2.1') sonos.setup_platform(self.hass, {}, mock.MagicMock(), '192.0.2.1')
device = sonos.DEVICES[-1] device = sonos.DEVICES[-1]
@ -163,8 +169,9 @@ class TestSonosMediaPlayer(unittest.TestCase):
self.assertEqual(unjoinMock.call_args, mock.call()) self.assertEqual(unjoinMock.call_args, mock.call())
@mock.patch('soco.SoCo', new=SoCoMock) @mock.patch('soco.SoCo', new=SoCoMock)
@mock.patch('socket.create_connection', side_effect=socket.error())
@mock.patch.object(SoCoMock, 'set_sleep_timer') @mock.patch.object(SoCoMock, 'set_sleep_timer')
def test_sonos_set_sleep_timer(self, set_sleep_timerMock): def test_sonos_set_sleep_timer(self, set_sleep_timerMock, *args):
"""Ensuring soco methods called for sonos_set_sleep_timer service.""" """Ensuring soco methods called for sonos_set_sleep_timer service."""
sonos.setup_platform(self.hass, {}, mock.MagicMock(), '192.0.2.1') sonos.setup_platform(self.hass, {}, mock.MagicMock(), '192.0.2.1')
device = sonos.DEVICES[-1] device = sonos.DEVICES[-1]
@ -172,8 +179,9 @@ class TestSonosMediaPlayer(unittest.TestCase):
set_sleep_timerMock.assert_called_once_with(30) set_sleep_timerMock.assert_called_once_with(30)
@mock.patch('soco.SoCo', new=SoCoMock) @mock.patch('soco.SoCo', new=SoCoMock)
@mock.patch('socket.create_connection', side_effect=socket.error())
@mock.patch.object(SoCoMock, 'set_sleep_timer') @mock.patch.object(SoCoMock, 'set_sleep_timer')
def test_sonos_clear_sleep_timer(self, set_sleep_timerMock): def test_sonos_clear_sleep_timer(self, set_sleep_timerMock, *args):
"""Ensuring soco methods called for sonos_clear_sleep_timer service.""" """Ensuring soco methods called for sonos_clear_sleep_timer service."""
sonos.setup_platform(self.hass, {}, mock.MagicMock(), '192.0.2.1') sonos.setup_platform(self.hass, {}, mock.MagicMock(), '192.0.2.1')
device = sonos.DEVICES[-1] device = sonos.DEVICES[-1]
@ -181,8 +189,9 @@ class TestSonosMediaPlayer(unittest.TestCase):
set_sleep_timerMock.assert_called_once_with(None) set_sleep_timerMock.assert_called_once_with(None)
@mock.patch('soco.SoCo', new=SoCoMock) @mock.patch('soco.SoCo', new=SoCoMock)
@mock.patch('socket.create_connection', side_effect=socket.error())
@mock.patch.object(soco.snapshot.Snapshot, 'snapshot') @mock.patch.object(soco.snapshot.Snapshot, 'snapshot')
def test_sonos_snapshot(self, snapshotMock): def test_sonos_snapshot(self, snapshotMock, *args):
"""Ensuring soco methods called for sonos_snapshot service.""" """Ensuring soco methods called for sonos_snapshot service."""
sonos.setup_platform(self.hass, {}, mock.MagicMock(), '192.0.2.1') sonos.setup_platform(self.hass, {}, mock.MagicMock(), '192.0.2.1')
device = sonos.DEVICES[-1] device = sonos.DEVICES[-1]
@ -192,8 +201,9 @@ class TestSonosMediaPlayer(unittest.TestCase):
self.assertEqual(snapshotMock.call_args, mock.call()) self.assertEqual(snapshotMock.call_args, mock.call())
@mock.patch('soco.SoCo', new=SoCoMock) @mock.patch('soco.SoCo', new=SoCoMock)
@mock.patch('socket.create_connection', side_effect=socket.error())
@mock.patch.object(soco.snapshot.Snapshot, 'restore') @mock.patch.object(soco.snapshot.Snapshot, 'restore')
def test_sonos_restore(self, restoreMock): def test_sonos_restore(self, restoreMock, *args):
"""Ensuring soco methods called for sonos_restor service.""" """Ensuring soco methods called for sonos_restor service."""
sonos.setup_platform(self.hass, {}, mock.MagicMock(), '192.0.2.1') sonos.setup_platform(self.hass, {}, mock.MagicMock(), '192.0.2.1')
device = sonos.DEVICES[-1] device = sonos.DEVICES[-1]