def test_anntotation_class_new(): projects = sa.search_projects(PROJECT_NAME, return_metadata=True) for project in projects: sa.delete_project(project) sa.create_project(PROJECT_NAME, "tt", "Vector") sa.create_annotation_class(PROJECT_NAME, "tt", "#FFFFFF") assert len(sa.search_annotation_classes(PROJECT_NAME)) == 1 sa.create_annotation_class(PROJECT_NAME, "tt", "#FFFFFF") assert len(sa.search_annotation_classes(PROJECT_NAME)) == 1
def test_annotation_classes(): projects = sa.search_projects(PROJECT_NAME, return_metadata=True) for project in projects: sa.delete_project(project) project = sa.create_project(PROJECT_NAME, "test1", "Vector") clss = sa.search_annotation_classes(project) assert len(clss) == 0 ac = sa.create_annotation_class(project, "fff", "#FFFFFF") clss = sa.search_annotation_classes(project) assert len(clss) == 1 ac = sa.search_annotation_classes(project, "ff")[0] sa.delete_annotation_class(project, ac) clss = sa.search_annotation_classes(project) assert len(clss) == 0 sa.delete_project(project)
def test_anntotation_class_new_json(): projects = sa.search_projects(PROJECT_NAME_JSON, return_metadata=True) for project in projects: sa.delete_project(project) sa.create_project(PROJECT_NAME_JSON, "tt", "Vector") sa.create_annotation_classes_from_classes_json( PROJECT_NAME_JSON, "./tests/sample_project_vector/classes/classes.json" ) assert len(sa.search_annotation_classes(PROJECT_NAME_JSON)) == 4 sa.create_annotation_classes_from_classes_json( PROJECT_NAME_JSON, "./tests/sample_project_vector/classes/classes.json" ) assert len(sa.search_annotation_classes(PROJECT_NAME_JSON)) == 4
def test_basic_project(project_type, name, description, from_folder, tmpdir): tmpdir = Path(tmpdir) projects_found = sa.search_projects(name, return_metadata=True) for pr in projects_found: sa.delete_project(pr) projects_found = sa.search_projects(name, return_metadata=True) assert len(projects_found) == 0 project = sa.create_project(name, description, project_type) assert project["name"] == name assert project["description"] == description assert project["type"] == project_type projects_found = sa.search_projects(name) assert len(projects_found) == 1 assert projects_found[0] == name sa.upload_images_from_folder_to_project(project, from_folder, annotation_status="InProgress") count_in_folder = len(list(from_folder.glob("*.jpg"))) + len( list(from_folder.glob("*.png"))) count_in_folder -= len(list(from_folder.glob("*___fuse.png"))) if project_type == "Pixel": count_in_folder -= len(list(from_folder.glob("*___save.png"))) images = sa.search_images(project) assert count_in_folder == len(images) sa.create_annotation_classes_from_classes_json( project, from_folder / "classes" / "classes.json") classes_in_file = json.load(open(from_folder / "classes" / "classes.json")) classes_in_project = sa.search_annotation_classes(project) json.dump(classes_in_project, open(Path(tmpdir) / "tmp_c.json", 'w')) assert len(classes_in_file) == len(classes_in_project) for cl_f in classes_in_file: found = False for cl_c in classes_in_project: if cl_f["name"] == cl_c["name"]: found = True break assert found sa.upload_annotations_from_folder_to_project(project, from_folder) export = sa.prepare_export(project) sa.download_export(project, export, tmpdir) for image in from_folder.glob("*.[jpg|png]"): found = False for image_in_project in tmpdir.glob("*.jpg"): if image.name == image_in_project.name: found = True break assert found, image for json_in_folder in from_folder.glob("*.json"): found = False for json_in_project in tmpdir.glob("*.json"): if json_in_folder.name == json_in_project.name: found = True break assert found, json_in_folder if project_type == "Pixel": for mask_in_folder in from_folder.glob("*___save.png"): found = False for mask_in_project in tmpdir.glob("*___save.png"): if mask_in_folder.name == mask_in_project.name: found = True break assert found, mask_in_folder
def test_create_like_project(tmpdir): tmpdir = Path(tmpdir) projects = sa.search_projects(PROJECT_NAME, return_metadata=True) for project in projects: sa.delete_project(project) sa.create_project(PROJECT_NAME, "tt", "Vector") sa.create_annotation_class(PROJECT_NAME, "rrr", "#FFAAFF") old_settings = sa.get_project_settings(PROJECT_NAME) for setting in old_settings: if "attribute" in setting and setting["attribute"] == "Brightness": brightness_value = setting["value"] sa.set_project_settings(PROJECT_NAME, [{ "attribute": "Brightness", "value": brightness_value + 10 }]) sa.set_project_workflow(PROJECT_NAME, [{ "step": 1, "className": "rrr", "tool": 3 }]) users = sa.search_team_contributors() sa.share_project(PROJECT_NAME, users[1], "QA") projects = sa.search_projects(PROJECT_NAME2, return_metadata=True) for project in projects: sa.delete_project(project) new_project = sa.clone_project(PROJECT_NAME2, PROJECT_NAME, copy_contributors=True) assert new_project["description"] == "tt" assert new_project["type"] == 1 time.sleep(1) ann_classes = sa.search_annotation_classes(PROJECT_NAME2, return_metadata=True) assert len(ann_classes) == 1 assert ann_classes[0]["name"] == "rrr" assert ann_classes[0]["color"] == "#FFAAFF" new_settings = sa.get_project_settings(PROJECT_NAME2) for setting in new_settings: if "attribute" in setting and setting["attribute"] == "Brightness": new_brightness_value = setting["value"] assert new_brightness_value == brightness_value + 10 new_workflow = sa.get_project_workflow(PROJECT_NAME2) assert len(new_workflow) == 1 assert new_workflow[0]["className"] == "rrr" assert new_workflow[0]["tool"] == 3 new_project = sa.get_project_metadata(new_project["name"], include_contributors=True) assert len(new_project["contributors"]) == 1 assert new_project["contributors"][0]["user_id"] == users[1] assert new_project["contributors"][0][ "user_role"] == sa.user_role_str_to_int("QA")