desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Test the icon.'
| def test_icon(self):
| for name in self.sensor_dict:
sensor = self.sensor_dict[name]['sensor']
self.assertEqual(self.sensor_dict[name]['icon'], sensor.icon)
|
'Test the initial state.'
| @requests_mock.Mocker()
def test_state(self, mock_req):
| self.setup_api(MOCK_DATA, mock_req)
now = datetime(1970, month=1, day=1)
with patch('homeassistant.util.dt.now', return_value=now):
for name in self.sensor_dict:
sensor = self.sensor_dict[name]['sensor']
self.fake_delay(2)
sensor.update()
if (name == g... |
'Test state gets updated to unknown when sensor returns no data.'
| @requests_mock.Mocker()
def test_update_when_value_is_none(self, mock_req):
| self.setup_api(None, mock_req)
for name in self.sensor_dict:
sensor = self.sensor_dict[name]['sensor']
self.fake_delay(2)
sensor.update()
self.assertEqual(STATE_UNKNOWN, sensor.state)
|
'Test state gets updated when sensor returns a new status.'
| @requests_mock.Mocker()
def test_update_when_value_changed(self, mock_req):
| self.setup_api(MOCK_DATA_NEXT, mock_req)
now = datetime(1970, month=1, day=1)
with patch('homeassistant.util.dt.now', return_value=now):
for name in self.sensor_dict:
sensor = self.sensor_dict[name]['sensor']
self.fake_delay(2)
sensor.update()
if (name... |
'Test state logs an error when data is missing.'
| @requests_mock.Mocker()
def test_when_api_data_missing(self, mock_req):
| self.setup_api(MOCK_DATA_MISSING, mock_req)
now = datetime(1970, month=1, day=1)
with patch('homeassistant.util.dt.now', return_value=now):
for name in self.sensor_dict:
sensor = self.sensor_dict[name]['sensor']
self.fake_delay(2)
sensor.update()
self.... |
'Test state updates when Google Wifi unavailable.'
| def test_update_when_unavailable(self):
| self.api.update = Mock('google_wifi.GoogleWifiAPI.update', side_effect=self.update_side_effect())
for name in self.sensor_dict:
sensor = self.sensor_dict[name]['sensor']
sensor.update()
self.assertEqual(STATE_UNKNOWN, sensor.state)
|
'Mock representation of update function.'
| def update_side_effect(self):
| self.api.data = None
self.api.available = False
|
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
|
'Stop down everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test the setting of the value via MQTT.'
| def test_setting_sensor_value_via_mqtt_message(self):
| mock_component(self.hass, 'mqtt')
assert setup_component(self.hass, sensor.DOMAIN, {sensor.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'state_topic': 'test-topic', 'unit_of_measurement': 'fav unit'}})
fire_mqtt_message(self.hass, 'test-topic', '100')
self.hass.block_till_done()
state = self.hass... |
'Test the expiration of the value.'
| @patch('homeassistant.core.dt_util.utcnow')
def test_setting_sensor_value_expires(self, mock_utcnow):
| mock_component(self.hass, 'mqtt')
assert setup_component(self.hass, sensor.DOMAIN, {sensor.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'state_topic': 'test-topic', 'unit_of_measurement': 'fav unit', 'expire_after': '4', 'force_update': True}})
state = self.hass.states.get('sensor.test')
self.assertE... |
'Test the setting of the value via MQTT with JSON playload.'
| def test_setting_sensor_value_via_mqtt_json_message(self):
| mock_component(self.hass, 'mqtt')
assert setup_component(self.hass, sensor.DOMAIN, {sensor.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'state_topic': 'test-topic', 'unit_of_measurement': 'fav unit', 'value_template': '{{ value_json.val }}'}})
fire_mqtt_message(self.hass, 'test-topic', '{ "val":... |
'Test force update option.'
| def test_force_update_disabled(self):
| mock_component(self.hass, 'mqtt')
assert setup_component(self.hass, sensor.DOMAIN, {sensor.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'state_topic': 'test-topic', 'unit_of_measurement': 'fav unit'}})
events = []
@ha.callback
def callback(event):
events.append(event)
self.hass.bus.li... |
'Test force update option.'
| def test_force_update_enabled(self):
| mock_component(self.hass, 'mqtt')
assert setup_component(self.hass, sensor.DOMAIN, {sensor.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'state_topic': 'test-topic', 'unit_of_measurement': 'fav unit', 'force_update': True}})
events = []
@ha.callback
def callback(event):
events.append(event... |
'Send a time changed event.'
| def _send_time_changed(self, now):
| self.hass.bus.fire(ha.EVENT_TIME_CHANGED, {ha.ATTR_NOW: now})
|
'Mock add devices.'
| def add_devices(self, devices):
| for device in devices:
self.DEVICES.append(device)
|
'Initialize values for this testcase class.'
| def setUp(self):
| self.hass = get_test_home_assistant()
self.username = 'foo'
self.password = 'bar'
self.config = {'username': self.username, 'password': self.password}
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test for successfully setting up the SleepIQ platform.'
| @requests_mock.Mocker()
def test_setup(self, mock):
| mock_responses(mock)
assert setup_component(self.hass, 'sleepiq', {'sleepiq': {'username': '', 'password': ''}})
sleepiq.setup_platform(self.hass, self.config, self.add_devices, MagicMock())
self.assertEqual(2, len(self.DEVICES))
left_side = self.DEVICES[1]
self.assertEqual('SleepNumber ILE ... |
'Initialize values for this testcase class.'
| def setUp(self):
| self.hass = get_test_home_assistant()
self.config = VALID_CONFIG
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test for operational tube_state sensor with proper attributes.'
| @requests_mock.Mocker()
def test_setup(self, mock_req):
| mock_req.get(URL, text=load_fixture('london_underground.json'))
self.assertTrue(setup_component(self.hass, 'sensor', {'sensor': self.config}))
state = self.hass.states.get('sensor.london_overground')
assert (state.state == 'Minor Delays')
assert (state.attributes.get('Description') == 'something'... |
'Mock add devices.'
| def add_devices(self, devices, update):
| for device in devices:
self.DEVICES.append(device)
|
'Initialize values for this testcase class.'
| def setUp(self):
| self.DEVICES = []
self.hass = get_test_home_assistant()
self.hass.config.time_zone = 'America/Los_Angeles'
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test getting all disk space.'
| @unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_diskspace_no_paths(self, req_mock):
| config = {'platform': 'sonarr', 'api_key': 'foo', 'days': '2', 'unit': 'GB', 'include_paths': [], 'monitored_conditions': ['diskspace']}
sonarr.setup_platform(self.hass, config, self.add_devices, None)
for device in self.DEVICES:
device.update()
self.assertEqual('263.10', device.state)
... |
'Test getting diskspace for included paths.'
| @unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_diskspace_paths(self, req_mock):
| config = {'platform': 'sonarr', 'api_key': 'foo', 'days': '2', 'unit': 'GB', 'include_paths': ['/data'], 'monitored_conditions': ['diskspace']}
sonarr.setup_platform(self.hass, config, self.add_devices, None)
for device in self.DEVICES:
device.update()
self.assertEqual('263.10', device.state... |
'Test getting running commands.'
| @unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_commands(self, req_mock):
| config = {'platform': 'sonarr', 'api_key': 'foo', 'days': '2', 'unit': 'GB', 'include_paths': ['/data'], 'monitored_conditions': ['commands']}
sonarr.setup_platform(self.hass, config, self.add_devices, None)
for device in self.DEVICES:
device.update()
self.assertEqual(1, device.state)
... |
'Test getting downloads in the queue.'
| @unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_queue(self, req_mock):
| config = {'platform': 'sonarr', 'api_key': 'foo', 'days': '2', 'unit': 'GB', 'include_paths': ['/data'], 'monitored_conditions': ['queue']}
sonarr.setup_platform(self.hass, config, self.add_devices, None)
for device in self.DEVICES:
device.update()
self.assertEqual(1, device.state)
s... |
'Test getting the number of series.'
| @unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_series(self, req_mock):
| config = {'platform': 'sonarr', 'api_key': 'foo', 'days': '2', 'unit': 'GB', 'include_paths': ['/data'], 'monitored_conditions': ['series']}
sonarr.setup_platform(self.hass, config, self.add_devices, None)
for device in self.DEVICES:
device.update()
self.assertEqual(1, device.state)
... |
'Test getting wanted episodes.'
| @unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_wanted(self, req_mock):
| config = {'platform': 'sonarr', 'api_key': 'foo', 'days': '2', 'unit': 'GB', 'include_paths': ['/data'], 'monitored_conditions': ['wanted']}
sonarr.setup_platform(self.hass, config, self.add_devices, None)
for device in self.DEVICES:
device.update()
self.assertEqual(1, device.state)
... |
'Test the upcoming episodes for multiple days.'
| @unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_upcoming_multiple_days(self, req_mock):
| config = {'platform': 'sonarr', 'api_key': 'foo', 'days': '2', 'unit': 'GB', 'include_paths': ['/data'], 'monitored_conditions': ['upcoming']}
sonarr.setup_platform(self.hass, config, self.add_devices, None)
for device in self.DEVICES:
device.update()
self.assertEqual(1, device.state)
... |
'Test filtering for a single day.
Sonarr needs to respond with at least 2 days'
| @pytest.mark.skip
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_upcoming_today(self, req_mock):
| config = {'platform': 'sonarr', 'api_key': 'foo', 'days': '1', 'unit': 'GB', 'include_paths': ['/data'], 'monitored_conditions': ['upcoming']}
sonarr.setup_platform(self.hass, config, self.add_devices, None)
for device in self.DEVICES:
device.update()
self.assertEqual(1, device.state)
... |
'Test SSL being enabled.'
| @pytest.mark.skip
@unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_ssl(self, req_mock):
| config = {'platform': 'sonarr', 'api_key': 'foo', 'days': '1', 'unit': 'GB', 'include_paths': ['/data'], 'monitored_conditions': ['upcoming'], 'ssl': 'true'}
sonarr.setup_platform(self.hass, config, self.add_devices, None)
for device in self.DEVICES:
device.update()
self.assertEqual(1, devic... |
'Test exception being handled.'
| @unittest.mock.patch('requests.get', side_effect=mocked_exception)
def test_exception_handling(self, req_mock):
| config = {'platform': 'sonarr', 'api_key': 'foo', 'days': '1', 'unit': 'GB', 'include_paths': ['/data'], 'monitored_conditions': ['upcoming']}
sonarr.setup_platform(self.hass, config, self.add_devices, None)
for device in self.DEVICES:
device.update()
self.assertEqual(None, device.state)
|
'Mock add entities.'
| def add_entities(self, new_entities, update_before_add=False):
| if update_before_add:
for entity in new_entities:
entity.update()
for entity in new_entities:
self.entities.append(entity)
|
'Initialize values for this testcase class.'
| def setUp(self):
| self.hass = get_test_home_assistant()
self.key = 'foo'
self.config = {'api_key': 'foo', 'forecast': [1, 2], 'monitored_conditions': ['summary', 'icon', 'temperature_max'], 'update_interval': timedelta(seconds=120)}
self.lat = self.hass.config.latitude = 37.8267
self.lon = self.hass.config.longitude ... |
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test the platform setup with configuration.'
| def test_setup_with_config(self):
| self.assertTrue(setup_component(self.hass, 'sensor', {'darksky': self.config}))
|
'Test for handling a bad API key.'
| @patch('forecastio.api.get_forecast')
def test_setup_bad_api_key(self, mock_get_forecast):
| url = 'https://api.darksky.net/forecast/{}/{},{}?units=auto'.format(self.key, str(self.lat), str(self.lon))
msg = '400 Client Error: Bad Request for url: {}'.format(url)
mock_get_forecast.side_effect = HTTPError(msg)
response = darksky.setup_platform(self.hass, self.config, MagicMoc... |
'Test for successfully setting up the forecast.io platform.'
| @requests_mock.Mocker()
@patch('forecastio.api.get_forecast', wraps=forecastio.api.get_forecast)
def test_setup(self, mock_req, mock_get_forecast):
| uri = 'https://api.(darksky.net|forecast.io)\\/forecast\\/(\\w+)\\/(-?\\d+\\.?\\d*),(-?\\d+\\.?\\d*)'
mock_req.get(re.compile(uri), text=load_fixture('darksky.json'))
darksky.setup_platform(self.hass, self.config, self.add_entities)
self.assertTrue(mock_get_forecast.called)
self.assertEqual(mock_get... |
'Initialize values for this testcase class.'
| def setUp(self):
| self.hass = get_test_home_assistant()
self.config = VALID_CONFIG
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test for operational uk_transport sensor with proper attributes.'
| @requests_mock.Mocker()
def test_bus(self, mock_req):
| with requests_mock.Mocker() as mock_req:
uri = re.compile((UkTransportSensor.TRANSPORT_API_URL_BASE + '*'))
mock_req.get(uri, text=load_fixture('uk_transport_bus.json'))
self.assertTrue(setup_component(self.hass, 'sensor', {'sensor': self.config}))
bus_state = self.hass.states.get('senso... |
'Test for operational uk_transport sensor with proper attributes.'
| @requests_mock.Mocker()
def test_train(self, mock_req):
| with requests_mock.Mocker() as mock_req:
uri = re.compile((UkTransportSensor.TRANSPORT_API_URL_BASE + '*'))
mock_req.get(uri, text=load_fixture('uk_transport_train.json'))
self.assertTrue(setup_component(self.hass, 'sensor', {'sensor': self.config}))
train_state = self.hass.states.get('s... |
'Mock add devices.'
| @requests_mock.Mocker()
def add_devices(self, devices, mock):
| mock_responses(mock)
for device in devices:
device.update()
self.DEVICES.append(device)
|
'Initialize values for this testcase class.'
| def setUp(self):
| self.hass = get_test_home_assistant()
self.config = ONE_SENSOR_CONFIG
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test for successfully setting up the Efergy platform.'
| @requests_mock.Mocker()
def test_single_sensor_readings(self, mock):
| mock_responses(mock)
assert setup_component(self.hass, 'sensor', {'sensor': ONE_SENSOR_CONFIG})
self.assertEqual('38.21', self.hass.states.get('sensor.energy_consumed').state)
self.assertEqual('1580', self.hass.states.get('sensor.energy_usage').state)
self.assertEqual('ok', self.hass.states.get('sen... |
'Test for multiple sensors in one household.'
| @requests_mock.Mocker()
def test_multi_sensor_readings(self, mock):
| mock_responses(mock)
assert setup_component(self.hass, 'sensor', {'sensor': MULTI_SENSOR_CONFIG})
self.assertEqual('218', self.hass.states.get('sensor.efergy_728386').state)
self.assertEqual('1808', self.hass.states.get('sensor.efergy_0').state)
self.assertEqual('312', self.hass.states.get('sensor.e... |
'Initialize values for this testcase class.'
| def setUp(self):
| self.hass = get_test_home_assistant()
self.config = VALID_CONFIG
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test the default setup.'
| @patch('yahoo_finance.Base._request', return_value=json.loads(load_fixture('yahoo_finance.json')))
def test_default_setup(self, mock_request):
| with assert_setup_component(1, sensor.DOMAIN):
assert setup_component(self.hass, sensor.DOMAIN, {'sensor': VALID_CONFIG})
state = self.hass.states.get('sensor.yhoo')
self.assertEqual('41.69', state.attributes.get('open'))
self.assertEqual('41.79', state.attributes.get('prev_close'))
self.ass... |
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
mock_component(self.hass, 'rfxtrx')
|
'Stop everything that was started.'
| def tearDown(self):
| rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS = []
rfxtrx_core.RFX_DEVICES = {}
if rfxtrx_core.RFXOBJECT:
rfxtrx_core.RFXOBJECT.close_connection()
self.hass.stop()
|
'Test with 0 sensor.'
| def test_default_config(self):
| self.assertTrue(setup_component(self.hass, 'sensor', {'sensor': {'platform': 'rfxtrx', 'devices': {}}}))
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
|
'Test with 1 sensor.'
| def test_old_config_sensor(self):
| self.assertTrue(setup_component(self.hass, 'sensor', {'sensor': {'platform': 'rfxtrx', 'devices': {'sensor_0502': {'name': 'Test', 'packetid': '0a52080705020095220269', 'data_type': 'Temperature'}}}}))
self.assertEqual(1, len(rfxtrx_core.RFX_DEVICES))
entity = rfxtrx_core.RFX_DEVICES['sensor_0502']['Tempera... |
'Test with 1 sensor.'
| def test_one_sensor(self):
| self.assertTrue(setup_component(self.hass, 'sensor', {'sensor': {'platform': 'rfxtrx', 'devices': {'0a52080705020095220269': {'name': 'Test', 'data_type': 'Temperature'}}}}))
self.assertEqual(1, len(rfxtrx_core.RFX_DEVICES))
entity = rfxtrx_core.RFX_DEVICES['sensor_0502']['Temperature']
self.assertEqual... |
'Test with 1 sensor.'
| def test_one_sensor_no_datatype(self):
| self.assertTrue(setup_component(self.hass, 'sensor', {'sensor': {'platform': 'rfxtrx', 'devices': {'0a52080705020095220269': {'name': 'Test'}}}}))
self.assertEqual(1, len(rfxtrx_core.RFX_DEVICES))
entity = rfxtrx_core.RFX_DEVICES['sensor_0502']['Temperature']
self.assertEqual('Test', entity.name)
se... |
'Test with 3 sensors.'
| def test_several_sensors(self):
| self.assertTrue(setup_component(self.hass, 'sensor', {'sensor': {'platform': 'rfxtrx', 'devices': {'0a52080705020095220269': {'name': 'Test', 'data_type': 'Temperature'}, '0a520802060100ff0e0269': {'name': 'Bath', 'data_type': ['Temperature', 'Humidity']}}}}))
self.assertEqual(2, len(rfxtrx_core.RFX_DEVICES))
... |
'Test with discovery of sensor.'
| def test_discover_sensor(self):
| self.assertTrue(setup_component(self.hass, 'sensor', {'sensor': {'platform': 'rfxtrx', 'automatic_add': True, 'devices': {}}}))
event = rfxtrx_core.get_rfx_object('0a520801070100b81b0279')
event.data = bytearray('\nR\x08\x01\x07\x01\x00\xb8\x1b\x02y')
rfxtrx_core.RECEIVED_EVT_SUBSCRIBERS[0](event)
e... |
'Test with discover of sensor when auto add is False.'
| def test_discover_sensor_noautoadd(self):
| self.assertTrue(setup_component(self.hass, 'sensor', {'sensor': {'platform': 'rfxtrx', 'automatic_add': False, 'devices': {}}}))
event = rfxtrx_core.get_rfx_object('0a520801070100b81b0279')
event.data = bytearray('\nR\x08\x01\x07\x01\x00\xb8\x1b\x02y')
self.assertEqual(0, len(rfxtrx_core.RFX_DEVICES))
... |
'Test with 3 sensors.'
| def test_update_of_sensors(self):
| self.assertTrue(setup_component(self.hass, 'sensor', {'sensor': {'platform': 'rfxtrx', 'devices': {'0a52080705020095220269': {'name': 'Test', 'data_type': 'Temperature'}, '0a520802060100ff0e0269': {'name': 'Bath', 'data_type': ['Temperature', 'Humidity']}}}}))
self.assertEqual(2, len(rfxtrx_core.RFX_DEVICES))
... |
'Setup things to be run when tests are started.'
| def setup_method(self, method):
| self.hass = get_test_home_assistant()
|
'Stop everything that was started.'
| def teardown_method(self, method):
| self.hass.stop()
|
'Test setup with missing configuration.'
| @mock.patch('mficlient.client.MFiClient')
def test_setup_missing_config(self, mock_client):
| config = {'sensor': {'platform': 'mfi'}}
assert setup_component(self.hass, 'sensor', config)
assert (not mock_client.called)
|
'Test setup with login failure.'
| @mock.patch('mficlient.client.MFiClient')
def test_setup_failed_login(self, mock_client):
| from mficlient.client import FailedToLogin
mock_client.side_effect = FailedToLogin
self.assertFalse(self.PLATFORM.setup_platform(self.hass, dict(self.GOOD_CONFIG), None))
|
'Test setup with conection failure.'
| @mock.patch('mficlient.client.MFiClient')
def test_setup_failed_connect(self, mock_client):
| mock_client.side_effect = requests.exceptions.ConnectionError
self.assertFalse(self.PLATFORM.setup_platform(self.hass, dict(self.GOOD_CONFIG), None))
|
'Test setup with minimum configuration.'
| @mock.patch('mficlient.client.MFiClient')
def test_setup_minimum(self, mock_client):
| config = dict(self.GOOD_CONFIG)
del config[self.THING]['port']
assert setup_component(self.hass, self.COMPONENT.DOMAIN, config)
self.assertEqual(mock_client.call_count, 1)
self.assertEqual(mock_client.call_args, mock.call('foo', 'user', 'pass', port=6443, use_tls=True, verify=True))
|
'Test setup with port.'
| @mock.patch('mficlient.client.MFiClient')
def test_setup_with_port(self, mock_client):
| config = dict(self.GOOD_CONFIG)
config[self.THING]['port'] = 6123
assert setup_component(self.hass, self.COMPONENT.DOMAIN, config)
self.assertEqual(mock_client.call_count, 1)
self.assertEqual(mock_client.call_args, mock.call('foo', 'user', 'pass', port=6123, use_tls=True, verify=True))
|
'Test setup without TLS.'
| @mock.patch('mficlient.client.MFiClient')
def test_setup_with_tls_disabled(self, mock_client):
| config = dict(self.GOOD_CONFIG)
del config[self.THING]['port']
config[self.THING]['ssl'] = False
config[self.THING]['verify_ssl'] = False
assert setup_component(self.hass, self.COMPONENT.DOMAIN, config)
self.assertEqual(mock_client.call_count, 1)
self.assertEqual(mock_client.call_args, mock.... |
'Test if setup adds devices.'
| @mock.patch('mficlient.client.MFiClient')
@mock.patch('homeassistant.components.sensor.mfi.MfiSensor')
def test_setup_adds_proper_devices(self, mock_sensor, mock_client):
| ports = {i: mock.MagicMock(model=model) for (i, model) in enumerate(mfi.SENSOR_MODELS)}
ports['bad'] = mock.MagicMock(model='notasensor')
mock_client.return_value.get_devices.return_value = [mock.MagicMock(ports=ports)]
assert setup_component(self.hass, sensor.DOMAIN, self.GOOD_CONFIG)
for (ident, p... |
'Setup things to be run when tests are started.'
| def setup_method(self, method):
| self.hass = get_test_home_assistant()
self.port = mock.MagicMock()
self.sensor = mfi.MfiSensor(self.port, self.hass)
|
'Stop everything that was started.'
| def teardown_method(self, method):
| self.hass.stop()
|
'Test the name.'
| def test_name(self):
| self.assertEqual(self.port.label, self.sensor.name)
|
'Test the UOM temperature.'
| def test_uom_temp(self):
| self.port.tag = 'temperature'
self.assertEqual(TEMP_CELSIUS, self.sensor.unit_of_measurement)
|
'Test the UOEM power.'
| def test_uom_power(self):
| self.port.tag = 'active_pwr'
self.assertEqual('Watts', self.sensor.unit_of_measurement)
|
'Test the UOM digital input.'
| def test_uom_digital(self):
| self.port.model = 'Input Digital'
self.assertEqual('State', self.sensor.unit_of_measurement)
|
'Test the UOM.'
| def test_uom_unknown(self):
| self.port.tag = 'balloons'
self.assertEqual('balloons', self.sensor.unit_of_measurement)
|
'Test that the UOM defaults if not initialized.'
| def test_uom_uninitialized(self):
| type(self.port).tag = mock.PropertyMock(side_effect=ValueError)
self.assertEqual('State', self.sensor.unit_of_measurement)
|
'Test the digital input.'
| def test_state_digital(self):
| self.port.model = 'Input Digital'
self.port.value = 0
self.assertEqual(mfi.STATE_OFF, self.sensor.state)
self.port.value = 1
self.assertEqual(mfi.STATE_ON, self.sensor.state)
self.port.value = 2
self.assertEqual(mfi.STATE_ON, self.sensor.state)
|
'Test the state of digits.'
| def test_state_digits(self):
| self.port.tag = 'didyoucheckthedict?'
self.port.value = 1.25
with mock.patch.dict(mfi.DIGITS, {'didyoucheckthedict?': 1}):
self.assertEqual(1.2, self.sensor.state)
with mock.patch.dict(mfi.DIGITS, {}):
self.assertEqual(1.0, self.sensor.state)
|
'Test the state of uninitialized sensors.'
| def test_state_uninitialized(self):
| type(self.port).tag = mock.PropertyMock(side_effect=ValueError)
self.assertEqual(mfi.STATE_OFF, self.sensor.state)
|
'Test the update.'
| def test_update(self):
| self.sensor.update()
self.assertEqual(self.port.refresh.call_count, 1)
self.assertEqual(self.port.refresh.call_args, mock.call())
|
'Mock add devices.'
| def add_devices(self, devices):
| for device in devices:
self.DEVICES.append(device)
|
'Initialize values for this testcase class.'
| def setUp(self):
| self.DEVICES = []
self.hass = get_test_home_assistant()
self.key = 'foo'
self.config = VALID_CONFIG_PWS
self.lat = 37.8267
self.lon = (-122.423)
self.hass.config.latitude = self.lat
self.hass.config.longitude = self.lon
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test that the component is loaded if passed in PWS Id.'
| @unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_setup(self, req_mock):
| self.assertTrue(wunderground.setup_platform(self.hass, VALID_CONFIG_PWS, self.add_devices, None))
self.assertTrue(wunderground.setup_platform(self.hass, VALID_CONFIG, self.add_devices, None))
self.assertTrue(wunderground.setup_platform(self.hass, INVALID_CONFIG, self.add_devices, None))
|
'Test the WUnderground sensor class and methods.'
| @unittest.mock.patch('requests.get', side_effect=mocked_requests_get)
def test_sensor(self, req_mock):
| wunderground.setup_platform(self.hass, VALID_CONFIG, self.add_devices, None)
for device in self.DEVICES:
device.update()
self.assertTrue(str(device.name).startswith('PWS_'))
if (device.name == 'PWS_weather'):
self.assertEqual(HTTPS_ICON_URL, device.entity_picture)
... |
'Mock add devices.'
| def add_devices(self, devices, action):
| for device in devices:
self.DEVICES.append(device)
|
'Cleanup any data created from the tests.'
| def cleanup(self):
| if os.path.isfile(self.cache):
os.remove(self.cache)
|
'Initialize values for this testcase class.'
| def setUp(self):
| self.hass = get_test_home_assistant()
self.cache = get_test_config_dir(base_ring.DEFAULT_CACHEDB)
self.config = {'username': 'foo', 'password': 'bar', 'monitored_conditions': ['battery', 'last_activity', 'last_ding', 'last_motion', 'volume']}
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
self.cleanup()
|
'Test the Ring senskor class and methods.'
| @requests_mock.Mocker()
def test_sensor(self, mock):
| mock.post('https://api.ring.com/clients_api/session', text=load_fixture('ring_session.json'))
mock.get('https://api.ring.com/clients_api/ring_devices', text=load_fixture('ring_devices.json'))
mock.get('https://api.ring.com/clients_api/doorbots/987652/history', text=load_fixture('ring_doorbots.json'))
ba... |
'Set up things to be run when tests are started.'
| def setup_method(self, method):
| self.hass = get_test_home_assistant()
|
'Stop everything that was started.'
| def teardown_method(self, method):
| self.hass.stop()
|
'Test the File sensor.'
| @patch('os.path.isfile', Mock(return_value=True))
@patch('os.access', Mock(return_value=True))
def test_file_value(self):
| config = {'sensor': {'platform': 'file', 'name': 'file1', 'file_path': 'mock.file1'}}
m_open = MockOpen(read_data='43\n45\n21')
with patch('homeassistant.components.sensor.file.open', m_open, create=True):
assert setup_component(self.hass, 'sensor', config)
self.hass.block_till_done()
st... |
'Test the File sensor with JSON entries.'
| @patch('os.path.isfile', Mock(return_value=True))
@patch('os.access', Mock(return_value=True))
def test_file_value_template(self):
| config = {'sensor': {'platform': 'file', 'name': 'file2', 'file_path': 'mock.file2', 'value_template': '{{ value_json.temperature }}'}}
data = '{"temperature": 29, "humidity": 31}\n{"temperature": 26, "humidity": 36}'
m_open = MockOpen(read_data=data)
with patch('homeassistant.co... |
'Test the File sensor with an empty file.'
| @patch('os.path.isfile', Mock(return_value=True))
@patch('os.access', Mock(return_value=True))
def test_file_empty(self):
| config = {'sensor': {'platform': 'file', 'name': 'file3', 'file_path': 'mock.file'}}
m_open = MockOpen(read_data='')
with patch('homeassistant.components.sensor.file.open', m_open, create=True):
assert setup_component(self.hass, 'sensor', config)
self.hass.block_till_done()
state = self.... |
'Setup the fake email reader.'
| def __init__(self, messages):
| self._messages = messages
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.