Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5205cc1

Browse files
committed
updated test
1 parent 17424fc commit 5205cc1

File tree

2 files changed

+84
-51
lines changed

2 files changed

+84
-51
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ test.py
2121
test_web.py
2222

2323
.eggs/
24-
.conda/
24+
.conda/
25+
26+
main.py
27+
.python-version
28+
pyproject.toml
29+
uv.lock

tests/test_classification.py

Lines changed: 78 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from unittest.mock import MagicMock
2-
import unittest
31
from jigsawstack.exceptions import JigsawStackError
42
from jigsawstack import JigsawStack
53

@@ -10,53 +8,83 @@
108
client = JigsawStack()
119

1210

13-
@pytest.mark.skip(reason="Skipping TestWebAPI class for now")
14-
class TestClassification(unittest.TestCase):
15-
def test_classification_text_success_response(self) -> None:
16-
params = {
17-
"dataset": [
18-
{"type": "text", "value": "I love programming"},
19-
{"type": "text", "value": "I love reading books"},
20-
{"type": "text", "value": "I love watching movies"},
21-
{"type": "text", "value": "I love playing games"},
22-
],
23-
"labels": [
24-
{"type": "text", "value": "programming"},
25-
{"type": "text", "value": "reading"},
26-
{"type": "text", "value": "watching"},
27-
{"type": "text", "value": "playing"},
28-
],
29-
}
30-
try:
31-
result = client.classification.text(params)
32-
assert result["success"] == True
33-
except JigsawStackError as e:
34-
assert e.message == "Failed to parse API response. Please try again."
11+
@pytest.mark.parametrize("dataset,labels", [
12+
(
13+
[
14+
{"type": "text", "value": "I love programming"},
15+
{"type": "text", "value": "I love reading books"},
16+
{"type": "text", "value": "I love watching movies"},
17+
{"type": "text", "value": "I love playing games"},
18+
],
19+
[
20+
{"type": "text", "value": "programming"},
21+
{"type": "text", "value": "reading"},
22+
{"type": "text", "value": "watching"},
23+
{"type": "text", "value": "playing"},
24+
]
25+
),
26+
(
27+
[
28+
{"type": "text", "value": "This is awesome!"},
29+
{"type": "text", "value": "I hate this product"},
30+
{"type": "text", "value": "It's okay, nothing special"},
31+
],
32+
[
33+
{"type": "text", "value": "positive"},
34+
{"type": "text", "value": "negative"},
35+
{"type": "text", "value": "neutral"},
36+
]
37+
),
38+
(
39+
[
40+
{"type": "text", "value": "The weather is sunny today"},
41+
{"type": "text", "value": "It's raining heavily outside"},
42+
{"type": "text", "value": "Snow is falling gently"},
43+
],
44+
[
45+
{"type": "text", "value": "sunny"},
46+
{"type": "text", "value": "rainy"},
47+
{"type": "text", "value": "snowy"},
48+
]
49+
),
50+
])
51+
def test_classification_text_success_response(dataset, labels) -> None:
52+
params = {
53+
"dataset": dataset,
54+
"labels": labels,
55+
}
56+
try:
57+
result = client.classification.text(params)
58+
print(result)
59+
assert result["success"] == True
60+
except JigsawStackError as e:
61+
print(str(e))
62+
assert e.message == "Failed to parse API response. Please try again."
3563

36-
def test_classification_image_success_response(self) -> None:
37-
params = {
38-
"dataset": [
39-
{"type": "image", "value": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ4aBhloyMLx5qA6G6wSEi0s9AvDu1r7utrbQ&s"},
40-
{"type": "image", "value": "https://cdn.britannica.com/79/232779-050-6B0411D7/German-Shepherd-dog-Alsatian.jpg"},
41-
],
42-
"labels": [
43-
{"type": "text", "value": "Cat"},
44-
{"type": "text", "value": "Dog"},
45-
],
46-
}
47-
try:
48-
result = client.classification.image(params)
49-
assert result["success"] == True
50-
except JigsawStackError as e:
51-
assert e.message == "Failed to parse API response. Please try again."
5264

53-
def test_dns_success_response(self) -> None:
54-
55-
params = {
56-
"url": "https://supabase.com/pricing",
57-
}
58-
try:
59-
result = client.web.dns(params)
60-
assert result["success"] == True
61-
except JigsawStackError as e:
62-
assert e.message == "Failed to parse API response. Please try again."
65+
@pytest.mark.parametrize("dataset,labels", [
66+
(
67+
[
68+
{"type": "image", "value": "https://as2.ftcdn.net/v2/jpg/02/24/11/57/1000_F_224115780_2ssvcCoTfQrx68Qsl5NxtVIDFWKtAgq2.jpg"},
69+
{"type": "image", "value": "https://t3.ftcdn.net/jpg/02/95/44/22/240_F_295442295_OXsXOmLmqBUfZreTnGo9PREuAPSLQhff.jpg"},
70+
{"type": "image", "value": "https://as1.ftcdn.net/v2/jpg/05/54/94/46/1000_F_554944613_okdr3fBwcE9kTOgbLp4BrtVi8zcKFWdP.jpg"},
71+
],
72+
[
73+
{"type": "text", "value": "banana"},
74+
{"type": "image", "value": "https://upload.wikimedia.org/wikipedia/commons/8/8a/Banana-Single.jpg"},
75+
{"type": "text", "value": "kisses"},
76+
]
77+
),
78+
])
79+
def test_classification_image_success_response(dataset, labels) -> None:
80+
params = {
81+
"dataset": dataset,
82+
"labels": labels,
83+
}
84+
try:
85+
result = client.classification.image(params)
86+
print(result)
87+
assert result["success"] == True
88+
except JigsawStackError as e:
89+
print(str(e))
90+
assert e.message == "Failed to parse API response. Please try again."

0 commit comments

Comments
 (0)