Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions tests/test_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

jigsaw = jigsawstack.JigsawStack(api_key=os.getenv("JIGSAWSTACK_API_KEY"))
async_jigsaw = jigsawstack.AsyncJigsawStack(api_key=os.getenv("JIGSAWSTACK_API_KEY"))
jigsaw = jigsawstack.JigsawStack(
api_key=os.getenv("JIGSAWSTACK_API_KEY"),
base_url=os.getenv("JIGSAWSTACK_BASE_URL") + "/api"
if os.getenv("JIGSAWSTACK_BASE_URL")
else "https://api.jigsawstack.com",
headers={"x-jigsaw-skip-cache": "true"},
)
async_jigsaw = jigsawstack.AsyncJigsawStack(
api_key=os.getenv("JIGSAWSTACK_API_KEY"),
base_url=os.getenv("JIGSAWSTACK_BASE_URL") + "/api"
if os.getenv("JIGSAWSTACK_BASE_URL")
else "https://api.jigsawstack.com",
headers={"x-jigsaw-skip-cache": "true"},
)

AUDIO_URL = AUDIO_URL_LONG = "https://jigsawstack.com/preview/stt-example.wav"

Expand Down Expand Up @@ -119,20 +131,26 @@
class TestAudioSync:
"""Test synchronous audio speech-to-text methods"""

@pytest.mark.parametrize("test_case", TEST_CASES, ids=[tc["name"] for tc in TEST_CASES])
@pytest.mark.parametrize(
"test_case", TEST_CASES, ids=[tc["name"] for tc in TEST_CASES]
)
def test_speech_to_text(self, test_case):
"""Test synchronous speech-to-text with various inputs"""
try:
if test_case.get("blob"):
# Download audio content
blob_content = requests.get(test_case["blob"]).content
result = jigsaw.audio.speech_to_text(blob_content, test_case.get("options", {}))
result = jigsaw.audio.speech_to_text(
blob_content, test_case.get("options", {})
)
else:
# Use params directly
result = jigsaw.audio.speech_to_text(test_case["params"])
# Verify response structure
assert result["success"]
assert result.get("text", None) is not None and isinstance(result["text"], str)
assert result.get("text", None) is not None and isinstance(
result["text"], str
)

# Check for chunks
if result.get("chunks", None):
Expand All @@ -154,7 +172,9 @@ def test_speech_to_text_webhook(self, test_case):
if test_case.get("blob"):
# Download audio content
blob_content = requests.get(test_case["blob"]).content
result = jigsaw.audio.speech_to_text(blob_content, test_case.get("options", {}))
result = jigsaw.audio.speech_to_text(
blob_content, test_case.get("options", {})
)
else:
# Use params directly
result = jigsaw.audio.speech_to_text(test_case["params"])
Expand All @@ -169,7 +189,9 @@ def test_speech_to_text_webhook(self, test_case):
class TestAudioAsync:
"""Test asynchronous audio speech-to-text methods"""

@pytest.mark.parametrize("test_case", TEST_CASES, ids=[tc["name"] for tc in TEST_CASES])
@pytest.mark.parametrize(
"test_case", TEST_CASES, ids=[tc["name"] for tc in TEST_CASES]
)
@pytest.mark.asyncio
async def test_speech_to_text_async(self, test_case):
"""Test asynchronous speech-to-text with various inputs"""
Expand All @@ -186,7 +208,9 @@ async def test_speech_to_text_async(self, test_case):

# Verify response structure
assert result["success"]
assert result.get("text", None) is not None and isinstance(result["text"], str)
assert result.get("text", None) is not None and isinstance(
result["text"], str
)

# Check for chunks
if result.get("chunks", None):
Expand All @@ -196,7 +220,9 @@ async def test_speech_to_text_async(self, test_case):
if result.get("speakers", None):
assert isinstance(result["speakers"], list)
except JigsawStackError as e:
pytest.fail(f"Unexpected JigsawStackError in async {test_case['name']}: {e}")
pytest.fail(
f"Unexpected JigsawStackError in async {test_case['name']}: {e}"
)

