Skip to content

Commit 9c046c3

Browse files
fix tests
1 parent 81c792e commit 9c046c3

File tree

1 file changed

+31
-47
lines changed

1 file changed

+31
-47
lines changed

tests/runtime/test_version_utils.py

Lines changed: 31 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,39 @@
33

44
"""Unit tests for version_utils module."""
55

6-
import os
7-
import unittest
86
import warnings
7+
import pytest
98

109
from microsoft_agents_a365.runtime.version_utils import build_version
1110

1211

13-
class TestVersionUtils(unittest.TestCase):
14-
"""Test cases for version utility functions.
15-
16-
Tests: Default version behavior, environment variable usage, and deprecation warning.
17-
"""
18-
19-
def tearDown(self):
20-
"""Clean up environment variables after each test."""
21-
if "AGENT365_PYTHON_SDK_PACKAGE_VERSION" in os.environ:
22-
del os.environ["AGENT365_PYTHON_SDK_PACKAGE_VERSION"]
23-
24-
def test_build_version_default_value(self):
25-
"""Test build_version returns default version when no env var is set."""
26-
if "AGENT365_PYTHON_SDK_PACKAGE_VERSION" in os.environ:
27-
del os.environ["AGENT365_PYTHON_SDK_PACKAGE_VERSION"]
28-
29-
with warnings.catch_warnings():
30-
warnings.simplefilter("ignore", DeprecationWarning)
31-
result = build_version()
32-
33-
self.assertEqual(result, "0.0.0")
34-
35-
def test_build_version_with_env_var(self):
36-
"""Test build_version returns version from environment variable."""
37-
test_version = "1.2.3"
38-
os.environ["AGENT365_PYTHON_SDK_PACKAGE_VERSION"] = test_version
39-
40-
with warnings.catch_warnings():
41-
warnings.simplefilter("ignore", DeprecationWarning)
42-
result = build_version()
43-
44-
self.assertEqual(result, test_version)
45-
46-
def test_build_version_deprecation_warning(self):
47-
"""Test that build_version raises DeprecationWarning."""
48-
with self.assertWarns(DeprecationWarning) as cm:
49-
build_version()
50-
51-
warning_message = str(cm.warning)
52-
self.assertIn("deprecated", warning_message.lower())
53-
self.assertIn("setuptools-git-versioning", warning_message)
54-
55-
56-
if __name__ == "__main__":
57-
unittest.main()
12+
# Tests for build_version
13+
@pytest.mark.parametrize(
14+
"env_value,expected",
15+
[
16+
(None, "0.0.0"),
17+
("1.2.3", "1.2.3"),
18+
("2.5.0-beta", "2.5.0-beta"),
19+
("", ""),
20+
],
21+
)
22+
def test_build_version(monkeypatch, env_value, expected):
23+
"""Test build_version returns correct version based on environment variable."""
24+
if env_value is None:
25+
monkeypatch.delenv("AGENT365_PYTHON_SDK_PACKAGE_VERSION", raising=False)
26+
else:
27+
monkeypatch.setenv("AGENT365_PYTHON_SDK_PACKAGE_VERSION", env_value)
28+
29+
with warnings.catch_warnings():
30+
warnings.simplefilter("ignore", DeprecationWarning)
31+
result = build_version()
32+
33+
assert result == expected
34+
35+
36+
def test_build_version_deprecation_warning():
37+
"""Test that build_version raises DeprecationWarning with correct message."""
38+
with pytest.warns(
39+
DeprecationWarning, match="build_version.*deprecated.*setuptools-git-versioning"
40+
):
41+
build_version()

0 commit comments

Comments
 (0)