Skip to content

Commit 6dd77eb

Browse files
committed
Refactor environment variable names in tests and update related code
- Renamed environment variables for consistency and clarity, changing prefixes from `azure_ai_projects_tests_` to `azure_ai_`. - Updated test files to reflect new environment variable names, ensuring all references are consistent. - Modified the sample executor and helper functions to accommodate the new variable names. - Added a script to automate the renaming of environment variables across the codebase. - Updated `.gitignore` to exclude the new `.test.env` file.
1 parent 54e42fc commit 6dd77eb

File tree

52 files changed

+321
-264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+321
-264
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.test.env
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import os
2+
import re
3+
from pathlib import Path
4+
5+
ROOT = Path(__file__).resolve().parent
6+
7+
PAIRS = {
8+
"azure_ai_projects_tests_project_endpoint": "azure_ai_project_endpoint",
9+
"azure_ai_projects_tests_agents_project_endpoint": "azure_ai_project_endpoint",
10+
"azure_ai_projects_tests_tracing_project_endpoint": "azure_ai_project_endpoint",
11+
"azure_ai_projects_tests_model_deployment_name": "azure_ai_model_deployment_name",
12+
}
13+
14+
TARGETS = [
15+
"azure_ai_projects_tests_image_generation_model_deployment_name",
16+
"azure_ai_projects_tests_container_app_resource_id",
17+
"azure_ai_projects_tests_container_ingress_subdomain_suffix",
18+
"azure_ai_projects_tests_bing_project_connection_id",
19+
"azure_ai_projects_tests_ai_search_project_connection_id",
20+
"azure_ai_projects_tests_ai_search_index_name",
21+
"azure_ai_projects_tests_mcp_project_connection_id",
22+
"azure_ai_projects_tests_sharepoint_project_connection_id",
23+
"azure_ai_projects_tests_completed_oai_model_sft_fine_tuning_job_id",
24+
"azure_ai_projects_tests_completed_oai_model_rft_fine_tuning_job_id",
25+
"azure_ai_projects_tests_completed_oai_model_dpo_fine_tuning_job_id",
26+
"azure_ai_projects_tests_completed_oss_model_sft_fine_tuning_job_id",
27+
"azure_ai_projects_tests_running_fine_tuning_job_id",
28+
"azure_ai_projects_tests_paused_fine_tuning_job_id",
29+
"azure_ai_projects_tests_azure_subscription_id",
30+
"azure_ai_projects_tests_azure_resource_group",
31+
"azure_ai_projects_tests_ai_search_user_input",
32+
"azure_ai_projects_tests_sharepoint_user_input",
33+
"azure_ai_projects_tests_memory_store_chat_model_deployment_name",
34+
"azure_ai_projects_tests_memory_store_embedding_model_deployment_name",
35+
]
36+
37+
PREFIX = "azure_ai_projects_tests_"
38+
for target in TARGETS:
39+
if target.startswith(PREFIX):
40+
PAIRS[target] = target[len(PREFIX) :]
41+
42+
IGNORE_DIRS = {".git", "__pycache__", ".venv", "build", "dist"}
43+
IGNORE_FILES = {".env", ".test.env", ".env.template", "rename_env_vars.py"}
44+
IGNORE_SUFFIXES = {".md", ".bak", ".tmp"}
45+
SCRIPT_NAME = Path(__file__).name
46+
47+
48+
def main() -> None:
49+
changed: list[Path] = []
50+
for dirpath, dirnames, filenames in os.walk(ROOT):
51+
dirnames[:] = [d for d in dirnames if d not in IGNORE_DIRS]
52+
for fname in filenames:
53+
path = Path(dirpath) / fname
54+
55+
# Skip ignored files, script itself, markdown, and temp/backup files
56+
if fname == SCRIPT_NAME or fname in IGNORE_FILES or path.suffix.lower() in IGNORE_SUFFIXES:
57+
continue
58+
59+
try:
60+
text = path.read_text(encoding="utf-8")
61+
except (UnicodeDecodeError, OSError):
62+
continue
63+
64+
updated = text
65+
for old, new in PAIRS.items():
66+
# new_upper = new.upper()
67+
new_upper = new
68+
updated = re.sub(old, new_upper, updated)
69+
updated = re.sub(old.upper(), new_upper, updated)
70+
71+
if updated != text:
72+
path.write_text(updated, encoding="utf-8")
73+
changed.append(path)
74+
75+
print("Updated files:")
76+
for path in changed:
77+
print(f" - {path.relative_to(ROOT)}")
78+
print(f"Total: {len(changed)}")
79+
80+
81+
if __name__ == "__main__":
82+
main()

sdk/ai/azure-ai-projects/tests/agents/telemetry/test_ai_agents_instrumentor.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def test_agent_creation_with_tracing_content_recording_enabled(self, **kwargs):
194194

195195
with self.create_client(operation_group="tracing", **kwargs) as project_client:
196196

197-
model = kwargs.get("azure_ai_projects_tests_model_deployment_name")
197+
model = kwargs.get("azure_ai_model_deployment_name")
198198
print(f"Using model deployment: {model}")
199199

