def validator(value): if value is None: return core.ID(None, is_declaration=False, type=type) return core.ID(validate_id_name(value), is_declaration=False, type=type)
def validator(value): if value is None: return core.ID(None, is_declaration=False, type=type) return core.ID(variable_id_str_(value), is_declaration=False, type=type)
def validator(value): check_not_templatable(value) if value is None: return core.ID(None, is_declaration=False, type=type) if isinstance(value, core.ID) and value.is_declaration is False and value.type is type: return value return core.ID(validate_id_name(value), is_declaration=False, type=type)
class TestID: @pytest.fixture def target(self): return core.ID(None, is_declaration=True, type="binary_sensor::Example") @pytest.mark.parametrize("id, is_manual, expected", ( ("foo", None, True), (None, None, False), ("foo", True, True), ("foo", False, False), (None, True, True), )) def test_init__resolve_is_manual(self, id, is_manual, expected): target = core.ID(id, is_manual=is_manual) assert target.is_manual == expected @pytest.mark.parametrize("registered_ids, expected", ( ([], "binary_sensor_example"), (["binary_sensor_example"], "binary_sensor_example_2"), (["foo"], "binary_sensor_example"), (["binary_sensor_example", "foo", "binary_sensor_example_2" ], "binary_sensor_example_3"), )) def test_resolve(self, target, registered_ids, expected): actual = target.resolve(registered_ids) assert actual == expected assert str(target) == expected def test_copy(self, target): target.resolve([]) actual = target.copy() assert actual is not target assert all( getattr(actual, n) == getattr(target, n) for n in ("id", "is_declaration", "type", "is_manual")) @pytest.mark.parametrize("comparison, other, expected", ( ("__eq__", core.ID(id="foo"), True), ("__eq__", core.ID(id="bar"), False), ("__eq__", 1000, NotImplemented), ("__eq__", "1000", NotImplemented), ("__eq__", True, NotImplemented), ("__eq__", object(), NotImplemented), ("__eq__", None, NotImplemented), )) def test_comparison(self, comparison, other, expected): target = core.ID(id="foo") actual = getattr(target, comparison)(other) assert actual == expected
def test_requires_ids(self): target = core.Lambda(SAMPLE_LAMBDA.strip()) # Check cache assert target._requires_ids is None actual = target.requires_ids assert target._requires_ids is actual assert target.requires_ids is actual assert actual == [ core.ID("my_font"), core.ID("esptime"), core.ID("my_font2"), core.ID("office_tmp"), core.ID("office_hmd"), ]
def test_comparison(self, comparison, other, expected): target = core.ID(id="foo") actual = getattr(target, comparison)(other) assert actual == expected
def test_init__resolve_is_manual(self, id, is_manual, expected): target = core.ID(id, is_manual=is_manual) assert target.is_manual == expected
def target(self): return core.ID(None, is_declaration=True, type="binary_sensor::Example")
def validator(value): check_not_templatable(value) if value is None: return core.ID(None, is_declaration=True, type=type) return core.ID(validate_id_name(value), is_declaration=True, type=type)