@pytest.mark.parametrize(
"test_case", WEBHOOK_TEST_CASES, ids=[tc["name"] for tc in WEBHOOK_TEST_CASES]
Expand All @@ -222,4 +248,6 @@ async def test_speech_to_text_webhook_async(self, test_case):

except JigsawStackError as e:
# Webhook URLs might fail if invalid
print(f"Expected possible error for async webhook test {test_case['name']}: {e}")
print(
f"Expected possible error for async webhook test {test_case['name']}: {e}"
)
16 changes: 14 additions & 2 deletions tests/test_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

jigsaw = jigsawstack.JigsawStack(api_key=os.getenv("JIGSAWSTACK_API_KEY"))
async_jigsaw = jigsawstack.AsyncJigsawStack(api_key=os.getenv("JIGSAWSTACK_API_KEY"))
jigsaw = jigsawstack.JigsawStack(
api_key=os.getenv("JIGSAWSTACK_API_KEY"),
base_url=os.getenv("JIGSAWSTACK_BASE_URL") + "/api"
if os.getenv("JIGSAWSTACK_BASE_URL")
else "https://api.jigsawstack.com",
headers={"x-jigsaw-skip-cache": "true"},
)
async_jigsaw = jigsawstack.AsyncJigsawStack(
api_key=os.getenv("JIGSAWSTACK_API_KEY"),
base_url=os.getenv("JIGSAWSTACK_BASE_URL") + "/api"
if os.getenv("JIGSAWSTACK_BASE_URL")
else "https://api.jigsawstack.com",
headers={"x-jigsaw-skip-cache": "true"},
)

TEST_CASES = [
{
Expand Down
16 changes: 14 additions & 2 deletions tests/test_deep_research.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

jigsaw = jigsawstack.JigsawStack(api_key=os.getenv("JIGSAWSTACK_API_KEY"))
async_jigsaw = jigsawstack.AsyncJigsawStack(api_key=os.getenv("JIGSAWSTACK_API_KEY"))
jigsaw = jigsawstack.JigsawStack(
api_key=os.getenv("JIGSAWSTACK_API_KEY"),
base_url=os.getenv("JIGSAWSTACK_BASE_URL") + "/api"
if os.getenv("JIGSAWSTACK_BASE_URL")
else "https://api.jigsawstack.com",
headers={"x-jigsaw-skip-cache": "true"},
)
async_jigsaw = jigsawstack.AsyncJigsawStack(
api_key=os.getenv("JIGSAWSTACK_API_KEY"),
base_url=os.getenv("JIGSAWSTACK_BASE_URL") + "/api"
if os.getenv("JIGSAWSTACK_BASE_URL")
else "https://api.jigsawstack.com",
headers={"x-jigsaw-skip-cache": "true"},
)

URL = "https://jigsawstack.com"

Expand Down
24 changes: 18 additions & 6 deletions tests/test_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,27 @@
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

jigsaw = jigsawstack.JigsawStack(api_key=os.getenv("JIGSAWSTACK_API_KEY"))
async_jigsaw = jigsawstack.AsyncJigsawStack(api_key=os.getenv("JIGSAWSTACK_API_KEY"))

SAMPLE_TEXT = (
"The quick brown fox jumps over the lazy dog. This is a sample text for embedding generation."
jigsaw = jigsawstack.JigsawStack(
api_key=os.getenv("JIGSAWSTACK_API_KEY"),
base_url=os.getenv("JIGSAWSTACK_BASE_URL") + "/api"
if os.getenv("JIGSAWSTACK_BASE_URL")
else "https://api.jigsawstack.com",
headers={"x-jigsaw-skip-cache": "true"},
)
async_jigsaw = jigsawstack.AsyncJigsawStack(
api_key=os.getenv("JIGSAWSTACK_API_KEY"),
base_url=os.getenv("JIGSAWSTACK_BASE_URL") + "/api"
if os.getenv("JIGSAWSTACK_BASE_URL")
else "https://api.jigsawstack.com",
headers={"x-jigsaw-skip-cache": "true"},
)

SAMPLE_TEXT = "The quick brown fox jumps over the lazy dog. This is a sample text for embedding generation."
SAMPLE_IMAGE_URL = "https://images.unsplash.com/photo-1542931287-023b922fa89b?q=80&w=2574&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"
SAMPLE_AUDIO_URL = "https://jigsawstack.com/preview/stt-example.wav"
SAMPLE_PDF_URL = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
SAMPLE_PDF_URL = (
"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
)

# Test cases for Embedding V1
EMBEDDING_V1_TEST_CASES = [
Expand Down
24 changes: 20 additions & 4 deletions tests/test_file_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,20 @@
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

jigsaw = jigsawstack.JigsawStack(api_key=os.getenv("JIGSAWSTACK_API_KEY"))
async_jigsaw = jigsawstack.AsyncJigsawStack(api_key=os.getenv("JIGSAWSTACK_API_KEY"))
jigsaw = jigsawstack.JigsawStack(
api_key=os.getenv("JIGSAWSTACK_API_KEY"),
base_url=os.getenv("JIGSAWSTACK_BASE_URL") + "/api"
if os.getenv("JIGSAWSTACK_BASE_URL")
else "https://api.jigsawstack.com",
headers={"x-jigsaw-skip-cache": "true"},
)
async_jigsaw = jigsawstack.AsyncJigsawStack(
api_key=os.getenv("JIGSAWSTACK_API_KEY"),
base_url=os.getenv("JIGSAWSTACK_BASE_URL") + "/api"
if os.getenv("JIGSAWSTACK_BASE_URL")
else "https://api.jigsawstack.com",
headers={"x-jigsaw-skip-cache": "true"},
)

TEXT_FILE_CONTENT = b"This is a test file content for JigsawStack storage"
JSON_FILE_CONTENT = b'{"test": "data", "key": "value"}'
Expand Down Expand Up @@ -118,7 +130,9 @@ class TestFileStoreAsync:
async def test_file_upload_async(self, test_case):
"""Test asynchronous file upload with various options"""
try:
result = await async_jigsaw.store.upload(test_case["file"], test_case["options"])
result = await async_jigsaw.store.upload(
test_case["file"], test_case["options"]
)

print(f"Async upload test {test_case['name']}: {result}")
assert result.get("key") is not None
Expand All @@ -133,7 +147,9 @@ async def test_file_upload_async(self, test_case):
self.uploaded_keys.append(result["key"])

except JigsawStackError as e:
pytest.fail(f"Unexpected JigsawStackError in async {test_case['name']}: {e}")
pytest.fail(
f"Unexpected JigsawStackError in async {test_case['name']}: {e}"
)

@pytest.mark.asyncio
async def test_file_get_async(self):
Expand Down
40 changes: 32 additions & 8 deletions tests/test_image_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

jigsaw = jigsawstack.JigsawStack(api_key=os.getenv("JIGSAWSTACK_API_KEY"))
async_jigsaw = jigsawstack.AsyncJigsawStack(api_key=os.getenv("JIGSAWSTACK_API_KEY"))
jigsaw = jigsawstack.JigsawStack(
api_key=os.getenv("JIGSAWSTACK_API_KEY"),
base_url=os.getenv("JIGSAWSTACK_BASE_URL") + "/api"
if os.getenv("JIGSAWSTACK_BASE_URL")
else "https://api.jigsawstack.com",
headers={"x-jigsaw-skip-cache": "true"},
)
async_jigsaw = jigsawstack.AsyncJigsawStack(
api_key=os.getenv("JIGSAWSTACK_API_KEY"),
base_url=os.getenv("JIGSAWSTACK_BASE_URL") + "/api"
if os.getenv("JIGSAWSTACK_BASE_URL")
else "https://api.jigsawstack.com",
headers={"x-jigsaw-skip-cache": "true"},
)

IMAGE_URL = "https://images.unsplash.com/photo-1494588024300-e9df7ff98d78?q=80&w=1284&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"
FILE_STORE_KEY = jigsaw.store.upload(
Expand Down Expand Up @@ -111,7 +123,9 @@
class TestImageGenerationSync:
"""Test synchronous image generation methods"""

@pytest.mark.parametrize("test_case", TEST_CASES, ids=[tc["name"] for tc in TEST_CASES])
@pytest.mark.parametrize(
"test_case", TEST_CASES, ids=[tc["name"] for tc in TEST_CASES]
)
def test_image_generation(self, test_case):
"""Test synchronous image generation with various parameters"""
try:
Expand Down Expand Up @@ -160,15 +174,19 @@ def test_image_to_image_generation(self, test_case):
elif type(result) is bytes:
assert isinstance(result, bytes)
else:
pytest.fail(f"Unexpected result type in {test_case['name']}: {type(result)}")
pytest.fail(
f"Unexpected result type in {test_case['name']}: {type(result)}"
)
except JigsawStackError as e:
pytest.fail(f"Unexpected JigsawStackError in {test_case['name']}: {e}")


class TestImageGenerationAsync:
"""Test asynchronous image generation methods"""

@pytest.mark.parametrize("test_case", TEST_CASES, ids=[tc["name"] for tc in TEST_CASES])
@pytest.mark.parametrize(
"test_case", TEST_CASES, ids=[tc["name"] for tc in TEST_CASES]
)
@pytest.mark.asyncio
async def test_image_generation_async(self, test_case):
"""Test asynchronous image generation with various parameters"""
Expand All @@ -195,7 +213,9 @@ async def test_image_generation_async(self, test_case):
assert isinstance(result, bytes)

except JigsawStackError as e:
pytest.fail(f"Unexpected JigsawStackError in async {test_case['name']}: {e}")
pytest.fail(
f"Unexpected JigsawStackError in async {test_case['name']}: {e}"
)

@pytest.mark.parametrize(
"test_case",
Expand All @@ -215,7 +235,11 @@ async def test_image_to_image_generation_async(self, test_case):
elif type(result) is bytes:
assert isinstance(result, bytes)
else:
pytest.fail(f"Unexpected result type in {test_case['name']}: {type(result)}")
pytest.fail(
f"Unexpected result type in {test_case['name']}: {type(result)}"
)

except JigsawStackError as e:
pytest.fail(f"Unexpected JigsawStackError in async {test_case['name']}: {e}")
pytest.fail(
f"Unexpected JigsawStackError in async {test_case['name']}: {e}"
)
24 changes: 18 additions & 6 deletions tests/test_object_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,23 @@
logger = logging.getLogger(__name__)


jigsaw = jigsawstack.JigsawStack(api_key=os.getenv("JIGSAWSTACK_API_KEY"))
async_jigsaw = jigsawstack.AsyncJigsawStack(api_key=os.getenv("JIGSAWSTACK_API_KEY"))

IMAGE_URL = (
"https://rogilvkqloanxtvjfrkm.supabase.co/storage/v1/object/public/demo/Collabo%201080x842.jpg"
jigsaw = jigsawstack.JigsawStack(
api_key=os.getenv("JIGSAWSTACK_API_KEY"),
base_url=os.getenv("JIGSAWSTACK_BASE_URL") + "/api"
if os.getenv("JIGSAWSTACK_BASE_URL")
else "https://api.jigsawstack.com",
headers={"x-jigsaw-skip-cache": "true"},
)
async_jigsaw = jigsawstack.AsyncJigsawStack(
api_key=os.getenv("JIGSAWSTACK_API_KEY"),
base_url=os.getenv("JIGSAWSTACK_BASE_URL") + "/api"
if os.getenv("JIGSAWSTACK_BASE_URL")
else "https://api.jigsawstack.com",
headers={"x-jigsaw-skip-cache": "true"},
)

IMAGE_URL = "https://rogilvkqloanxtvjfrkm.supabase.co/storage/v1/object/public/demo/Collabo%201080x842.jpg"

TEST_CASES = [
{
"name": "with_url_only",
Expand Down Expand Up @@ -104,7 +114,9 @@ def test_object_detection(self, test_case):
if test_case.get("blob"):
# Download blob content
blob_content = requests.get(test_case["blob"]).content
result = jigsaw.vision.object_detection(blob_content, test_case.get("options", {}))
result = jigsaw.vision.object_detection(
blob_content, test_case.get("options", {})
)
else:
# Use params directly
result = jigsaw.vision.object_detection(test_case["params"])
Expand Down
24 changes: 20 additions & 4 deletions tests/test_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,20 @@
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

jigsaw = jigsawstack.JigsawStack(api_key=os.getenv("JIGSAWSTACK_API_KEY"))
async_jigsaw = jigsawstack.AsyncJigsawStack(api_key=os.getenv("JIGSAWSTACK_API_KEY"))
jigsaw = jigsawstack.JigsawStack(
api_key=os.getenv("JIGSAWSTACK_API_KEY"),
base_url=os.getenv("JIGSAWSTACK_BASE_URL") + "/api"
if os.getenv("JIGSAWSTACK_BASE_URL")
else "https://api.jigsawstack.com",
headers={"x-jigsaw-skip-cache": "true"},
)
async_jigsaw = jigsawstack.AsyncJigsawStack(
api_key=os.getenv("JIGSAWSTACK_API_KEY"),
base_url=os.getenv("JIGSAWSTACK_BASE_URL") + "/api"
if os.getenv("JIGSAWSTACK_BASE_URL")
else "https://api.jigsawstack.com",
headers={"x-jigsaw-skip-cache": "true"},
)


def generate_dates(start_date, num_days):
Expand Down Expand Up @@ -47,7 +59,9 @@ def generate_dates(start_date, num_days):
{
"name": "seasonal_pattern",
"params": {
"dataset": [{"date": dates[i], "value": 100 + (50 * (i % 7))} for i in range(21)],
"dataset": [
{"date": dates[i], "value": 100 + (50 * (i % 7))} for i in range(21)
],
"steps": 7,
},
},
Expand All @@ -61,7 +75,9 @@ def generate_dates(start_date, num_days):
{
"name": "large_dataset_prediction",
"params": {
"dataset": [{"date": dates[i], "value": 1000 + (i * 20)} for i in range(30)],
"dataset": [
{"date": dates[i], "value": 1000 + (i * 20)} for i in range(30)
],
"steps": 10,
},
},
Expand Down
Loading
Loading