def is_child_of(self, path, strict=False): """Checks if the current object is a child of the passed object or path. """ if isinstance(path, SourceObject): path = path.path if self.path is None or path is None: return False return is_path_child_of(self.path, path, strict=strict)
def test_is_path_child_of(): from lektor.utils import is_path_child_of assert not is_path_child_of('a/b', 'a/b') assert is_path_child_of('a/b', 'a/b', strict=False) assert is_path_child_of('a/b/c', 'a') assert not is_path_child_of('a/b/c', 'b') assert is_path_child_of('a/b@foo/bar', 'a/b@foo') assert is_path_child_of('a/b@foo', 'a/b@foo', strict=False) assert not is_path_child_of('a/b@foo/bar', 'a/c@foo') assert not is_path_child_of('a/b@foo/bar', 'a/c') assert is_path_child_of('a/b@foo', 'a/b') assert is_path_child_of('a/b@foo/bar', 'a/b@foo') assert not is_path_child_of('a/b@foo/bar', 'a/b@bar')
def test_is_path_child_of(): from lektor.utils import is_path_child_of assert not is_path_child_of("a/b", "a/b") assert is_path_child_of("a/b", "a/b", strict=False) assert is_path_child_of("a/b/c", "a") assert not is_path_child_of("a/b/c", "b") assert is_path_child_of("a/b@foo/bar", "a/b@foo") assert is_path_child_of("a/b@foo", "a/b@foo", strict=False) assert not is_path_child_of("a/b@foo/bar", "a/c@foo") assert not is_path_child_of("a/b@foo/bar", "a/c") assert is_path_child_of("a/b@foo", "a/b") assert is_path_child_of("a/b@foo/bar", "a/b@foo") assert not is_path_child_of("a/b@foo/bar", "a/b@bar")
def test_is_path_child_of(): assert not is_path_child_of("a/b", "a/b") assert is_path_child_of("a/b", "a/b", strict=False) assert is_path_child_of("a/b/c", "a") assert not is_path_child_of("a/b/c", "b") assert is_path_child_of("a/b@foo/bar", "a/b@foo") assert is_path_child_of("a/b@foo", "a/b@foo", strict=False) assert not is_path_child_of("a/b@foo/bar", "a/c@foo") assert not is_path_child_of("a/b@foo/bar", "a/c") assert is_path_child_of("a/b@foo", "a/b") assert is_path_child_of("a/b@foo/bar", "a/b@foo") assert not is_path_child_of("a/b@foo/bar", "a/b@bar")