mirror of
https://github.com/home-assistant/core.git
synced 2025-08-12 06:50:00 +00:00
.github
config
docs
homeassistant
script
tests
components
alarm_control_panel
automation
binary_sensor
camera
climate
cover
test_command_line.py
test_demo.py
test_mqtt.py
test_rfxtrx.py
device_tracker
fan
light
lock
media_player
mqtt
notify
recorder
sensor
switch
weather
__init__.py
test_alexa.py
test_api.py
test_configurator.py
test_conversation.py
test_demo.py
test_device_sun_light_trigger.py
test_emulated_hue.py
test_frontend.py
test_graphite.py
test_group.py
test_history.py
test_http.py
test_influxdb.py
test_init.py
test_input_boolean.py
test_input_select.py
test_input_slider.py
test_introduction.py
test_logbook.py
test_logentries.py
test_logger.py
test_mqtt_eventstream.py
test_panel_custom.py
test_panel_iframe.py
test_persistent_notification.py
test_pilight.py
test_proximity.py
test_rfxtrx.py
test_scene.py
test_script.py
test_shell_command.py
test_sleepiq.py
test_splunk.py
test_statsd.py
test_sun.py
test_updater.py
test_weblink.py
test_zone.py
fixtures
helpers
resources
scripts
test_util
testing_config
util
__init__.py
common.py
conftest.py
test_bootstrap.py
test_config.py
test_core.py
test_loader.py
test_main.py
test_remote.py
virtualization
.coveragerc
.dockerignore
.gitignore
.gitmodules
.hound.yml
.travis.yml
CONTRIBUTING.md
Dockerfile
LICENSE
MANIFEST.in
README.rst
pylintrc
requirements_all.txt
requirements_docs.txt
requirements_test.txt
setup.cfg
setup.py
tox.ini

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))
88 lines
3.0 KiB
Python
88 lines
3.0 KiB
Python
"""The tests the cover command line platform."""
|
|
|
|
import os
|
|
import tempfile
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
from homeassistant.bootstrap import setup_component
|
|
import homeassistant.components.cover as cover
|
|
from homeassistant.components.cover import (
|
|
command_line as cmd_rs)
|
|
|
|
from tests.common import get_test_home_assistant
|
|
|
|
|
|
class TestCommandCover(unittest.TestCase):
|
|
"""Test the cover command line platform."""
|
|
|
|
def setup_method(self, method):
|
|
"""Setup things to be run when tests are started."""
|
|
self.hass = get_test_home_assistant()
|
|
self.rs = cmd_rs.CommandCover(self.hass, 'foo',
|
|
'command_open', 'command_close',
|
|
'command_stop', 'command_state',
|
|
None)
|
|
|
|
def teardown_method(self, method):
|
|
"""Stop down everything that was started."""
|
|
self.hass.stop()
|
|
|
|
def test_should_poll(self):
|
|
"""Test the setting of polling."""
|
|
self.assertTrue(self.rs.should_poll)
|
|
self.rs._command_state = None
|
|
self.assertFalse(self.rs.should_poll)
|
|
|
|
def test_query_state_value(self):
|
|
"""Test with state value."""
|
|
with mock.patch('subprocess.check_output') as mock_run:
|
|
mock_run.return_value = b' foo bar '
|
|
result = self.rs._query_state_value('runme')
|
|
self.assertEqual('foo bar', result)
|
|
self.assertEqual(mock_run.call_count, 1)
|
|
self.assertEqual(
|
|
mock_run.call_args, mock.call('runme', shell=True)
|
|
)
|
|
|
|
def test_state_value(self):
|
|
"""Test with state value."""
|
|
with tempfile.TemporaryDirectory() as tempdirname:
|
|
path = os.path.join(tempdirname, 'cover_status')
|
|
test_cover = {
|
|
'command_state': 'cat {}'.format(path),
|
|
'command_open': 'echo 1 > {}'.format(path),
|
|
'command_close': 'echo 1 > {}'.format(path),
|
|
'command_stop': 'echo 0 > {}'.format(path),
|
|
'value_template': '{{ value }}'
|
|
}
|
|
self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
|
|
'cover': {
|
|
'platform': 'command_line',
|
|
'covers': {
|
|
'test': test_cover
|
|
}
|
|
}
|
|
}))
|
|
|
|
state = self.hass.states.get('cover.test')
|
|
self.assertEqual('unknown', state.state)
|
|
|
|
cover.open_cover(self.hass, 'cover.test')
|
|
self.hass.block_till_done()
|
|
|
|
state = self.hass.states.get('cover.test')
|
|
self.assertEqual('open', state.state)
|
|
|
|
cover.close_cover(self.hass, 'cover.test')
|
|
self.hass.block_till_done()
|
|
|
|
state = self.hass.states.get('cover.test')
|
|
self.assertEqual('open', state.state)
|
|
|
|
cover.stop_cover(self.hass, 'cover.test')
|
|
self.hass.block_till_done()
|
|
|
|
state = self.hass.states.get('cover.test')
|
|
self.assertEqual('closed', state.state)
|