Skip to content

Commit feb64c7

Browse files
author
Val Brodsky
committed
Handle new editor task types without breaking Project
1 parent 202e592 commit feb64c7

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

libs/labelbox/src/labelbox/schema/ontology_kind.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ class EditorTaskType(Enum):
3333
def is_supported(cls, value):
3434
return isinstance(value, cls)
3535

36+
@classmethod
37+
def _missing_(cls, name) -> 'EditorTaskType':
38+
"""Handle missing null new task types
39+
Handle upper case names for compatibility with
40+
the GraphQL"""
41+
42+
if name is None:
43+
return cls.Missing
44+
45+
for member in cls.__members__:
46+
if member.name == name.upper():
47+
return member
48+
49+
return cls.Missing
50+
3651

3752
class EditorTaskTypeMapper:
3853

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import pytest
2+
from unittest.mock import MagicMock
3+
4+
from labelbox.schema.project import Project
5+
from labelbox.schema.ontology_kind import EditorTaskType
6+
7+
8+
@pytest.mark.parametrize(
9+
'api_editor_task_type, expected_editor_task_type',
10+
[(None, EditorTaskType.Missing),
11+
('MODEL_CHAT_EVALUATION', EditorTaskType.ModelChatEvaluation),
12+
('RESPONSE_CREATION', EditorTaskType.ResponseCreation),
13+
('OFFLINE_MODEL_CHAT_EVALUATION',
14+
EditorTaskType.OfflineModelChatEvaluation),
15+
('NEW_TYPE', EditorTaskType.Missing)])
16+
def test_project_editor_task_type(api_editor_task_type,
17+
expected_editor_task_type):
18+
client = MagicMock()
19+
project = Project(
20+
client, {
21+
"id": "test",
22+
"name": "test",
23+
"createdAt": "2021-06-01T00:00:00.000Z",
24+
"updatedAt": "2021-06-01T00:00:00.000Z",
25+
"autoAuditNumberOfLabels": 1,
26+
"autoAuditPercentage": 100,
27+
"dataRowCount": 1,
28+
"description": "test",
29+
"editorTaskType": None,
30+
"lastActivityTime": "2021-06-01T00:00:00.000Z",
31+
"allowedMediaType": "IMAGE",
32+
"queueMode": "BATCH",
33+
"setupComplete": "2021-06-01T00:00:00.000Z",
34+
})
35+
36+
assert project.editor_task_type == EditorTaskType.Missing

0 commit comments

Comments
 (0)