Skip to content

Commit 1d0cf7b

Browse files
author
Adrian Chang
committed
Formatting
1 parent 87b6a40 commit 1d0cf7b

File tree

2 files changed

+96
-8
lines changed

2 files changed

+96
-8
lines changed

libs/labelbox/tests/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,14 @@ def consensus_project(client, rand_gen):
430430

431431
@pytest.fixture
432432
def model_config(client, rand_gen, valid_model_id):
433-
model_config = client.create_model_config(name=rand_gen(str), model_id=valid_model_id, inference_params = {"param": "value"})
433+
model_config = client.create_model_config(
434+
name=rand_gen(str),
435+
model_id=valid_model_id,
436+
inference_params={"param": "value"})
434437
yield model_config
435438
client.delete_model_config(model_config.uid)
436439

440+
437441
@pytest.fixture
438442
def consensus_project_with_batch(consensus_project, initial_dataset, rand_gen,
439443
image_url):
@@ -1050,6 +1054,7 @@ def embedding(client: Client):
10501054
yield embedding
10511055
embedding.delete()
10521056

1057+
10531058
@pytest.fixture
10541059
def valid_model_id():
10551060
return "2c903542-d1da-48fd-9db1-8c62571bd3d2"

libs/labelbox/tests/unit/export_task/test_export_task.py

Lines changed: 90 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,53 @@
33
from unittest.mock import MagicMock, patch
44
from labelbox.schema.export_task import ExportTask
55

6+
67
class TestExportTask:
78

