Пример #1
0
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)
Пример #2
0
 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)
     )
Пример #3
0
 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)
Пример #5
0
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
Пример #6
0
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
Пример #7
0
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
Пример #8
0
def test_length_unknown_unit():
    """Test length conversion with unknown from unit."""
    with pytest.raises(ValueError):
        METRIC_SYSTEM.length(5, "fr")
Пример #9
0
 def test_length_unknown_unit(self):
     """Test length conversion with unknown from unit."""
     with self.assertRaises(ValueError):
         METRIC_SYSTEM.length(5, 'fr')
Пример #10
0
 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)
Пример #11
0
 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)
Пример #12
0
 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)
Пример #13
0
 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))
Пример #14
0
 def test_length_unknown_unit(self):
     """Test length conversion with unknown from unit."""
     with self.assertRaises(ValueError):
         METRIC_SYSTEM.length(5, 'fr')
Пример #15
0
 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")