Skip to content

Commit d949253

Browse files
Add min tests
1 parent 70f4c08 commit d949253

2 files changed

Lines changed: 10 additions & 195 deletions

File tree

tests/runtime/test_environment_utils.py

Lines changed: 6 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import os
77
import unittest
8-
from unittest.mock import patch
98

109
from microsoft_agents_a365.runtime.environment_utils import (
1110
DEVELOPMENT_ENVIRONMENT_NAME,
@@ -18,14 +17,15 @@
1817

1918

2019
class TestEnvironmentUtils(unittest.TestCase):
21-
"""Test cases for environment utility functions."""
20+
"""Test cases for environment utility functions.
21+
22+
Tests: Constants validation, observability scope retrieval, and environment detection logic.
23+
"""
2224

2325
def tearDown(self):
2426
"""Clean up environment variables after each test."""
25-
env_vars = ["PYTHON_ENVIRONMENT"]
26-
for var in env_vars:
27-
if var in os.environ:
28-
del os.environ[var]
27+
if "PYTHON_ENVIRONMENT" in os.environ:
28+
del os.environ["PYTHON_ENVIRONMENT"]
2929

3030
def test_constants(self):
3131
"""Test that environment constants have expected values."""
@@ -44,7 +44,6 @@ def test_get_observability_authentication_scope_returns_prod_scope(self):
4444

4545
def test_is_development_environment_with_no_env_var(self):
4646
"""Test is_development_environment returns False when no environment variable is set."""
47-
# Ensure environment variables are not set
4847
if "PYTHON_ENVIRONMENT" in os.environ:
4948
del os.environ["PYTHON_ENVIRONMENT"]
5049

@@ -60,16 +59,6 @@ def test_is_development_environment_with_development_env_var(self):
6059

6160
self.assertTrue(result)
6261

63-
def test_is_development_environment_case_insensitive(self):
64-
"""Test is_development_environment is case-insensitive."""
65-
test_cases = ["development", "DEVELOPMENT", "DeveLoPMenT", "Development"]
66-
67-
for env_value in test_cases:
68-
with self.subTest(env_value=env_value):
69-
os.environ["PYTHON_ENVIRONMENT"] = env_value
70-
result = is_development_environment()
71-
self.assertTrue(result)
72-
7362
def test_is_development_environment_with_production_env_var(self):
7463
"""Test is_development_environment returns False when PYTHON_ENVIRONMENT is 'production'."""
7564
os.environ["PYTHON_ENVIRONMENT"] = "production"
@@ -78,86 +67,6 @@ def test_is_development_environment_with_production_env_var(self):
7867

7968
self.assertFalse(result)
8069

81-
def test_is_development_environment_with_other_env_var(self):
82-
"""Test is_development_environment returns False for other environment values."""
83-
test_cases = ["staging", "test", "preprod", "custom"]
84-
85-
for env_value in test_cases:
86-
with self.subTest(env_value=env_value):
87-
os.environ["PYTHON_ENVIRONMENT"] = env_value
88-
result = is_development_environment()
89-
self.assertFalse(result)
90-
91-
def test_is_development_environment_with_empty_env_var(self):
92-
"""Test is_development_environment returns False when PYTHON_ENVIRONMENT is empty."""
93-
os.environ["PYTHON_ENVIRONMENT"] = ""
94-
95-
result = is_development_environment()
96-
97-
self.assertFalse(result)
98-
99-
def test_is_development_environment_with_whitespace_env_var(self):
100-
"""Test is_development_environment returns False when PYTHON_ENVIRONMENT is whitespace."""
101-
os.environ["PYTHON_ENVIRONMENT"] = " "
102-
103-
result = is_development_environment()
104-
105-
self.assertFalse(result)
106-
107-
@patch.dict(os.environ, {"PYTHON_ENVIRONMENT": "Development"}, clear=False)
108-
def test_python_environment_precedence(self):
109-
"""Test that PYTHON_ENVIRONMENT takes precedence."""
110-
result = is_development_environment()
111-
112-
self.assertTrue(result)
113-
114-
def test_default_environment_is_production(self):
115-
"""Test that the default environment is production when no env vars are set."""
116-
# Ensure no environment variables are set
117-
if "PYTHON_ENVIRONMENT" in os.environ:
118-
del os.environ["PYTHON_ENVIRONMENT"]
119-
120-
# The _get_current_environment function should default to PRODUCTION_ENVIRONMENT_NAME
121-
result = is_development_environment()
122-
123-
self.assertFalse(result)
124-
125-
126-
class TestObservabilityAuthenticationScope(unittest.TestCase):
127-
"""Test cases for observability authentication scope."""
128-
129-
def test_scope_is_list(self):
130-
"""Test that the scope is returned as a list."""
131-
result = get_observability_authentication_scope()
132-
133-
self.assertIsInstance(result, list)
134-
135-
def test_scope_contains_single_value(self):
136-
"""Test that the scope list contains exactly one value."""
137-
result = get_observability_authentication_scope()
138-
139-
self.assertEqual(len(result), 1)
140-
141-
def test_scope_value_is_string(self):
142-
"""Test that the scope value is a string."""
143-
result = get_observability_authentication_scope()
144-
145-
self.assertIsInstance(result[0], str)
146-
147-
def test_scope_value_format(self):
148-
"""Test that the scope value has the correct format."""
149-
result = get_observability_authentication_scope()
150-
151-
self.assertTrue(result[0].startswith("https://"))
152-
self.assertTrue(result[0].endswith(".default"))
153-
154-
def test_scope_consistency(self):
155-
"""Test that multiple calls return the same scope."""
156-
result1 = get_observability_authentication_scope()
157-
result2 = get_observability_authentication_scope()
158-
159-
self.assertEqual(result1, result2)
160-
16170

16271
if __name__ == "__main__":
16372
unittest.main()

tests/runtime/test_version_utils.py

Lines changed: 4 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,18 @@
1111

1212

1313
class TestVersionUtils(unittest.TestCase):
14-
"""Test cases for version utility functions."""
14+
"""Test cases for version utility functions.
15+
16+
Tests: Default version behavior, environment variable usage, and deprecation warning.
17+
"""
1518

1619
def tearDown(self):
1720
"""Clean up environment variables after each test."""
1821
if "AGENT365_PYTHON_SDK_PACKAGE_VERSION" in os.environ:
1922
del os.environ["AGENT365_PYTHON_SDK_PACKAGE_VERSION"]
2023

21-
def test_build_version_returns_string(self):
22-
"""Test that build_version returns a string."""
23-
with warnings.catch_warnings():
24-
warnings.simplefilter("ignore", DeprecationWarning)
25-
result = build_version()
26-
27-
self.assertIsInstance(result, str)
28-
2924
def test_build_version_default_value(self):
3025
"""Test build_version returns default version when no env var is set."""
31-
# Ensure environment variable is not set
3226
if "AGENT365_PYTHON_SDK_PACKAGE_VERSION" in os.environ:
3327
del os.environ["AGENT365_PYTHON_SDK_PACKAGE_VERSION"]
3428

@@ -49,36 +43,6 @@ def test_build_version_with_env_var(self):
4943

5044
self.assertEqual(result, test_version)
5145

52-
def test_build_version_with_complex_version(self):
53-
"""Test build_version with complex version strings."""
54-
test_cases = [
55-
"1.0.0-alpha",
56-
"2.3.4-beta.1",
57-
"3.0.0-rc.2",
58-
"1.2.3+build.456",
59-
"2.0.0-alpha.1+build.789",
60-
]
61-
62-
for version in test_cases:
63-
with self.subTest(version=version):
64-
os.environ["AGENT365_PYTHON_SDK_PACKAGE_VERSION"] = version
65-
66-
with warnings.catch_warnings():
67-
warnings.simplefilter("ignore", DeprecationWarning)
68-
result = build_version()
69-
70-
self.assertEqual(result, version)
71-
72-
def test_build_version_with_empty_env_var(self):
73-
"""Test build_version with empty environment variable."""
74-
os.environ["AGENT365_PYTHON_SDK_PACKAGE_VERSION"] = ""
75-
76-
with warnings.catch_warnings():
77-
warnings.simplefilter("ignore", DeprecationWarning)
78-
result = build_version()
79-
80-
self.assertEqual(result, "")
81-
8246
def test_build_version_deprecation_warning(self):
8347
"""Test that build_version raises DeprecationWarning."""
8448
with self.assertWarns(DeprecationWarning) as cm:
@@ -88,64 +52,6 @@ def test_build_version_deprecation_warning(self):
8852
self.assertIn("deprecated", warning_message.lower())
8953
self.assertIn("setuptools-git-versioning", warning_message)
9054

91-
def test_build_version_deprecation_warning_message(self):
92-
"""Test that deprecation warning contains the correct message."""
93-
with warnings.catch_warnings(record=True) as w:
94-
warnings.simplefilter("always")
95-
build_version()
96-
97-
# Check that exactly one warning was raised
98-
self.assertEqual(len(w), 1)
99-
100-
# Check that it's a DeprecationWarning
101-
self.assertTrue(issubclass(w[0].category, DeprecationWarning))
102-
103-
# Check the message content
104-
message = str(w[0].message)
105-
self.assertIn("build_version() is deprecated", message)
106-
self.assertIn("setuptools-git-versioning", message)
107-
108-
def test_build_version_stacklevel(self):
109-
"""Test that deprecation warning has correct stack level."""
110-
with warnings.catch_warnings(record=True) as w:
111-
warnings.simplefilter("always")
112-
build_version()
113-
114-
# The warning should point to the caller of build_version
115-
# not to the function itself (stacklevel=2)
116-
self.assertEqual(len(w), 1)
117-
warning = w[0]
118-
119-
# Verify the warning was captured
120-
self.assertIsNotNone(warning.filename)
121-
self.assertGreater(warning.lineno, 0)
122-
123-
124-
class TestVersionUtilsDocstring(unittest.TestCase):
125-
"""Test cases for version_utils module documentation."""
126-
127-
def test_module_has_docstring(self):
128-
"""Test that the module has a docstring."""
129-
import microsoft_agents_a365.runtime.version_utils as version_utils
130-
131-
self.assertIsNotNone(version_utils.__doc__)
132-
self.assertGreater(len(version_utils.__doc__), 0)
133-
134-
def test_module_docstring_mentions_deprecation(self):
135-
"""Test that module docstring mentions deprecation."""
136-
import microsoft_agents_a365.runtime.version_utils as version_utils
137-
138-
self.assertIn("deprecated", version_utils.__doc__.lower())
139-
140-
def test_function_has_docstring(self):
141-
"""Test that build_version function has a docstring."""
142-
self.assertIsNotNone(build_version.__doc__)
143-
self.assertGreater(len(build_version.__doc__), 0)
144-
145-
def test_function_docstring_mentions_deprecation(self):
146-
"""Test that function docstring mentions deprecation."""
147-
self.assertIn("DEPRECATED", build_version.__doc__)
148-
14955

15056
if __name__ == "__main__":
15157
unittest.main()

0 commit comments

Comments
 (0)