89
def test_export_task(self):
910
with patch('requests.get') as mock_requests_get:
1011
mock_task = MagicMock()
1112
mock_task.client.execute.side_effect = [
12-
{"task": {"exportMetadataHeader": { "total_size": 1, "total_lines": 1, "lines": { "start": 0, "end": 1 }, "offsets": { "start": 0, "end": 0 }, "file": "file" } } },
13-
{"task": {"exportFileFromOffset": { "total_size": 1, "total_lines": 1, "lines": { "start": 0, "end": 1 }, "offsets": { "start": 0, "end": 0 }, "file": "file" } } },
13+
{
14+
"task": {
15+
"exportMetadataHeader": {
16+
"total_size": 1,
17+
"total_lines": 1,
18+
"lines": {
19+
"start": 0,
20+
"end": 1
21+
},
22+
"offsets": {
23+
"start": 0,
24+
"end": 0
25+
},
26+
"file": "file"
27+
}
28+
}
29+
},
30+
{
31+
"task": {
32+
"exportFileFromOffset": {
33+
"total_size": 1,
34+
"total_lines": 1,
35+
"lines": {
36+
"start": 0,
37+
"end": 1
38+
},
39+
"offsets": {
40+
"start": 0,
41+
"end": 0
42+
},
43+
"file": "file"
44+
}
45+
}
46+
},
1447
]
1548
mock_task.status = "COMPLETE"
1649
data = {
1750
"data_row": {
18-
"raw_data": """
51+
"raw_data":
52+
"""
1953
{"raw_text":"}{"}
2054
{"raw_text":"\\nbad"}
2155
"""
@@ -30,12 +64,61 @@ def test_export_task_bad_offsets(self):
3064
with patch('requests.get') as mock_requests_get:
3165
mock_task = MagicMock()
3266
mock_task.client.execute.side_effect = [
33-
{"task": {"exportMetadataHeader": { "total_size": 1, "total_lines": 1, "lines": { "start": 0, "end": 1 }, "offsets": { "start": 0, "end": 0 }, "file": "file" } } },
34-
{"task": {"exportFileFromOffset": { "total_size": 1, "total_lines": 1, "lines": { "start": 0, "end": 1 }, "offsets": { "start": 0, "end": 0 }, "file": "file" } } },
67+
{
68+
"task": {
69+
"exportMetadataHeader": {
70+
"total_size": 1,
71+
"total_lines": 1,
72+
"lines": {
73+
"start": 0,
74+
"end": 1
75+
},
76+
"offsets": {
77+
"start": 0,
78+
"end": 0
79+
},
80+
"file": "file"
81+
}
82+
}
83+
},
84+
{
85+
"task": {
86+
"exportFileFromOffset": {
87+
"total_size": 1,
88+
"total_lines": 1,
89+
"lines": {
90+
"start": 0,
91+
"end": 1
92+
},
93+
"offsets": {
94+
"start": 0,
95+
"end": 0
96+
},
97+
"file": "file"
98+
}
99+
}
100+
},
35101
]
36102
mock_task.status = "COMPLETE"
37-
data = {"data_row": {"id": "clwb6wvpv3mpx0712aafl9m00", "external_id": "43cdad5e-1fcf-450d-ad72-df4460edf973", "global_key": "9ab56c5a-5c2f-45ae-8e21-e53eb415cefe", "row_data": "{\"type\":\"application/vnd.labelbox.conversational\",\"version\":1,\"messages\":[{\"messageId\":\"message-0\",\"timestampUsec\":1530718491,\"content\":\"The minimum value of $3 \\\\cos x + 4 \\\\sin x + 8$ is\",\"user\":{\"userId\":\"prompt\",\"name\":\"prompt\"},\"align\":\"left\",\"canLabel\":true}],\"modelOutputs\":[{\"title\":\"Response 1\",\"content\":\"To find the minimum value of the expression $3 \\\\cos x + 4 \\\\sin x + 8$, we can use the fact that $a\\\\cos x+b\\\\sin x=\\\\sqrt{a^2+b^2}\\\\left(\\\\frac{a}{\\\\sqrt{a^2+b^2}}\\\\cos x+\\\\frac{b}{\\\\sqrt{a^2+b^2}}\\\\sin x\\\\right)$. This allows us to rewrite the expression as:\\n\\n$3\\\\cos x+4\\\\sin x+8=\\\\sqrt{3^2+4^2}\\\\left(\\\\frac{3}{\\\\sqrt{3^2+4^2}}\\\\cos x+\\\\frac{4}{\\\\sqrt{3^2+4^2}}\\\\sin x\\\\right)+8=5\\\\left(\\\\frac{3}{5}\\\\cos x+\\\\frac{4}{5}\\\\sin x\\\\right)+8$\\n\\nNow, let's consider the expression $\\\\frac{3}{5}\\\\cos x+\\\\frac{4}{5}\\\\sin x$. Since $\\\\left(\\\\frac{3}{5}\\\\right)^2+\\\\left(\\\\frac{4}{5}\\\\right)^2=1$, we can write $\\\\frac{3}{5}=\\\\cos\\\\theta$ and $\\\\frac{4}{5}=\\\\sin\\\\theta$ for some angle $\\\\theta$. Then:\\n\\n$\\\\frac{3}{5}\\\\cos x+\\\\frac{4}{5}\\\\sin x=\\\\cos\\\\theta\\\\cos x+\\\\sin\\\\theta\\\\sin x=\\\\cos(x-\\\\theta)$\\n\\nSo, the original expression can be written as:\\n\\n$5\\\\cos(x-\\\\theta)+8$\\n\\nSince the minimum value of $\\\\cos(x-\\\\theta)$ is $-1$, the minimum value of the original expression is:\\n\\n$5(-1)+8=-5+8=3$\\n\\nTherefore, the minimum value of $3\\\\cos x + 4\\\\sin x + 8$ is $\\\\boxed{3}$.\",\"modelConfigName\":\"null\"},{\"title\":\"Response 2\",\"content\":\"A nice math question!\\n\\nTo find the minimum value of $3 \\\\cos x + 4 \\\\sin x + 8$, we can use the fact that $a\\\\cos x + b\\\\sin x = \\\\sqrt{a^2 + b^2} \\\\cos(x - \\\\alpha)$, where $\\\\alpha = \\\\tan^{-1}\\\\left(\\\\frac{b}{a}\\\\right)$.\\n\\nIn this case, $a = 3$ and $b = 4$, so $\\\\alpha = \\\\tan^{-1}\\\\left(\\\\frac{4}{3}\\\\right)$.\\n\\nSo, we have:\\n\\n$$3 \\\\cos x + 4 \\\\sin x + 8 = \\\\sqrt{3^2 + 4^2} \\\\cos(x - \\\\alpha) + 8 = 5 \\\\cos(x - \\\\alpha) + 8$$\\n\\nNow, the minimum value of $\\\\cos(x - \\\\alpha)$ is $-1$, so the minimum value of $5 \\\\cos(x - \\\\alpha) + 8$ is:\\n\\n$$5(-1) + 8 = -5 + 8 = 3$$\\n\\nTherefore, the minimum value of $3 \\\\cos x + 4 \\\\sin x + 8$ is $\\\\boxed{3}$.\\n\\nLet me know if you have any questions or need further clarification!\",\"modelConfigName\":\"null\"}]}"}, "media_attributes": {"asset_type": "conversational", "mime_type": "application/vnd.labelbox.conversational", "labelable_ids": ["message-0"], "message_count": 1}}
103+
data = {
104+
"data_row": {
105+
"id":
106+
"clwb6wvpv3mpx0712aafl9m00",
107+
"external_id":
108+
"43cdad5e-1fcf-450d-ad72-df4460edf973",
109+
"global_key":
110+
"9ab56c5a-5c2f-45ae-8e21-e53eb415cefe",
111+
"row_data":
112+
"{\"type\":\"application/vnd.labelbox.conversational\",\"version\":1,\"messages\":[{\"messageId\":\"message-0\",\"timestampUsec\":1530718491,\"content\":\"The minimum value of $3 \\\\cos x + 4 \\\\sin x + 8$ is\",\"user\":{\"userId\":\"prompt\",\"name\":\"prompt\"},\"align\":\"left\",\"canLabel\":true}],\"modelOutputs\":[{\"title\":\"Response 1\",\"content\":\"To find the minimum value of the expression $3 \\\\cos x + 4 \\\\sin x + 8$, we can use the fact that $a\\\\cos x+b\\\\sin x=\\\\sqrt{a^2+b^2}\\\\left(\\\\frac{a}{\\\\sqrt{a^2+b^2}}\\\\cos x+\\\\frac{b}{\\\\sqrt{a^2+b^2}}\\\\sin x\\\\right)$. This allows us to rewrite the expression as:\\n\\n$3\\\\cos x+4\\\\sin x+8=\\\\sqrt{3^2+4^2}\\\\left(\\\\frac{3}{\\\\sqrt{3^2+4^2}}\\\\cos x+\\\\frac{4}{\\\\sqrt{3^2+4^2}}\\\\sin x\\\\right)+8=5\\\\left(\\\\frac{3}{5}\\\\cos x+\\\\frac{4}{5}\\\\sin x\\\\right)+8$\\n\\nNow, let's consider the expression $\\\\frac{3}{5}\\\\cos x+\\\\frac{4}{5}\\\\sin x$. Since $\\\\left(\\\\frac{3}{5}\\\\right)^2+\\\\left(\\\\frac{4}{5}\\\\right)^2=1$, we can write $\\\\frac{3}{5}=\\\\cos\\\\theta$ and $\\\\frac{4}{5}=\\\\sin\\\\theta$ for some angle $\\\\theta$. Then:\\n\\n$\\\\frac{3}{5}\\\\cos x+\\\\frac{4}{5}\\\\sin x=\\\\cos\\\\theta\\\\cos x+\\\\sin\\\\theta\\\\sin x=\\\\cos(x-\\\\theta)$\\n\\nSo, the original expression can be written as:\\n\\n$5\\\\cos(x-\\\\theta)+8$\\n\\nSince the minimum value of $\\\\cos(x-\\\\theta)$ is $-1$, the minimum value of the original expression is:\\n\\n$5(-1)+8=-5+8=3$\\n\\nTherefore, the minimum value of $3\\\\cos x + 4\\\\sin x + 8$ is $\\\\boxed{3}$.\",\"modelConfigName\":\"null\"},{\"title\":\"Response 2\",\"content\":\"A nice math question!\\n\\nTo find the minimum value of $3 \\\\cos x + 4 \\\\sin x + 8$, we can use the fact that $a\\\\cos x + b\\\\sin x = \\\\sqrt{a^2 + b^2} \\\\cos(x - \\\\alpha)$, where $\\\\alpha = \\\\tan^{-1}\\\\left(\\\\frac{b}{a}\\\\right)$.\\n\\nIn this case, $a = 3$ and $b = 4$, so $\\\\alpha = \\\\tan^{-1}\\\\left(\\\\frac{4}{3}\\\\right)$.\\n\\nSo, we have:\\n\\n$$3 \\\\cos x + 4 \\\\sin x + 8 = \\\\sqrt{3^2 + 4^2} \\\\cos(x - \\\\alpha) + 8 = 5 \\\\cos(x - \\\\alpha) + 8$$\\n\\nNow, the minimum value of $\\\\cos(x - \\\\alpha)$ is $-1$, so the minimum value of $5 \\\\cos(x - \\\\alpha) + 8$ is:\\n\\n$$5(-1) + 8 = -5 + 8 = 3$$\\n\\nTherefore, the minimum value of $3 \\\\cos x + 4 \\\\sin x + 8$ is $\\\\boxed{3}$.\\n\\nLet me know if you have any questions or need further clarification!\",\"modelConfigName\":\"null\"}]}"
113+
},
114+
"media_attributes": {
115+
"asset_type": "conversational",
116+
"mime_type": "application/vnd.labelbox.conversational",
117+
"labelable_ids": ["message-0"],
118+
"message_count": 1
119+
}
120+
}
38121
mock_requests_get.return_value.text = json.dumps(data)
39122
mock_requests_get.return_value.content = "b"
40123
export_task = ExportTask(mock_task, is_export_v2=True)
41-
assert export_task.result[0] == data
124+
assert export_task.result[0] == data

0 commit comments

Comments
 (0)