desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Test the \'and\' condition.'
| def test_and_condition_with_template(self):
| test = condition.from_config({'condition': 'and', 'conditions': [{'condition': 'template', 'value_template': '{{ states.sensor.temperature.state == "100" }}'}, {'condition': 'numeric_state', 'entity_id': 'sensor.temperature', 'below': 110}]})
self.hass.states.set('sensor.temperature', 120)
asser... |
'Test the \'or\' condition.'
| def test_or_condition(self):
| test = condition.from_config({'condition': 'or', 'conditions': [{'condition': 'state', 'entity_id': 'sensor.temperature', 'state': '100'}, {'condition': 'numeric_state', 'entity_id': 'sensor.temperature', 'below': 110}]})
self.hass.states.set('sensor.temperature', 120)
assert (not test(self.hass))
self.... |
'Test the \'or\' condition.'
| def test_or_condition_with_template(self):
| test = condition.from_config({'condition': 'or', 'conditions': [{'condition': 'template', 'value_template': '{{ states.sensor.temperature.state == "100" }}'}, {'condition': 'numeric_state', 'entity_id': 'sensor.temperature', 'below': 110}]})
self.hass.states.set('sensor.temperature', 120)
assert... |
'Test time condition windows.'
| def test_time_window(self):
| sixam = dt.parse_time('06:00:00')
sixpm = dt.parse_time('18:00:00')
with patch('homeassistant.helpers.condition.dt_util.now', return_value=dt.now().replace(hour=3)):
assert (not condition.time(after=sixam, before=sixpm))
assert condition.time(after=sixpm, before=sixam)
with patch('homeas... |
'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 simple function (executor).'
| def test_simple_function(self):
| calls = []
def test_funct(data):
'Test function.'
calls.append(data)
dispatcher_connect(self.hass, 'test', test_funct)
dispatcher_send(self.hass, 'test', 3)
self.hass.block_till_done()
assert (calls == [3])
dispatcher_send(self.hass, 'test', 'bla')
self.hass.block_till... |
'Test simple function (executor) and unsub.'
| def test_simple_function_unsub(self):
| calls1 = []
calls2 = []
def test_funct1(data):
'Test function.'
calls1.append(data)
def test_funct2(data):
'Test function.'
calls2.append(data)
dispatcher_connect(self.hass, 'test1', test_funct1)
unsub = dispatcher_connect(self.hass, 'test2', test_funct2)
... |
'Test simple callback (async).'
| def test_simple_callback(self):
| calls = []
@callback
def test_funct(data):
'Test function.'
calls.append(data)
dispatcher_connect(self.hass, 'test', test_funct)
dispatcher_send(self.hass, 'test', 3)
self.hass.block_till_done()
assert (calls == [3])
dispatcher_send(self.hass, 'test', 'bla')
self.h... |
'Test simple coro (async).'
| def test_simple_coro(self):
| calls = []
@asyncio.coroutine
def test_funct(data):
'Test function.'
calls.append(data)
dispatcher_connect(self.hass, 'test', test_funct)
dispatcher_send(self.hass, 'test', 3)
self.hass.block_till_done()
assert (calls == [3])
dispatcher_send(self.hass, 'test', 'bla')
... |
'Test simple function (executor).'
| def test_simple_function_multiargs(self):
| calls = []
def test_funct(data1, data2, data3):
'Test function.'
calls.append(data1)
calls.append(data2)
calls.append(data3)
dispatcher_connect(self.hass, 'test', test_funct)
dispatcher_send(self.hass, 'test', 3, 2, 'bla')
self.hass.block_till_done()
assert (ca... |
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
self.calls = mock_service(self.hass, 'test_domain', 'test_service')
|
'Stop down everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test service call with tempating.'
| def test_template_service_call(self):
| config = {'service_template': "{{ 'test_domain.test_service' }}", 'entity_id': 'hello.world', 'data_template': {'hello': "{{ 'goodbye' }}", 'data': {'value': "{{ 'complex' }}", 'simple': 'simple'}, 'list': ["{{ 'list' }}", '2']}}
service.call_from_config(self.hass, config)
self.hass.... |
'Test passing variables to templates.'
| def test_passing_variables_to_templates(self):
| config = {'service_template': '{{ var_service }}', 'entity_id': 'hello.world', 'data_template': {'hello': '{{ var_data }}'}}
service.call_from_config(self.hass, config, variables={'var_service': 'test_domain.test_service', 'var_data': 'goodbye'})
self.hass.block_till_done()
self.assertEqual(... |
'Test splitting of entity string.'
| def test_split_entity_string(self):
| service.call_from_config(self.hass, {'service': 'test_domain.test_service', 'entity_id': 'hello.world, sensor.beer'})
self.hass.block_till_done()
self.assertEqual(['hello.world', 'sensor.beer'], self.calls[(-1)].data.get('entity_id'))
|
'Test for immutable input.'
| def test_not_mutate_input(self):
| config = cv.SERVICE_SCHEMA({'service': 'test_domain.test_service', 'entity_id': 'hello.world, sensor.beer', 'data': {'hello': 1}, 'data_template': {'nested': {'value': '{{ 1 + 1 }}'}}})
orig = deepcopy(config)
template.attach(self.hass, orig)
service.call_from_config(self.hass, config, va... |
'Test failling if service is missing.'
| @patch('homeassistant.helpers.service._LOGGER.error')
def test_fail_silently_if_no_service(self, mock_log):
| service.call_from_config(self.hass, None)
self.assertEqual(1, mock_log.call_count)
service.call_from_config(self.hass, {})
self.assertEqual(2, mock_log.call_count)
service.call_from_config(self.hass, {'service': 'invalid'})
self.assertEqual(3, mock_log.call_count)
|
'Test extract_entity_ids method.'
| def test_extract_entity_ids(self):
| self.hass.states.set('light.Bowl', STATE_ON)
self.hass.states.set('light.Ceiling', STATE_OFF)
self.hass.states.set('light.Kitchen', STATE_OFF)
loader.get_component('group').Group.create_group(self.hass, 'test', ['light.Ceiling', 'light.Kitchen'])
call = ha.ServiceCall('light', 'turn_on', {ATTR_ENTIT... |
'Run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
run_coroutine_threadsafe(core_components.async_setup(self.hass, {}), self.hass.loop).result()
|
'Stop when tests are finished.'
| def tearDown(self):
| self.hass.stop()
|
'Test get_changed_since.'
| def test_get_changed_since(self):
| point1 = dt_util.utcnow()
point2 = (point1 + timedelta(seconds=5))
point3 = (point2 + timedelta(seconds=5))
with patch('homeassistant.core.dt_util.utcnow', return_value=point1):
self.hass.states.set('light.test', 'on')
state1 = self.hass.states.get('light.test')
with patch('homeassis... |
'Test reproduce_state with no entity.'
| def test_reproduce_with_no_entity(self):
| calls = mock_service(self.hass, 'light', SERVICE_TURN_ON)
state.reproduce_state(self.hass, ha.State('light.test', 'on'))
self.hass.block_till_done()
self.assertTrue((len(calls) == 0))
self.assertEqual(None, self.hass.states.get('light.test'))
|
'Test reproduce_state with SERVICE_TURN_ON.'
| def test_reproduce_turn_on(self):
| calls = mock_service(self.hass, 'light', SERVICE_TURN_ON)
self.hass.states.set('light.test', 'off')
state.reproduce_state(self.hass, ha.State('light.test', 'on'))
self.hass.block_till_done()
self.assertTrue((len(calls) > 0))
last_call = calls[(-1)]
self.assertEqual('light', last_call.domain)... |
'Test reproduce_state with SERVICE_TURN_OFF.'
| def test_reproduce_turn_off(self):
| calls = mock_service(self.hass, 'light', SERVICE_TURN_OFF)
self.hass.states.set('light.test', 'on')
state.reproduce_state(self.hass, ha.State('light.test', 'off'))
self.hass.block_till_done()
self.assertTrue((len(calls) > 0))
last_call = calls[(-1)]
self.assertEqual('light', last_call.domain... |
'Test reproduce_state with complex service data.'
| def test_reproduce_complex_data(self):
| calls = mock_service(self.hass, 'light', SERVICE_TURN_ON)
self.hass.states.set('light.test', 'off')
complex_data = ['hello', {'11': '22'}]
state.reproduce_state(self.hass, ha.State('light.test', 'on', {'complex': complex_data}))
self.hass.block_till_done()
self.assertTrue((len(calls) > 0))
l... |
'Test reproduce_state with SERVICE_PLAY_MEDIA.'
| def test_reproduce_media_data(self):
| calls = mock_service(self.hass, 'media_player', SERVICE_PLAY_MEDIA)
self.hass.states.set('media_player.test', 'off')
media_attributes = {'media_content_type': 'movie', 'media_content_id': 'batman'}
state.reproduce_state(self.hass, ha.State('media_player.test', 'None', media_attributes))
self.hass.bl... |
'Test reproduce_state with SERVICE_MEDIA_PLAY.'
| def test_reproduce_media_play(self):
| calls = mock_service(self.hass, 'media_player', SERVICE_MEDIA_PLAY)
self.hass.states.set('media_player.test', 'off')
state.reproduce_state(self.hass, ha.State('media_player.test', 'playing'))
self.hass.block_till_done()
self.assertTrue((len(calls) > 0))
last_call = calls[(-1)]
self.assertEqu... |
'Test reproduce_state with SERVICE_MEDIA_PAUSE.'
| def test_reproduce_media_pause(self):
| calls = mock_service(self.hass, 'media_player', SERVICE_MEDIA_PAUSE)
self.hass.states.set('media_player.test', 'playing')
state.reproduce_state(self.hass, ha.State('media_player.test', 'paused'))
self.hass.block_till_done()
self.assertTrue((len(calls) > 0))
last_call = calls[(-1)]
self.asser... |
'Test reproduce_state with bad state.'
| def test_reproduce_bad_state(self):
| calls = mock_service(self.hass, 'light', SERVICE_TURN_ON)
self.hass.states.set('light.test', 'off')
state.reproduce_state(self.hass, ha.State('light.test', 'bad'))
self.hass.block_till_done()
self.assertTrue((len(calls) == 0))
self.assertEqual('off', self.hass.states.get('light.test').state)
|
'Test reproduce_state with group.'
| def test_reproduce_group(self):
| light_calls = mock_service(self.hass, 'light', SERVICE_TURN_ON)
self.hass.states.set('group.test', 'off', {'entity_id': ['light.test1', 'light.test2']})
state.reproduce_state(self.hass, ha.State('group.test', 'on'))
self.hass.block_till_done()
self.assertEqual(1, len(light_calls))
last_call = li... |
'Test reproduce_state with group with same domain and data.'
| def test_reproduce_group_same_data(self):
| light_calls = mock_service(self.hass, 'light', SERVICE_TURN_ON)
self.hass.states.set('light.test1', 'off')
self.hass.states.set('light.test2', 'off')
state.reproduce_state(self.hass, [ha.State('light.test1', 'on', {'brightness': 95}), ha.State('light.test2', 'on', {'brightness': 95})])
self.hass.blo... |
'Test state_as_number with states.'
| def test_as_number_states(self):
| zero_states = (STATE_OFF, STATE_CLOSED, STATE_UNLOCKED, STATE_BELOW_HORIZON, STATE_NOT_HOME)
one_states = (STATE_ON, STATE_OPEN, STATE_LOCKED, STATE_ABOVE_HORIZON, STATE_HOME)
for _state in zero_states:
self.assertEqual(0, state.state_as_number(ha.State('domain.test', _state, {})))
for _state in... |
'Test state_as_number with number.'
| def test_as_number_coercion(self):
| for _state in ('0', '0.0', 0, 0.0):
self.assertEqual(0.0, state.state_as_number(ha.State('domain.test', _state, {})))
for _state in ('1', '1.0', 1, 1.0):
self.assertEqual(1.0, state.state_as_number(ha.State('domain.test', _state, {})))
|
'Test state_as_number with invalid cases.'
| def test_as_number_invalid_cases(self):
| for _state in ('', 'foo', 'foo.bar', None, False, True, object, object()):
self.assertRaises(ValueError, state.state_as_number, ha.State('domain.test', _state, {}))
|
'Test config per platform method.'
| @patch('homeassistant.scripts.get_default_config_dir', return_value='/default')
def test_config_per_platform(self, mock_def):
| self.assertEqual(scripts.get_default_config_dir(), '/default')
self.assertEqual(scripts.extract_config_dir(), '/default')
self.assertEqual(scripts.extract_config_dir(['']), '/default')
self.assertEqual(scripts.extract_config_dir(['-c', '/arg']), '/arg')
self.assertEqual(scripts.extract_config_dir(['... |
'Prepare the test.'
| def setUp(self):
| try:
asyncio.get_event_loop()
except (RuntimeError, AssertionError):
asyncio.set_event_loop(asyncio.new_event_loop())
|
'Test a valid platform setup.'
| def test_config_platform_valid(self):
| files = {'light.yaml': (BASE_CONFIG + 'light:\n platform: demo')}
with patch_yaml_files(files):
res = check_config.check(get_test_config_dir('light.yaml'))
change_yaml_files(res)
self.assertDictEqual({'components': {'light': [{'platform': 'demo'}], 'group': None}, 'except': {},... |
'Test errors if component & platform not found.'
| def test_config_component_platform_fail_validation(self):
| files = {'component.yaml': (BASE_CONFIG + 'http:\n password: err123')}
with patch_yaml_files(files):
res = check_config.check(get_test_config_dir('component.yaml'))
change_yaml_files(res)
self.assertDictEqual({}, res['components'])
res['except'].pop(check_config.ERROR_S... |
'Test errors if component or platform not found.'
| def test_component_platform_not_found(self):
| files = {'badcomponent.yaml': (BASE_CONFIG + 'beer:'), 'badplatform.yaml': (BASE_CONFIG + 'light:\n platform: beer')}
with patch_yaml_files(files):
res = check_config.check(get_test_config_dir('badcomponent.yaml'))
change_yaml_files(res)
self.assertDictEqual({}, res['components... |
'Test secrets config checking method.'
| def test_secrets(self):
| files = {get_test_config_dir('secret.yaml'): (BASE_CONFIG + 'http:\n api_password: !secret http_pw'), 'secrets.yaml': 'logger: debug\nhttp_pw: abc123'}
self.maxDiff = None
with patch_yaml_files(files):
config_path = get_test_config_dir('secret.yaml')
secrets_path = get_tes... |
'Test a valid platform setup.'
| def test_package_invalid(self):
| files = {'bad.yaml': (BASE_CONFIG + ' packages:\n p1:\n group: ["a"]')}
with patch_yaml_files(files):
res = check_config.check(get_test_config_dir('bad.yaml'))
change_yaml_files(res)
err = res['except'].pop('homeassistant.packages.p1')
... |
'Stop everything that was started.'
| def tearDown(self):
| hass.block_till_done()
|
'Test Python API validate_api.'
| def test_validate_api(self):
| self.assertEqual(remote.APIStatus.OK, remote.validate_api(master_api))
self.assertEqual(remote.APIStatus.INVALID_PASSWORD, remote.validate_api(remote.API('127.0.0.1', (API_PASSWORD + 'A'), MASTER_PORT)))
self.assertEqual(remote.APIStatus.CANNOT_CONNECT, remote.validate_api(broken_api))
|
'Test Python API get_event_listeners.'
| def test_get_event_listeners(self):
| local_data = hass.bus.listeners
remote_data = remote.get_event_listeners(master_api)
for event in remote_data:
self.assertEqual(local_data.pop(event['event']), event['listener_count'])
self.assertEqual(len(local_data), 0)
self.assertEqual({}, remote.get_event_listeners(broken_api))
|
'Test Python API fire_event.'
| def test_fire_event(self):
| test_value = []
@ha.callback
def listener(event):
'Helper method that will verify our event got called.'
test_value.append(1)
hass.bus.listen('test.event_no_data', listener)
remote.fire_event(master_api, 'test.event_no_data')
hass.block_till_done()
sel... |
'Test Python API get_state.'
| def test_get_state(self):
| self.assertEqual(hass.states.get('test.test'), remote.get_state(master_api, 'test.test'))
self.assertEqual(None, remote.get_state(broken_api, 'test.test'))
|
'Test Python API get_state_entity_ids.'
| def test_get_states(self):
| self.assertEqual(hass.states.all(), remote.get_states(master_api))
self.assertEqual([], remote.get_states(broken_api))
|
'Test Python API set_state.'
| def test_remove_state(self):
| hass.states.set('test.remove_state', 'set_test')
self.assertIn('test.remove_state', hass.states.entity_ids())
remote.remove_state(master_api, 'test.remove_state')
self.assertNotIn('test.remove_state', hass.states.entity_ids())
|
'Test Python API set_state.'
| def test_set_state(self):
| remote.set_state(master_api, 'test.test', 'set_test')
state = hass.states.get('test.test')
self.assertIsNotNone(state)
self.assertEqual('set_test', state.state)
self.assertFalse(remote.set_state(broken_api, 'test.test', 'set_test'))
|
'Test Python API set_state with push option.'
| def test_set_state_with_push(self):
| events = []
hass.bus.listen(EVENT_STATE_CHANGED, (lambda ev: events.append(ev)))
remote.set_state(master_api, 'test.test', 'set_test_2')
remote.set_state(master_api, 'test.test', 'set_test_2')
hass.block_till_done()
self.assertEqual(1, len(events))
remote.set_state(master_api, 'test.test', '... |
'Test Python API is_state.'
| def test_is_state(self):
| self.assertTrue(remote.is_state(master_api, 'test.test', hass.states.get('test.test').state))
self.assertFalse(remote.is_state(broken_api, 'test.test', hass.states.get('test.test').state))
|
'Test Python API get_services.'
| def test_get_services(self):
| local_services = hass.services.services
for serv_domain in remote.get_services(master_api):
local = local_services.pop(serv_domain['domain'])
self.assertEqual(local, serv_domain['services'])
self.assertEqual({}, remote.get_services(broken_api))
|
'Test Python API services.call.'
| def test_call_service(self):
| test_value = []
@ha.callback
def listener(service_call):
'Helper method that will verify that our service got called.'
test_value.append(1)
hass.services.register('test_domain', 'test_service', listener)
remote.call_service(master_api, 'test_domain', 'test_... |
'Test the JSON Encoder.'
| def test_json_encoder(self):
| ha_json_enc = remote.JSONEncoder()
state = hass.states.get('test.test')
self.assertEqual(state.as_dict(), ha_json_enc.default(state))
self.assertRaises(TypeError, ha_json_enc.default, 1)
now = dt_util.utcnow()
self.assertEqual(now.isoformat(), ha_json_enc.default(now))
|
'Test getting the distance.'
| def test_get_distance_to_same_place(self):
| meters = location_util.distance(COORDINATES_PARIS[0], COORDINATES_PARIS[1], COORDINATES_PARIS[0], COORDINATES_PARIS[1])
assert (meters == 0)
|
'Test getting the distance.'
| def test_get_distance(self):
| meters = location_util.distance(COORDINATES_PARIS[0], COORDINATES_PARIS[1], COORDINATES_NEW_YORK[0], COORDINATES_NEW_YORK[1])
assert (((meters / 1000) - DISTANCE_KM) < 0.01)
|
'Test getting the distance between given coordinates in km.'
| def test_get_kilometers(self):
| kilometers = location_util.vincenty(COORDINATES_PARIS, COORDINATES_NEW_YORK)
assert (round(kilometers, 2) == DISTANCE_KM)
|
'Test getting the distance between given coordinates in miles.'
| def test_get_miles(self):
| miles = location_util.vincenty(COORDINATES_PARIS, COORDINATES_NEW_YORK, miles=True)
assert (round(miles, 2) == DISTANCE_MILES)
|
'Test detect location info using freegeoip.'
| @requests_mock.Mocker()
def test_detect_location_info_freegeoip(self, m):
| m.get(location_util.FREEGEO_API, text=load_fixture('freegeoip.io.json'))
info = location_util.detect_location_info(_test_real=True)
assert (info is not None)
assert (info.ip == '1.2.3.4')
assert (info.country_code == 'US')
assert (info.country_name == 'United States')
assert (info.region_... |
'Test detect location info using freegeoip.'
| @requests_mock.Mocker()
@patch('homeassistant.util.location._get_freegeoip', return_value=None)
def test_detect_location_info_ipapi(self, mock_req, mock_freegeoip):
| mock_req.get(location_util.IP_API, text=load_fixture('ip-api.com.json'))
info = location_util.detect_location_info(_test_real=True)
assert (info is not None)
assert (info.ip == '1.2.3.4')
assert (info.country_code == 'US')
assert (info.country_name == 'United States')
assert (info.region_... |
'Ensure we return None if both queries fail.'
| @patch('homeassistant.util.location.elevation', return_value=0)
@patch('homeassistant.util.location._get_freegeoip', return_value=None)
@patch('homeassistant.util.location._get_ip_api', return_value=None)
def test_detect_location_info_both_queries_fail(self, mock_ipapi, mock_freegeoip, mock_elevation):
| info = location_util.detect_location_info(_test_real=True)
assert (info is None)
|
'Test freegeoip query when the request to API fails.'
| @patch('homeassistant.util.location.requests.get', side_effect=requests.RequestException)
def test_freegeoip_query_raises(self, mock_get):
| info = location_util._get_freegeoip()
assert (info is None)
|
'Test ip api query when the request to API fails.'
| @patch('homeassistant.util.location.requests.get', side_effect=requests.RequestException)
def test_ip_api_query_raises(self, mock_get):
| info = location_util._get_ip_api()
assert (info is None)
|
'Test elevation when the request to API fails.'
| @patch('homeassistant.util.location.requests.get', side_effect=requests.RequestException)
def test_elevation_query_raises(self, mock_get):
| elevation = location_util.elevation(10, 10, _test_real=True)
assert (elevation == 0)
|
'Test elevation when the request to API fails.'
| @requests_mock.Mocker()
def test_elevation_query_fails(self, mock_req):
| mock_req.get(location_util.ELEVATION_URL, text='{}', status_code=401)
elevation = location_util.elevation(10, 10, _test_real=True)
assert (elevation == 0)
|
'Test if elevation API returns a non JSON value.'
| @requests_mock.Mocker()
def test_elevation_query_nonjson(self, mock_req):
| mock_req.get(location_util.ELEVATION_URL, text='{ I am not JSON }')
elevation = location_util.elevation(10, 10, _test_real=True)
assert (elevation == 0)
|
'Test errors are raised when invalid units are passed in.'
| def test_invalid_units(self):
| with self.assertRaises(ValueError):
UnitSystem(SYSTEM_NAME, INVALID_UNIT, LENGTH_METERS, VOLUME_LITERS, MASS_GRAMS)
with self.assertRaises(ValueError):
UnitSystem(SYSTEM_NAME, TEMP_CELSIUS, INVALID_UNIT, VOLUME_LITERS, MASS_GRAMS)
with self.assertRaises(ValueError):
UnitSystem(SYSTEM... |
'Test no conversion happens if value is non-numeric.'
| def test_invalid_value(self):
| with self.assertRaises(TypeError):
METRIC_SYSTEM.length('25a', LENGTH_KILOMETERS)
with self.assertRaises(TypeError):
METRIC_SYSTEM.temperature('50K', TEMP_CELSIUS)
|
'Test that the as_dict() method returns the expected dictionary.'
| def test_as_dict(self):
| expected = {LENGTH: LENGTH_KILOMETERS, TEMPERATURE: TEMP_CELSIUS, VOLUME: VOLUME_LITERS, MASS: MASS_GRAMS}
self.assertEqual(expected, METRIC_SYSTEM.as_dict())
|
'Test no conversion happens if to unit is same as from unit.'
| def test_temperature_same_unit(self):
| self.assertEqual(5, METRIC_SYSTEM.temperature(5, METRIC_SYSTEM.temperature_unit))
|
'Test no conversion happens if unknown unit.'
| def test_temperature_unknown_unit(self):
| with self.assertRaises(ValueError):
METRIC_SYSTEM.temperature(5, 'K')
|
'Test temperature conversion to metric system.'
| def test_temperature_to_metric(self):
| self.assertEqual(25, METRIC_SYSTEM.temperature(25, METRIC_SYSTEM.temperature_unit))
self.assertEqual(26.7, round(METRIC_SYSTEM.temperature(80, IMPERIAL_SYSTEM.temperature_unit), 1))
|
'Test temperature conversion to imperial system.'
| def test_temperature_to_imperial(self):
| self.assertEqual(77, IMPERIAL_SYSTEM.temperature(77, IMPERIAL_SYSTEM.temperature_unit))
self.assertEqual(77, IMPERIAL_SYSTEM.temperature(25, METRIC_SYSTEM.temperature_unit))
|
'Test length conversion with unknown from unit.'
| def test_length_unknown_unit(self):
| with self.assertRaises(ValueError):
METRIC_SYSTEM.length(5, 'fr')
|
'Test length conversion to metric system.'
| def test_length_to_metric(self):
| self.assertEqual(100, METRIC_SYSTEM.length(100, METRIC_SYSTEM.length_unit))
self.assertEqual(8.04672, METRIC_SYSTEM.length(5, IMPERIAL_SYSTEM.length_unit))
|
'Test length conversion to imperial system.'
| def test_length_to_imperial(self):
| self.assertEqual(100, IMPERIAL_SYSTEM.length(100, IMPERIAL_SYSTEM.length_unit))
self.assertEqual(3.106855, IMPERIAL_SYSTEM.length(5, METRIC_SYSTEM.length_unit))
|
'Test the unit properties are returned as expected.'
| def test_properties(self):
| self.assertEqual(LENGTH_KILOMETERS, METRIC_SYSTEM.length_unit)
self.assertEqual(TEMP_CELSIUS, METRIC_SYSTEM.temperature_unit)
self.assertEqual(MASS_GRAMS, METRIC_SYSTEM.mass_unit)
self.assertEqual(VOLUME_LITERS, METRIC_SYSTEM.volume_unit)
|
'Test the is metric flag.'
| def test_is_metric(self):
| self.assertTrue(METRIC_SYSTEM.is_metric)
self.assertFalse(IMPERIAL_SYSTEM.is_metric)
|
'Test color_RGB_to_xy.'
| def test_color_RGB_to_xy(self):
| self.assertEqual((0, 0, 0), color_util.color_RGB_to_xy(0, 0, 0))
self.assertEqual((0.32, 0.336, 255), color_util.color_RGB_to_xy(255, 255, 255))
self.assertEqual((0.136, 0.04, 12), color_util.color_RGB_to_xy(0, 0, 255))
self.assertEqual((0.172, 0.747, 170), color_util.color_RGB_to_xy(0, 255, 0))
sel... |
'Test color_RGB_to_xy.'
| def test_color_xy_brightness_to_RGB(self):
| self.assertEqual((0, 0, 0), color_util.color_xy_brightness_to_RGB(1, 1, 0))
self.assertEqual((255, 243, 222), color_util.color_xy_brightness_to_RGB(0.35, 0.35, 255))
self.assertEqual((255, 0, 60), color_util.color_xy_brightness_to_RGB(1, 0, 255))
self.assertEqual((0, 255, 0), color_util.color_xy_brightn... |
'Test color_RGB_to_hsv.'
| def test_color_RGB_to_hsv(self):
| self.assertEqual((0, 0, 0), color_util.color_RGB_to_hsv(0, 0, 0))
self.assertEqual((0, 0, 255), color_util.color_RGB_to_hsv(255, 255, 255))
self.assertEqual((43690, 255, 255), color_util.color_RGB_to_hsv(0, 0, 255))
self.assertEqual((21845, 255, 255), color_util.color_RGB_to_hsv(0, 255, 0))
self.ass... |
'Test color_RGB_to_hsv.'
| def test_color_hsv_to_RGB(self):
| self.assertEqual((0, 0, 0), color_util.color_hsv_to_RGB(0, 0, 0))
self.assertEqual((255, 255, 255), color_util.color_hsv_to_RGB(0, 0, 255))
self.assertEqual((0, 0, 255), color_util.color_hsv_to_RGB(43690, 255, 255))
self.assertEqual((0, 255, 0), color_util.color_hsv_to_RGB(21845, 255, 255))
self.ass... |
'Test color_xy_to_hs.'
| def test_color_xy_to_hs(self):
| self.assertEqual((8609, 255), color_util.color_xy_to_hs(1, 1))
self.assertEqual((6950, 32), color_util.color_xy_to_hs(0.35, 0.35))
self.assertEqual((62965, 255), color_util.color_xy_to_hs(1, 0))
self.assertEqual((21845, 255), color_util.color_xy_to_hs(0, 1))
self.assertEqual((40992, 255), color_util... |
'Test rgb_hex_to_rgb_list.'
| def test_rgb_hex_to_rgb_list(self):
| self.assertEqual([255, 255, 255], color_util.rgb_hex_to_rgb_list('ffffff'))
self.assertEqual([0, 0, 0], color_util.rgb_hex_to_rgb_list('000000'))
self.assertEqual([255, 255, 255, 255], color_util.rgb_hex_to_rgb_list('ffffffff'))
self.assertEqual([0, 0, 0, 0], color_util.rgb_hex_to_rgb_list('00000000'))
... |
'Test color_name_to_rgb.'
| def test_color_name_to_rgb_valid_name(self):
| self.assertEqual((255, 0, 0), color_util.color_name_to_rgb('red'))
self.assertEqual((0, 0, 255), color_util.color_name_to_rgb('blue'))
self.assertEqual((0, 128, 0), color_util.color_name_to_rgb('green'))
self.assertEqual((72, 61, 139), color_util.color_name_to_rgb('dark slate blue'))
self.asse... |
'Test color_name_to_rgb.'
| def test_color_name_to_rgb_unknown_name_default_white(self):
| self.assertEqual((255, 255, 255), color_util.color_name_to_rgb('not a color'))
|
'Test color_rgb_to_rgbw.'
| def test_color_rgb_to_rgbw(self):
| self.assertEqual((0, 0, 0, 0), color_util.color_rgb_to_rgbw(0, 0, 0))
self.assertEqual((0, 0, 0, 255), color_util.color_rgb_to_rgbw(255, 255, 255))
self.assertEqual((255, 0, 0, 0), color_util.color_rgb_to_rgbw(255, 0, 0))
self.assertEqual((0, 255, 0, 0), color_util.color_rgb_to_rgbw(0, 255, 0))
self... |
'Test color_rgbw_to_rgb.'
| def test_color_rgbw_to_rgb(self):
| self.assertEqual((0, 0, 0), color_util.color_rgbw_to_rgb(0, 0, 0, 0))
self.assertEqual((255, 255, 255), color_util.color_rgbw_to_rgb(0, 0, 0, 255))
self.assertEqual((255, 0, 0), color_util.color_rgbw_to_rgb(255, 0, 0, 0))
self.assertEqual((0, 255, 0), color_util.color_rgbw_to_rgb(0, 255, 0, 0))
self... |
'Test color_rgb_to_hex.'
| def test_color_rgb_to_hex(self):
| assert (color_util.color_rgb_to_hex(255, 255, 255) == 'ffffff')
assert (color_util.color_rgb_to_hex(0, 0, 0) == '000000')
assert (color_util.color_rgb_to_hex(51, 153, 255) == '3399ff')
|
'Function should return 25000K if given 40 mired.'
| def test_should_return_25000_kelvin_when_input_is_40_mired(self):
| kelvin = color_util.color_temperature_mired_to_kelvin(40)
self.assertEqual(25000, kelvin)
|
'Function should return 5000K if given 200 mired.'
| def test_should_return_5000_kelvin_when_input_is_200_mired(self):
| kelvin = color_util.color_temperature_mired_to_kelvin(200)
self.assertEqual(5000, kelvin)
|
'Function should return 40 mired when given 25000 Kelvin.'
| def test_should_return_40_mired_when_input_is_25000_kelvin(self):
| mired = color_util.color_temperature_kelvin_to_mired(25000)
self.assertEqual(40, mired)
|
'Function should return 200 mired when given 5000 Kelvin.'
| def test_should_return_200_mired_when_input_is_5000_kelvin(self):
| mired = color_util.color_temperature_kelvin_to_mired(5000)
self.assertEqual(200, mired)
|
'Function should return same value for 999 Kelvin and 0 Kelvin.'
| def test_returns_same_value_for_any_two_temperatures_below_1000(self):
| rgb_1 = color_util.color_temperature_to_rgb(999)
rgb_2 = color_util.color_temperature_to_rgb(0)
self.assertEqual(rgb_1, rgb_2)
|
'Function should return same value for 40001K and 999999K.'
| def test_returns_same_value_for_any_two_temperatures_above_40000(self):
| rgb_1 = color_util.color_temperature_to_rgb(40001)
rgb_2 = color_util.color_temperature_to_rgb(999999)
self.assertEqual(rgb_1, rgb_2)
|
'Function should return red=255, blue=255, green=255 when given 6600K.
6600K is considered "pure white" light.
This is just a rough estimate because the formula itself is a "best
guess" approach.'
| def test_should_return_pure_white_at_6600(self):
| rgb = color_util.color_temperature_to_rgb(6600)
self.assertEqual((255, 255, 255), rgb)
|
'Function should return a higher blue value for blue-ish light.'
| def test_color_above_6600_should_have_more_blue_than_red_or_green(self):
| rgb = color_util.color_temperature_to_rgb(6700)
self.assertGreater(rgb[2], rgb[1])
self.assertGreater(rgb[2], rgb[0])
|
'Function should return a higher red value for red-ish light.'
| def test_color_below_6600_should_have_more_red_than_blue_or_green(self):
| rgb = color_util.color_temperature_to_rgb(6500)
self.assertGreater(rgb[0], rgb[1])
self.assertGreater(rgb[0], rgb[2])
|
'Test sanitize_filename.'
| def test_sanitize_filename(self):
| self.assertEqual('test', util.sanitize_filename('test'))
self.assertEqual('test', util.sanitize_filename('/test'))
self.assertEqual('test', util.sanitize_filename('..test'))
self.assertEqual('test', util.sanitize_filename('\\test'))
self.assertEqual('test', util.sanitize_filename('\\../test'))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.