Beispiel #1
0
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
Beispiel #2
0
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