Skip to content

Commit 863ca0f

Browse files
tests for dall-e (Azure#30852)
* fix parameterize option for ALL * add dall-e tests
1 parent 1d64fa3 commit 863ca0f

File tree

7 files changed

+144
-5
lines changed

7 files changed

+144
-5
lines changed

sdk/openai/azure-openai/tests/test_chat_completions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_chat_completion_kw_input(self, azure_openai_creds, api_type):
4040
openai.ChatCompletion.create(messages=messages, model=deployment)
4141
assert "Must provide an 'engine' or 'deployment_id' parameter" in str(e.value)
4242

43-
@pytest.mark.parametrize("api_type", [ALL])
43+
@pytest.mark.parametrize("api_type", ALL)
4444
@configure
4545
def test_chat_completion(self, azure_openai_creds, api_type):
4646
messages = [

sdk/openai/azure-openai/tests/test_completions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_completion_kw_input(self, azure_openai_creds, api_type):
3333
openai.Completion.create(prompt="hello world", model=deployment)
3434
assert "Must provide an 'engine' or 'deployment_id' parameter" in str(e.value)
3535

36-
@pytest.mark.parametrize("api_type", [ALL])
36+
@pytest.mark.parametrize("api_type", ALL)
3737
@configure
3838
def test_completion(self, azure_openai_creds, api_type):
3939
kwargs = {"model": azure_openai_creds["completions_model"]} if api_type == "openai" \

sdk/openai/azure-openai/tests/test_completions_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def test_completion_kw_input(self, azure_openai_creds, api_type):
3535
assert "Must provide an 'engine' or 'deployment_id' parameter" in str(e.value)
3636

3737
@pytest.mark.asyncio
38-
@pytest.mark.parametrize("api_type", [ALL])
38+
@pytest.mark.parametrize("api_type", ALL)
3939
@configure
4040
async def test_completion(self, azure_openai_creds, api_type):
4141
kwargs = {"model": azure_openai_creds["completions_model"]} if api_type == "openai" \
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# ------------------------------------
5+
6+
import pytest
7+
import openai
8+
from devtools_testutils import AzureRecordedTestCase
9+
from conftest import configure, AZURE, OPENAI, ALL
10+
11+
12+
class TestDallE(AzureRecordedTestCase):
13+
14+
@pytest.mark.parametrize("api_type", ALL)
15+
@configure
16+
def test_image_create(self, azure_openai_creds, api_type):
17+
image = openai.Image.create(
18+
prompt="a cute baby seal"
19+
)
20+
assert image.created
21+
assert len(image.data) == 1
22+
assert image.data[0].url
23+
24+
@pytest.mark.parametrize("api_type", [AZURE, OPENAI])
25+
@configure
26+
def test_image_create_n(self, azure_openai_creds, api_type):
27+
image = openai.Image.create(
28+
prompt="a cute baby seal",
29+
n=2
30+
)
31+
assert image.created
32+
assert len(image.data) == 2
33+
for img in image.data:
34+
assert img.url
35+
36+
@pytest.mark.parametrize("api_type", [AZURE, OPENAI])
37+
@configure
38+
def test_image_create_size(self, azure_openai_creds, api_type):
39+
image = openai.Image.create(
40+
prompt="a cute baby seal",
41+
size="256x256"
42+
)
43+
assert image.created
44+
assert len(image.data) == 1
45+
assert image.data[0].url
46+
47+
@pytest.mark.parametrize("api_type", [OPENAI])
48+
@configure
49+
def test_image_create_response_format(self, azure_openai_creds, api_type):
50+
image = openai.Image.create(
51+
prompt="a cute baby seal",
52+
response_format="b64_json" # No Azure support yet
53+
)
54+
assert image.created
55+
assert len(image.data) == 1
56+
assert image.data[0].b64_json
57+
58+
@pytest.mark.parametrize("api_type", [AZURE, OPENAI])
59+
@configure
60+
def test_image_create_user(self, azure_openai_creds, api_type):
61+
image = openai.Image.create(
62+
prompt="a cute baby seal",
63+
user="krista"
64+
)
65+
assert image.created
66+
assert len(image.data) == 1
67+
assert image.data[0].url
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# ------------------------------------
2+
# Copyright (c) Microsoft Corporation.
3+
# Licensed under the MIT License.
4+
# ------------------------------------
5+
6+
import pytest
7+
import openai
8+
from devtools_testutils import AzureRecordedTestCase
9+
from conftest import configure, AZURE, OPENAI, ALL
10+
11+
12+
class TestDallEAsync(AzureRecordedTestCase):
13+
14+
@pytest.mark.asyncio
15+
@pytest.mark.parametrize("api_type", ALL)
16+
@configure
17+
async def test_image_create(self, azure_openai_creds, api_type):
18+
image = await openai.Image.acreate(
19+
prompt="a cute baby seal"
20+
)
21+
assert image.created
22+
assert len(image.data) == 1
23+
assert image.data[0].url
24+
25+
@pytest.mark.asyncio
26+
@pytest.mark.parametrize("api_type", [AZURE, OPENAI])
27+
@configure
28+
async def test_image_create_n(self, azure_openai_creds, api_type):
29+
image = await openai.Image.acreate(
30+
prompt="a cute baby seal",
31+
n=2
32+
)
33+
assert image.created
34+
assert len(image.data) == 2
35+
for img in image.data:
36+
assert img.url
37+
38+
@pytest.mark.asyncio
39+
@pytest.mark.parametrize("api_type", [AZURE, OPENAI])
40+
@configure
41+
async def test_image_create_size(self, azure_openai_creds, api_type):
42+
image = await openai.Image.acreate(
43+
prompt="a cute baby seal",
44+
size="256x256"
45+
)
46+
assert image.created
47+
assert len(image.data) == 1
48+
assert image.data[0].url
49+
50+
@pytest.mark.asyncio
51+
@pytest.mark.parametrize("api_type", [OPENAI])
52+
@configure
53+
async def test_image_create_response_format(self, azure_openai_creds, api_type):
54+
image = await openai.Image.acreate(
55+
prompt="a cute baby seal",
56+
response_format="b64_json" # No Azure support yet
57+
)
58+
assert image.created
59+
assert len(image.data) == 1
60+
assert image.data[0].b64_json
61+
62+
@pytest.mark.asyncio
63+
@pytest.mark.parametrize("api_type", [AZURE, OPENAI])
64+
@configure
65+
async def test_image_create_user(self, azure_openai_creds, api_type):
66+
image = await openai.Image.acreate(
67+
prompt="a cute baby seal",
68+
user="krista"
69+
)
70+
assert image.created
71+
assert len(image.data) == 1
72+
assert image.data[0].url

sdk/openai/azure-openai/tests/test_embeddings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_embedding_kw_input(self, azure_openai_creds, api_type):
3232
openai.Embedding.create(input="hello world", model=deployment)
3333
assert "Must provide an 'engine' or 'deployment_id' parameter" in str(e.value)
3434

35-
@pytest.mark.parametrize("api_type", [ALL])
35+
@pytest.mark.parametrize("api_type", ALL)
3636
@configure
3737
def test_embedding(self, azure_openai_creds, api_type):
3838
kwargs = {"model": azure_openai_creds["embeddings_model"]} if api_type == "openai" \

sdk/openai/azure-openai/tests/test_embeddings_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def test_embedding_kw_input(self, azure_openai_creds, api_type):
3535
assert "Must provide an 'engine' or 'deployment_id' parameter" in str(e.value)
3636

3737
@pytest.mark.asyncio
38-
@pytest.mark.parametrize("api_type", [ALL])
38+
@pytest.mark.parametrize("api_type", ALL)
3939
@configure
4040
async def test_embedding(self, azure_openai_creds, api_type):
4141
kwargs = {"model": azure_openai_creds["embeddings_model"]} if api_type == "openai" \

0 commit comments

Comments
 (0)