<s> """<STR_LIT>""" <EOL> import os <EOL> import tempfile <EOL> import unittest <EOL> from unittest . mock import patch <EOL> from subprocess import SubprocessError <EOL> from homeassistant . bootstrap import _setup_component <EOL> from homeassistant . components import shell_command <EOL> from tests . common import get_test_home_assistant <EOL> class TestShellCommand ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass = get_test_home_assistant ( ) <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> self . hass . stop ( ) <EOL> def test_executing_service ( self ) : <EOL> """<STR_LIT>""" <EOL> with tempfile . TemporaryDirectory ( ) as tempdirname : <EOL> path = os . path . join ( tempdirname , '<STR_LIT>' ) <EOL> assert _setup_component ( self . hass , shell_command . DOMAIN , { <EOL> shell_command . DOMAIN : { <EOL> '<STR_LIT>' : "<STR_LIT>" . format ( path ) <EOL> } <EOL> } ) <EOL> self . hass . services . call ( '<STR_LIT>' , '<STR_LIT>' , <EOL> blocking = True ) <EOL> self . assertTrue ( os . path . isfile ( path ) ) <EOL> def test_config_not_dict ( self ) : <EOL> """<STR_LIT>""" <EOL> assert not _setup_component ( self . hass , shell_command . DOMAIN , { <EOL> shell_command . DOMAIN : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:list>' ] <EOL> } ) <EOL> def test_config_not_valid_service_names ( self ) : <EOL> """<STR_LIT>""" <EOL> assert not _setup_component ( self . hass , shell_command . DOMAIN , { <EOL> shell_command . DOMAIN : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } ) <EOL> @ patch ( '<STR_LIT>' , <EOL> side_effect = SubprocessError ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_subprocess_raising_error ( self , mock_call , mock_error ) : <EOL> """<STR_LIT>""" <EOL> with tempfile . TemporaryDirectory ( ) as tempdirname : <EOL> path = os . path . join ( tempdirname , '<STR_LIT>' ) <EOL> assert _setup_component ( self . hass , shell_command . DOMAIN , { <EOL> shell_command . DOMAIN : { <EOL> '<STR_LIT>' : "<STR_LIT>" . format ( path ) <EOL> } <EOL> } ) <EOL> self . hass . services . call ( '<STR_LIT>' , '<STR_LIT>' , <EOL> blocking = True ) <EOL> self . assertFalse ( os . path . isfile ( path ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , mock_error . call_count ) </s>
