Renamed mock_switch_platform to mock_toggledevice_platform

pull/12/head
Paulus Schoutsen 2014-11-25 19:16:42 -08:00
parent 3e348880d5
commit 845a028d42
3 changed files with 26 additions and 23 deletions

View File

@ -7,7 +7,7 @@ Provides a mock switch platform.
import homeassistant.components as components
class MockSwitch(components.ToggleDevice):
class MockToggleDevice(components.ToggleDevice):
""" Fake switch. """
def __init__(self, name, state):
self.name = name
@ -34,22 +34,24 @@ class MockSwitch(components.ToggleDevice):
return {}
FAKE_NO_SWITCHES = False
FAKE_NO_DEVICES = False
SWITCHES = [
MockSwitch('AC', components.STATE_ON),
MockSwitch('AC', components.STATE_OFF),
MockSwitch(None, components.STATE_OFF)
DEVICES = [
MockToggleDevice('AC', components.STATE_ON),
MockToggleDevice('AC', components.STATE_OFF),
MockToggleDevice(None, components.STATE_OFF)
]
def fake_no_switches(do_fake):
""" Set the platform to act as if it has no switches. """
global FAKE_NO_SWITCHES
""" Set the platform to act as if it has no devices. """
global FAKE_NO_DEVICES
FAKE_NO_SWITCHES = do_fake
FAKE_NO_DEVICES = do_fake
def get_switches(hass, config):
""" Returns mock switches. """
return [] if FAKE_NO_SWITCHES else SWITCHES
""" Returns mock devices. """
return [] if FAKE_NO_DEVICES else DEVICES
get_lights = get_switches

View File

@ -1,8 +1,8 @@
"""
test.test_component_chromecast
~~~~~~~~~~~
test.test_component_switch
~~~~~~~~~~~~~~~~~~~~~~~~~~
Tests Chromecast component.
Tests switch component.
"""
# pylint: disable=too-many-public-methods,protected-access
import unittest
@ -12,7 +12,7 @@ import homeassistant.loader as loader
import homeassistant.components as components
import homeassistant.components.switch as switch
import mock_switch_platform
import mock_toggledevice_platform
class TestSwitch(unittest.TestCase):
@ -21,7 +21,7 @@ class TestSwitch(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
loader.prepare(self.hass)
loader.set_component('switch.test', mock_switch_platform)
loader.set_component('switch.test', mock_toggledevice_platform)
self.assertTrue(switch.setup(
self.hass, {switch.DOMAIN: {ha.CONF_TYPE: 'test'}}
@ -29,7 +29,7 @@ class TestSwitch(unittest.TestCase):
# Switch 1 is ON, switch 2 is OFF
self.switch_1, self.switch_2, self.switch_3 = \
mock_switch_platform.get_switches(None, None)
mock_toggledevice_platform.get_switches(None, None)
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """
@ -92,12 +92,13 @@ class TestSwitch(unittest.TestCase):
))
# Test if switch component returns 0 switches
mock_switch_platform.fake_no_switches(True)
mock_toggledevice_platform.fake_no_switches(True)
self.assertEqual([], mock_switch_platform.get_switches(None, None))
self.assertEqual(
[], mock_toggledevice_platform.get_switches(None, None))
self.assertFalse(switch.setup(
self.hass, {switch.DOMAIN: {ha.CONF_TYPE: 'test'}}
))
mock_switch_platform.fake_no_switches(False)
mock_toggledevice_platform.fake_no_switches(False)

View File

@ -11,7 +11,7 @@ import homeassistant as ha
import homeassistant.loader as loader
import homeassistant.components.http as http
import mock_switch_platform
import mock_toggledevice_platform
class TestLoader(unittest.TestCase):
@ -26,10 +26,10 @@ class TestLoader(unittest.TestCase):
def test_set_component(self):
""" Test if set_component works. """
loader.set_component('switch.test', mock_switch_platform)
loader.set_component('switch.test', mock_toggledevice_platform)
self.assertEqual(
mock_switch_platform, loader.get_component('switch.test'))
mock_toggledevice_platform, loader.get_component('switch.test'))
def test_get_component(self):
""" Test if get_component works. """