200200
agent_definition = PromptAgentDefinition(
@@ -288,7 +288,7 @@ def test_agent_creation_with_tracing_content_recording_disabled(self, **kwargs):
288288

289289
with self.create_client(operation_group="agents", **kwargs) as project_client:
290290

291-
model = kwargs.get("azure_ai_projects_tests_model_deployment_name")
291+
model = kwargs.get("azure_ai_model_deployment_name")
292292
agent_definition = PromptAgentDefinition(
293293
# Required parameter
294294
model=model,
@@ -520,7 +520,7 @@ def test_agent_with_structured_output_with_instructions_content_recording_enable
520520

521521
with self.create_client(operation_group="tracing", **kwargs) as project_client:
522522

523-
model = kwargs.get("azure_ai_projects_tests_model_deployment_name")
523+
model = kwargs.get("azure_ai_model_deployment_name")
524524

525525
# Define a JSON schema for structured output
526526
test_schema = {
@@ -607,7 +607,7 @@ def test_agent_with_structured_output_with_instructions_content_recording_disabl
607607

608608
with self.create_client(operation_group="agents", **kwargs) as project_client:
609609

610-
model = kwargs.get("azure_ai_projects_tests_model_deployment_name")
610+
model = kwargs.get("azure_ai_model_deployment_name")
611611

612612
test_schema = {
613613
"type": "object",
@@ -681,7 +681,7 @@ def test_agent_with_structured_output_without_instructions_content_recording_ena
681681

682682
with self.create_client(operation_group="tracing", **kwargs) as project_client:
683683

684-
model = kwargs.get("azure_ai_projects_tests_model_deployment_name")
684+
model = kwargs.get("azure_ai_model_deployment_name")
685685

686686
test_schema = {
687687
"type": "object",
@@ -763,7 +763,7 @@ def test_agent_with_structured_output_without_instructions_content_recording_dis
763763

764764
with self.create_client(operation_group="agents", **kwargs) as project_client:
765765

766-
model = kwargs.get("azure_ai_projects_tests_model_deployment_name")
766+
model = kwargs.get("azure_ai_model_deployment_name")
767767

768768
test_schema = {
769769
"type": "object",

sdk/ai/azure-ai-projects/tests/agents/telemetry/test_ai_agents_instrumentor_async.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async def test_create_agent_with_tracing_content_recording_enabled(self, **kwarg
7171
assert True == AIProjectInstrumentor().is_instrumented()
7272

7373
project_client = self.create_async_client(operation_group="tracing", **kwargs)
74-
model = kwargs.get("azure_ai_projects_tests_model_deployment_name")
74+
model = kwargs.get("azure_ai_model_deployment_name")
7575

7676
async with project_client:
7777
agent_definition = PromptAgentDefinition(
@@ -164,7 +164,7 @@ async def test_agent_creation_with_tracing_content_recording_disabled(self, **kw
164164
assert True == AIProjectInstrumentor().is_instrumented()
165165

166166
project_client = self.create_async_client(operation_group="agents", **kwargs)
167-
model = kwargs.get("azure_ai_projects_tests_model_deployment_name")
167+
model = kwargs.get("azure_ai_model_deployment_name")
168168

169169
async with project_client:
170170
agent_definition = PromptAgentDefinition(
@@ -399,7 +399,7 @@ async def test_agent_with_structured_output_with_instructions_content_recording_
399399
project_client = self.create_async_client(operation_group="tracing", **kwargs)
400400

401401
async with project_client:
402-
model = kwargs.get("azure_ai_projects_tests_model_deployment_name")
402+
model = kwargs.get("azure_ai_model_deployment_name")
403403

404404
# Define a JSON schema for structured output
405405
test_schema = {
@@ -489,7 +489,7 @@ async def test_agent_with_structured_output_with_instructions_content_recording_
489489
project_client = self.create_async_client(operation_group="agents", **kwargs)
490490

491491
async with project_client:
492-
model = kwargs.get("azure_ai_projects_tests_model_deployment_name")
492+
model = kwargs.get("azure_ai_model_deployment_name")
493493

494494
test_schema = {
495495
"type": "object",
@@ -566,7 +566,7 @@ async def test_agent_with_structured_output_without_instructions_content_recordi
566566
project_client = self.create_async_client(operation_group="tracing", **kwargs)
567567

568568
async with project_client:
569-
model = kwargs.get("azure_ai_projects_tests_model_deployment_name")
569+
model = kwargs.get("azure_ai_model_deployment_name")
570570

571571
test_schema = {
572572
"type": "object",
@@ -649,7 +649,7 @@ async def test_agent_with_structured_output_without_instructions_content_recordi
649649
project_client = self.create_async_client(operation_group="agents", **kwargs)
650650

651651
async with project_client:
652-
model = kwargs.get("azure_ai_projects_tests_model_deployment_name")
652+
model = kwargs.get("azure_ai_model_deployment_name")
653653

654654
test_schema = {
655655
"type": "object",

0 commit comments

Comments
 (0)