本文整理汇总了Python中homeassistant.util.unit_system.METRIC_SYSTEM.length方法的典型用法代码示例。如果您正苦于以下问题:Python METRIC_SYSTEM.length方法的具体用法?Python METRIC_SYSTEM.length怎么用?Python METRIC_SYSTEM.length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类homeassistant.util.unit_system.METRIC_SYSTEM
的用法示例。
在下文中一共展示了METRIC_SYSTEM.length方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_length_to_metric
# 需要导入模块: from homeassistant.util.unit_system import METRIC_SYSTEM [as 别名]
# 或者: from homeassistant.util.unit_system.METRIC_SYSTEM import length [as 别名]
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)
)
示例2: test_invalid_value
# 需要导入模块: from homeassistant.util.unit_system import METRIC_SYSTEM [as 别名]
# 或者: from homeassistant.util.unit_system.METRIC_SYSTEM import length [as 别名]
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)
示例3: test_length_unknown_unit
# 需要导入模块: from homeassistant.util.unit_system import METRIC_SYSTEM [as 别名]
# 或者: from homeassistant.util.unit_system.METRIC_SYSTEM import length [as 别名]
def test_length_unknown_unit(self):
"""Test length conversion with unknown from unit."""
with self.assertRaises(ValueError):
METRIC_SYSTEM.length(5, 'fr')
示例4: test_invalid_value
# 需要导入模块: from homeassistant.util.unit_system import METRIC_SYSTEM [as 别名]
# 或者: from homeassistant.util.unit_system.METRIC_SYSTEM import length [as 别名]
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)
示例5: test_length_to_metric
# 需要导入模块: from homeassistant.util.unit_system import METRIC_SYSTEM [as 别名]
# 或者: from homeassistant.util.unit_system.METRIC_SYSTEM import length [as 别名]
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)