async def test_getters(lock: Lock) -> None: assert lock.scene assert lock.project ap = next(ap for ap in lock.project.action_points if ap.name == "ap") ap2 = next(ap for ap in lock.project.action_points if ap.name == "ap2") ap_ap = next(ap for ap in lock.project.action_points if ap.name == "ap_ap") ap_ap_ap = next(ap for ap in lock.project.action_points if ap.name == "ap_ap_ap") ori = lock.project.ap_orientations(ap_ap_ap.id)[0] scene_object = next(iter(lock.scene.objects)) # test object getter for obj in (ori, ap_ap_ap, ap_ap, ap, ap2, scene_object): assert lock.get_by_id(obj.id) == obj # test parents getter parents = lock.get_all_parents(ori.id) test_parents = (ap_ap_ap.id, ap_ap.id, ap.id) assert len(parents) == len(test_parents) for item in test_parents: assert item in parents # for scene only lock.project = None assert not lock.get_all_parents(scene_object.id)
def lock() -> Lock: """Creates lock with initialized scene and project.""" test = "test" lock = Lock({}) scene = UpdateableCachedScene(cmn.Scene(test, description=test)) lock.scene = scene project = UpdateableCachedProject(cmn.Project(test, lock.scene.id, description=test, has_logic=True)) lock.project = project assert lock.scene == scene assert lock.scene_or_exception() == scene assert lock.project == project assert lock.project_or_exception() == project # add some scene and project objects test_object = cmn.SceneObject(test, "TestType") lock.scene.upsert_object(test_object) ap = lock.project.upsert_action_point(cmn.BareActionPoint.uid(), "ap", cmn.Position(0, 0, 0)) ap_ap = lock.project.upsert_action_point(cmn.BareActionPoint.uid(), "ap_ap", cmn.Position(0, 0, 1), ap.id) ap_ap_ap = lock.project.upsert_action_point(cmn.BareActionPoint.uid(), "ap_ap_ap", cmn.Position(0, 0, 2), ap_ap.id) lock.project.upsert_action_point(cmn.BareActionPoint.uid(), "ap2", cmn.Position(0, 1, 0)) ori = cmn.NamedOrientation("ori", cmn.Orientation()) lock.project.upsert_orientation(ap_ap_ap.id, ori) action = cmn.Action("action", "test/type", parameters=[], flows=[]) lock.project.upsert_action(ap_ap_ap.id, action) return lock
async def test_root_getter(lock: Lock) -> None: assert lock.scene assert lock.project ap = next(ap for ap in lock.project.action_points if ap.name == "ap") ap_ap = next(ap for ap in lock.project.action_points if ap.name == "ap_ap") scene_object_id = next(iter(lock.scene.object_ids)) assert await lock.get_root_id(lock.scene.id) == lock.scene.id assert await lock.get_root_id(lock.project.id) == lock.project.id assert await lock.get_root_id(scene_object_id) == scene_object_id assert await lock.get_root_id(ap_ap.id) == ap.id assert await lock.get_root_id(ap.id) == ap.id # root getter for scene only lock.project = None assert await lock.get_root_id(scene_object_id) == scene_object_id
async def test_root_getter_without_scene_and_project(lock: Lock) -> None: assert lock.scene assert lock.project scene = lock.scene project = lock.project lock.project = None lock.scene = None with pytest.raises(Arcor2Exception): lock.scene_or_exception() with pytest.raises(Arcor2Exception): lock.project_or_exception() async def patch() -> set[str]: return {project.id, scene.id} storage.get_project_ids = storage.get_scene_ids = patch assert await lock.get_root_id(project.id) == project.id assert await lock.get_root_id(scene.id) == scene.id