Skip to content

Commit 00cee0e

Browse files
committed
Addressed review comments
1 parent 3bd1b5c commit 00cee0e

8 files changed

+242
-125
lines changed

tests/gsd/test_2000_synthetic_data.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313

1414
import pytest
1515
import select_ai
16-
from select_ai import Profile, ProfileAttributes, SyntheticDataAttributes, SyntheticDataParams
16+
from select_ai import (
17+
Profile,
18+
ProfileAttributes,
19+
SyntheticDataAttributes,
20+
SyntheticDataParams,
21+
)
1722

1823
PROFILE_PREFIX = f"PYSAI_2000_{uuid.uuid4().hex.upper()}"
1924

@@ -130,4 +135,3 @@ def test_2008_generate_with_none_attributes(synthetic_profile):
130135
"""Passing None as attributes raises error"""
131136
with pytest.raises(Exception):
132137
synthetic_profile.generate_synthetic_data(None)
133-

tests/gsd/test_2100_synthetic_data_async.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313

1414
import pytest
1515
import select_ai
16-
from select_ai import AsyncProfile, ProfileAttributes, SyntheticDataAttributes, SyntheticDataParams
16+
from select_ai import (
17+
AsyncProfile,
18+
ProfileAttributes,
19+
SyntheticDataAttributes,
20+
SyntheticDataParams,
21+
)
1722

1823
PROFILE_PREFIX = f"PYSAI_2100_{uuid.uuid4().hex.upper()}"
1924

@@ -35,7 +40,9 @@ def async_synthetic_provider(oci_compartment_id):
3540

3641

3742
@pytest.fixture(scope="module")
38-
def async_synthetic_profile_attributes(oci_credential, async_synthetic_provider):
43+
def async_synthetic_profile_attributes(
44+
oci_credential, async_synthetic_provider
45+
):
3946
return ProfileAttributes(
4047
credential_name=oci_credential["credential_name"],
4148
object_list=[

tests/profiles/test_1400_conversation.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from oracledb import DatabaseError
1717
from select_ai import Conversation, ConversationAttributes
1818

19-
2019
CONVERSATION_PREFIX = f"PYSAI_1400_{uuid.uuid4().hex.upper()}"
2120

2221

@@ -34,10 +33,7 @@ def _create(**kwargs):
3433
yield _create
3534

3635
for conv in created:
37-
try:
38-
conv.delete(force=True)
39-
except Exception:
40-
pass
36+
conv.delete(force=True)
4137

4238

4339
@pytest.fixture
@@ -204,4 +200,4 @@ def test_1419_create_with_description_none(conversation_factory):
204200
)
205201
attrs = conv.get_attributes()
206202
assert attrs.title == f"{CONVERSATION_PREFIX}_NONE_DESC"
207-
assert attrs.description is None
203+
assert attrs.description is None

tests/profiles/test_1500_conversation_async.py

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from oracledb import DatabaseError
1717
from select_ai import AsyncConversation, ConversationAttributes
1818

19-
2019
CONVERSATION_PREFIX = f"PYSAI_1500_{uuid.uuid4().hex.upper()}"
2120

2221

@@ -34,15 +33,14 @@ async def _create(**kwargs):
3433
yield _create
3534

3635
for conversation in created:
37-
try:
38-
await conversation.delete(force=True)
39-
except Exception:
40-
pass
36+
await conversation.delete(force=True)
4137

4238

4339
@pytest.fixture
4440
async def async_conversation(async_conversation_factory):
45-
return await async_conversation_factory(title=f"{CONVERSATION_PREFIX}_ACTIVE")
41+
return await async_conversation_factory(
42+
title=f"{CONVERSATION_PREFIX}_ACTIVE"
43+
)
4644

4745

4846
@pytest.mark.anyio
@@ -60,7 +58,9 @@ async def test_1501_create_with_description(async_conversation_factory):
6058
)
6159
attributes = await conversation.get_attributes()
6260
assert attributes.title == f"{CONVERSATION_PREFIX}_HISTORY"
63-
assert attributes.description == "LLM's understanding of history of science"
61+
assert (
62+
attributes.description == "LLM's understanding of history of science"
63+
)
6464

6565

6666
@pytest.mark.anyio
@@ -110,7 +110,9 @@ async def test_1506_set_attributes_with_none(async_conversation):
110110
@pytest.mark.anyio
111111
async def test_1507_delete_conversation(async_conversation_factory):
112112
"""Delete async conversation and validate removal"""
113-
conversation = await async_conversation_factory(title=f"{CONVERSATION_PREFIX}_DELETE")
113+
conversation = await async_conversation_factory(
114+
title=f"{CONVERSATION_PREFIX}_DELETE"
115+
)
114116
await conversation.delete(force=True)
115117
with pytest.raises(select_ai.errors.ConversationNotFoundError):
116118
await conversation.get_attributes()
@@ -119,7 +121,9 @@ async def test_1507_delete_conversation(async_conversation_factory):
119121
@pytest.mark.anyio
120122
async def test_1508_delete_twice(async_conversation_factory):
121123
"""Deleting an already deleted async conversation raises DatabaseError"""
122-
conversation = await async_conversation_factory(title=f"{CONVERSATION_PREFIX}_DELETE_TWICE")
124+
conversation = await async_conversation_factory(
125+
title=f"{CONVERSATION_PREFIX}_DELETE_TWICE"
126+
)
123127
await conversation.delete(force=True)
124128
with pytest.raises(DatabaseError):
125129
await conversation.delete()
@@ -133,7 +137,9 @@ async def test_1509_list_contains_created_conversation(async_conversation):
133137

