def test_invalid_value(): """Test no conversion happens if value is non-numeric.""" with pytest.raises(TypeError): METRIC_SYSTEM.length("25a", LENGTH_KILOMETERS) with pytest.raises(TypeError): METRIC_SYSTEM.temperature("50K", TEMP_CELSIUS) with pytest.raises(TypeError): METRIC_SYSTEM.volume("50L", VOLUME_LITERS) with pytest.raises(TypeError): METRIC_SYSTEM.pressure("50Pa", PRESSURE_PA)
def test_length_to_metric(self): """Test length conversion to metric system.""" self.assertEqual( 100, METRIC_SYSTEM.length(100, METRIC_SYSTEM.length_unit) ) self.assertEqual( 8.04672, METRIC_SYSTEM.length(5, IMPERIAL_SYSTEM.length_unit) )
def test_invalid_value(self): """Test no conversion happens if value is non-numeric.""" with pytest.raises(TypeError): METRIC_SYSTEM.length('25a', LENGTH_KILOMETERS) with pytest.raises(TypeError): METRIC_SYSTEM.temperature('50K', TEMP_CELSIUS) with pytest.raises(TypeError): METRIC_SYSTEM.volume('50L', VOLUME_LITERS) with pytest.raises(TypeError): METRIC_SYSTEM.pressure('50Pa', PRESSURE_PA)
def test_invalid_value(): """Test no conversion happens if value is non-numeric.""" with pytest.raises(TypeError): METRIC_SYSTEM.length("25a", LENGTH_KILOMETERS) with pytest.raises(TypeError): METRIC_SYSTEM.temperature("50K", TEMP_CELSIUS) with pytest.raises(TypeError): METRIC_SYSTEM.wind_speed("50km/h", SPEED_METERS_PER_SECOND) with pytest.raises(TypeError): METRIC_SYSTEM.volume("50L", VOLUME_LITERS) with pytest.raises(TypeError): METRIC_SYSTEM.pressure("50Pa", PRESSURE_PA) with pytest.raises(TypeError): METRIC_SYSTEM.accumulated_precipitation("50mm", LENGTH_MILLIMETERS)
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Set up the GeoNet NZ Quakes component as config entry.""" hass.data.setdefault(DOMAIN, {}) feeds = hass.data[DOMAIN].setdefault(FEED, {}) radius = config_entry.data[CONF_RADIUS] if hass.config.units.name == CONF_UNIT_SYSTEM_IMPERIAL: radius = METRIC_SYSTEM.length(radius, LENGTH_MILES) # Create feed entity manager for all platforms. manager = GeonetnzQuakesFeedEntityManager(hass, config_entry, radius) feeds[config_entry.entry_id] = manager _LOGGER.debug("Feed entity manager added for %s", config_entry.entry_id) await manager.async_init() return True
async def async_setup_entry(hass, config_entry): """Set up the GeoNet NZ Volcano component as config entry.""" hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN].setdefault(FEED, {}) radius = config_entry.data[CONF_RADIUS] unit_system = config_entry.data[CONF_UNIT_SYSTEM] if unit_system == CONF_UNIT_SYSTEM_IMPERIAL: radius = METRIC_SYSTEM.length(radius, LENGTH_MILES) # Create feed entity manager for all platforms. manager = GeonetnzVolcanoFeedEntityManager(hass, config_entry, radius, unit_system) hass.data[DOMAIN][FEED][config_entry.entry_id] = manager _LOGGER.debug("Feed entity manager added for %s", config_entry.entry_id) await manager.async_init() return True
def test_length_to_metric(): """Test length conversion to metric system.""" assert METRIC_SYSTEM.length(100, METRIC_SYSTEM.length_unit) == 100 assert METRIC_SYSTEM.length(5, IMPERIAL_SYSTEM.length_unit) == 8.04672
def test_length_unknown_unit(): """Test length conversion with unknown from unit.""" with pytest.raises(ValueError): METRIC_SYSTEM.length(5, "fr")
def test_length_unknown_unit(self): """Test length conversion with unknown from unit.""" with self.assertRaises(ValueError): METRIC_SYSTEM.length(5, 'fr')
def test_invalid_value(self): """Test no conversion happens if value is non-numeric.""" with self.assertRaises(TypeError): METRIC_SYSTEM.length('25a', LENGTH_KILOMETERS) with self.assertRaises(TypeError): METRIC_SYSTEM.temperature('50K', TEMP_CELSIUS)
def test_length_to_metric(self): """Test length conversion to metric system.""" assert 100 == \ METRIC_SYSTEM.length(100, METRIC_SYSTEM.length_unit) assert 8.04672 == \ METRIC_SYSTEM.length(5, IMPERIAL_SYSTEM.length_unit)
def test_invalid_value(self): """Test no conversion happens if value is non-numeric.""" with pytest.raises(TypeError): METRIC_SYSTEM.length('25a', LENGTH_KILOMETERS) with pytest.raises(TypeError): METRIC_SYSTEM.temperature('50K', TEMP_CELSIUS)
def test_length_to_metric(self): """Test length conversion to metric system.""" self.assertEqual(100, METRIC_SYSTEM.length(100, METRIC_SYSTEM.length_unit)) self.assertEqual(8.04672, METRIC_SYSTEM.length(5, IMPERIAL_SYSTEM.length_unit))
def test_length_unknown_unit(self): """Test length conversion with unknown from unit.""" with self.assertRaises(ValueError): METRIC_SYSTEM.length(5, 'fr')
def test_length_to_metric(self): """Test length conversion to metric system.""" assert 100 == \ METRIC_SYSTEM.length(100, METRIC_SYSTEM.length_unit) assert 8.04672 == \ METRIC_SYSTEM.length(5, IMPERIAL_SYSTEM.length_unit)
def test_wind_speed_unknown_unit(): """Test wind_speed conversion with unknown from unit.""" with pytest.raises(ValueError): METRIC_SYSTEM.length(5, "turtles")