134138

135139
@pytest.mark.anyio
136-
async def test_1510_multiple_conversations_have_unique_ids(async_conversation_factory):
140+
async def test_1510_multiple_conversations_have_unique_ids(
141+
async_conversation_factory,
142+
):
137143
"""Multiple async conversations produce unique identifiers"""
138144
titles = [
139145
f"{CONVERSATION_PREFIX}_AI",
@@ -165,7 +171,9 @@ async def test_1512_set_attributes_with_invalid_id():
165171
"""Updating async conversation with invalid id raises DatabaseError"""
166172
conversation = AsyncConversation(conversation_id="fake_id")
167173
with pytest.raises(DatabaseError):
168-
await conversation.set_attributes(ConversationAttributes(title="Invalid"))
174+
await conversation.set_attributes(
175+
ConversationAttributes(title="Invalid")
176+
)
169177

170178

171179
@pytest.mark.anyio
@@ -185,9 +193,13 @@ async def test_1514_get_attributes_with_invalid_id():
185193

186194

187195
@pytest.mark.anyio
188-
async def test_1515_get_attributes_for_deleted_conversation(async_conversation_factory):
196+
async def test_1515_get_attributes_for_deleted_conversation(
197+
async_conversation_factory,
198+
):
189199
"""Fetching attributes after deletion raises ConversationNotFound"""
190-
conversation = await async_conversation_factory(title=f"{CONVERSATION_PREFIX}_TO_DELETE")
200+
conversation = await async_conversation_factory(
201+
title=f"{CONVERSATION_PREFIX}_TO_DELETE"
202+
)
191203
await conversation.delete(force=True)
192204
with pytest.raises(select_ai.errors.ConversationNotFoundError):
193205
await conversation.get_attributes()
@@ -196,7 +208,9 @@ async def test_1515_get_attributes_for_deleted_conversation(async_conversation_f
196208
@pytest.mark.anyio
197209
async def test_1516_list_contains_new_conversation(async_conversation_factory):
198210
"""List reflects newly created async conversation"""
199-
conversation = await async_conversation_factory(title=f"{CONVERSATION_PREFIX}_LIST")
211+
conversation = await async_conversation_factory(
212+
title=f"{CONVERSATION_PREFIX}_LIST"
213+
)
200214
listed = [item async for item in AsyncConversation.list()]
201215
assert any(
202216
item.conversation_id == conversation.conversation_id for item in listed
@@ -211,9 +225,13 @@ async def test_1517_list_returns_async_conversation_instances():
211225

212226

213227
@pytest.mark.anyio
214-
async def test_1518_get_attributes_without_description(async_conversation_factory):
228+
async def test_1518_get_attributes_without_description(
229+
async_conversation_factory,
230+
):
215231
"""Async conversation created without description has None description"""
216-
conversation = await async_conversation_factory(title=f"{CONVERSATION_PREFIX}_NO_DESC")
232+
conversation = await async_conversation_factory(
233+
title=f"{CONVERSATION_PREFIX}_NO_DESC"
234+
)
217235
attributes = await conversation.get_attributes()
218236
assert attributes.title == f"{CONVERSATION_PREFIX}_NO_DESC"
219237
assert attributes.description is None
@@ -228,4 +246,4 @@ async def test_1519_create_with_description_none(async_conversation_factory):
228246
)
229247
attributes = await conversation.get_attributes()
230248
assert attributes.title == f"{CONVERSATION_PREFIX}_NONE_DESC"
231-
assert attributes.description is None
249+
assert attributes.description is None

tests/profiles/test_1600_generate.py

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@
99
1600 - Profile generate API tests
1010
"""
1111

12+
import json
1213
import uuid
1314

1415
import oracledb
1516
import pandas as pd
1617
import pytest
1718
import select_ai
18-
from select_ai import Conversation, ConversationAttributes, Profile, ProfileAttributes
19+
from select_ai import (
20+
Conversation,
21+
ConversationAttributes,
22+
Profile,
23+
ProfileAttributes,
24+
)
1925
from select_ai.profile import Action
2026

21-
2227
PROFILE_PREFIX = f"PYSAI_1600_{uuid.uuid4().hex.upper()}"
2328

2429
PROMPTS = [
@@ -37,12 +42,12 @@ def generate_provider(oci_compartment_id):
3742

3843

3944
@pytest.fixture(scope="module")
40-
def generate_profile_attributes(oci_credential, generate_provider):
45+
def generate_profile_attributes(test_env, oci_credential, generate_provider):
4146
return ProfileAttributes(
4247
credential_name=oci_credential["credential_name"],
4348
object_list=[
44-
{"owner": "PYTHONUSER", "name": "people"},
45-
{"owner": "PYTHONUSER", "name": "gymnast"},
49+
{"owner": test_env.test_user, "name": "people"},
50+
{"owner": test_env.test_user, "name": "gymnast"},
4651
],
4752
provider=generate_provider,
4853
)
@@ -61,14 +66,11 @@ def generate_profile(generate_profile_attributes):
6166
attribute_value="meta.llama-3.1-405b-instruct",
6267
)
6368
yield profile
64-
try:
65-
profile.delete(force=True)
66-
except Exception:
67-
pass
69+
profile.delete(force=True)
6870

6971

7072
@pytest.fixture
71-
def negative_profile(oci_credential, generate_provider):
73+
def negative_profile(test_env, oci_credential, generate_provider):
7274
profile_name = f"{PROFILE_PREFIX}_NEG_{uuid.uuid4().hex.upper()}"
7375
attributes = ProfileAttributes(
7476
credential_name=oci_credential["credential_name"],
@@ -82,23 +84,31 @@ def negative_profile(oci_credential, generate_provider):
8284
)
8385
profile.set_attribute(
8486
attribute_name="object_list",
85-
attribute_value='[{"owner": "PYTHONUSER", "name": "people"},'
86-
'{"owner": "PYTHONUSER", "name": "gymnast"}]',
87+
attribute_value=json.dumps(
88+
[
89+
{"owner": test_env.test_user, "name": "people"},
90+
{"owner": test_env.test_user, "name": "gymnast"},
91+
]
92+
),
8793
)
8894
profile.set_attribute(
8995
attribute_name="model",
9096
attribute_value="meta.llama-3.1-405b-instruct",
9197
)
9298
yield profile
93-
try:
94-
profile.delete(force=True)
95-
except Exception:
96-
pass
99+
profile.delete(force=True)
97100

98101

99102
def test_1600_action_enum_members():
100103
"""Validate Action enum exposes expected members"""
101-
for member in ["RUNSQL", "SHOWSQL", "EXPLAINSQL", "NARRATE", "CHAT", "SHOWPROMPT"]:
104+
for member in [
105+
"RUNSQL",
106+
"SHOWSQL",
107+
"EXPLAINSQL",
108+
"NARRATE",
109+
"CHAT",
110+
"SHOWPROMPT",
111+
]:
102112
assert hasattr(Action, member)
103113

104114

@@ -167,7 +177,9 @@ def test_1608_narrate(generate_profile):
167177
def test_1609_chat_session(generate_profile):
168178
"""chat_session provides a session context"""
169179
conversation = Conversation(attributes=ConversationAttributes())
170-
with generate_profile.chat_session(conversation=conversation, delete=True) as session:
180+
with generate_profile.chat_session(
181+
conversation=conversation, delete=True
182+
) as session:
171183
assert session is not None
172184

173185

@@ -194,22 +206,28 @@ def test_1612_generate_showsql(generate_profile):
194206

195207
def test_1613_generate_chat(generate_profile):
196208
"""generate with CHAT returns response"""
197-
chat_resp = generate_profile.generate(prompt="Tell me about OCI", action=Action.CHAT)
209+
chat_resp = generate_profile.generate(
210+
prompt="Tell me about OCI", action=Action.CHAT
211+
)
198212
assert isinstance(chat_resp, str)
199213
assert len(chat_resp) > 0
200214

201215

202216
def test_1614_generate_narrate(generate_profile):
203217
"""generate with NARRATE returns response"""
204-
narrate_resp = generate_profile.generate(prompt=PROMPTS[1], action=Action.NARRATE)
218+
narrate_resp = generate_profile.generate(
219+
prompt=PROMPTS[1], action=Action.NARRATE
220+
)
205221
assert isinstance(narrate_resp, str)
206222
assert len(narrate_resp) > 0
207223

208224

209225
def test_1615_generate_explainsql(generate_profile):
210226
"""generate with EXPLAINSQL returns explanation"""
211227
for prompt in PROMPTS:
212-
explain_sql = generate_profile.generate(prompt=prompt, action=Action.EXPLAINSQL)
228+
explain_sql = generate_profile.generate(
229+
prompt=prompt, action=Action.EXPLAINSQL
230+
)
213231
assert isinstance(explain_sql, str)
214232
assert len(explain_sql) > 0
215233

@@ -256,8 +274,9 @@ def test_1617_none_prompt_raises_value_error(negative_profile):
256274
# """run_sql with non existent table raises DatabaseError"""
257275
# negative_profile.set_attribute(
258276
# attribute_name="object_list",
259-
# attribute_value='[{"owner": "PYTHONUSER", "name": "non_existent_table"}]',
277+
# attribute_value=json.dumps(
278+
# [{"owner": test_env.test_user, "name": "non_existent_table"}]
279+
# ),
260280
# )
261281
# with pytest.raises(oracledb.DatabaseError):
262282
# negative_profile.run_sql(prompt="How many entries in the table")
263-

0 commit comments

Comments
 (0)