Skip to content

Commit 68c09de

Browse files
committed
fix unit tests
1 parent 615bbd6 commit 68c09de

File tree

9 files changed

+51
-62
lines changed

9 files changed

+51
-62
lines changed

src/aks-agent/azext_aks_agent/agent/status.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
16
"""
27
Status collection and management for AKS Agent.
38
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
"""
7+
Pytest configuration for azext_aks_agent tests.
8+
9+
Skips the entire test suite in this folder when running under Python < 3.10.
10+
"""
11+
12+
import sys
13+
import pytest
14+
15+
16+
def pytest_collection_modifyitems(config, items):
17+
"""Mark all tests in this folder as skipped on Python < 3.10.
18+
19+
This ensures tests are still collected (so pytest exits with code 0),
20+
but are skipped during execution under older Python versions.
21+
"""
22+
if sys.version_info < (3, 10):
23+
skip_marker = pytest.mark.skip(
24+
reason="azext_aks_agent tests require Python >= 3.10"
25+
)
26+
for item in items:
27+
item.add_marker(skip_marker)

src/aks-agent/azext_aks_agent/tests/latest/test_agent.py renamed to src/aks-agent/azext_aks_agent/tests/latest/test_aks_agent.py

File renamed without changes.

src/aks-agent/azext_aks_agent/tests/latest/test_mcp_manager.py renamed to src/aks-agent/azext_aks_agent/tests/latest/test_aks_agent_mcp_manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def tearDown(self):
3737
shutil.rmtree(self.test_config_dir, ignore_errors=True)
3838

3939
@patch('azext_aks_agent.agent.mcp_manager.get_config_dir')
40-
def test_init_with_default_config_dir(self, mock_get_config_dir):
40+
def test_mcp_manager_init_with_default_config_dir(self, mock_get_config_dir):
4141
"""Test MCP manager initialization with default config directory."""
4242
mock_get_config_dir.return_value = '/mock/config/dir'
4343

@@ -52,7 +52,7 @@ def test_init_with_default_config_dir(self, mock_get_config_dir):
5252
self.assertIsNone(manager.server_port)
5353
mock_get_config_dir.assert_called_once()
5454

55-
def test_init_with_custom_config_dir(self):
55+
def test_mcp_manager_init_with_custom_config_dir(self):
5656
"""Test MCP manager initialization with custom config directory."""
5757
manager = MCPManager(config_dir=self.test_config_dir, verbose=True)
5858

@@ -390,4 +390,3 @@ def test_get_server_port_not_running(self):
390390

391391
runner = unittest.TextTestRunner(verbosity=2)
392392
result = runner.run(suite)
393-

src/aks-agent/azext_aks_agent/tests/latest/test_aks_agent_status.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
16
"""
27
Unit tests for agent status collection functionality.
38
"""
@@ -26,7 +31,7 @@ def teardown_method(self):
2631
import shutil
2732
shutil.rmtree(self.temp_dir, ignore_errors=True)
2833

29-
def test_init_with_default_config_dir(self):
34+
def test_status_manager_init_with_default_config_dir(self):
3035
"""Test initialization with default config directory."""
3136
with patch('azext_aks_agent.agent.status.get_config_dir') as mock_get_config_dir:
3237
mock_get_config_dir.return_value = '/mock/config/dir'
@@ -36,7 +41,7 @@ def test_init_with_default_config_dir(self):
3641
assert manager.config_dir == '/mock/config/dir'
3742
mock_get_config_dir.assert_called_once()
3843

39-
def test_init_with_custom_config_dir(self):
44+
def test_status_manager_init_with_custom_config_dir(self):
4045
"""Test initialization with custom config directory."""
4146
custom_dir = '/custom/config/dir'
4247
manager = AgentStatusManager(config_dir=custom_dir)
@@ -387,4 +392,3 @@ def test_load_config_file_invalid_json_falls_back_to_yaml(self):
387392
result = self.status_manager._load_config_file(config_file_path)
388393

389394
assert result is None
390-

src/aks-agent/azext_aks_agent/tests/latest/test_aks_agent_status_command.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def test_display_agent_status_verbose(self):
205205
# Check that print was called multiple times (for table and recommendations)
206206
self.assertTrue(mock_console.print.call_count >= 2)
207207

208-
def test_command_registration(self):
208+
def test_status_command_registration(self):
209209
"""Test that the agent status command is properly registered."""
210210
# Import functions to verify presence
211211
try:
@@ -220,4 +220,3 @@ def test_command_registration(self):
220220

221221
if __name__ == '__main__':
222222
unittest.main()
223-

src/aks-agent/azext_aks_agent/tests/latest/test_aks_agent_status_models.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class TestBinaryStatus(unittest.TestCase):
2323
"""Test BinaryStatus data model."""
2424

25-
def test_default_initialization(self):
25+
def test_binary_status_default_initialization(self):
2626
"""Test default values are set correctly."""
2727
status = BinaryStatus()
2828

@@ -35,7 +35,7 @@ def test_default_initialization(self):
3535
self.assertIsNone(status.error_message)
3636
self.assertFalse(status.ready)
3737

38-
def test_initialization_with_values(self):
38+
def test_binary_status_initialization_with_values(self):
3939
"""Test initialization with specific values."""
4040
now = datetime.now()
4141
status = BinaryStatus(
@@ -121,7 +121,7 @@ def test_from_file_path_os_error(self, mock_stat):
121121
class TestServerStatus(unittest.TestCase):
122122
"""Test ServerStatus data model."""
123123

124-
def test_default_initialization(self):
124+
def test_server_status_default_initialization(self):
125125
"""Test default values are set correctly."""
126126
status = ServerStatus()
127127

@@ -196,7 +196,7 @@ def test_full_initialization(self):
196196
class TestConfigStatus(unittest.TestCase):
197197
"""Test ConfigStatus data model."""
198198

199-
def test_default_initialization(self):
199+
def test_config_status_default_initialization(self):
200200
"""Test default values and post_init behavior."""
201201
status = ConfigStatus()
202202

@@ -208,7 +208,7 @@ def test_default_initialization(self):
208208
self.assertTrue(status.config_valid)
209209
self.assertIsNone(status.error_message)
210210

211-
def test_initialization_with_values(self):
211+
def test_config_status_initialization_with_values(self):
212212
"""Test initialization with specific values."""
213213
toolsets = ["aks/core", "kubernetes/core"]
214214
mcp_servers = ["aks-mcp"]
@@ -272,7 +272,7 @@ def test_count_properties(self):
272272
class TestAgentStatus(unittest.TestCase):
273273
"""Test AgentStatus data model."""
274274

275-
def test_default_initialization(self):
275+
def test_agent_status_default_initialization(self):
276276
"""Test default values and component creation."""
277277
status = AgentStatus()
278278

@@ -471,4 +471,3 @@ def test_get_recommendations_config_invalid(self):
471471

472472
if __name__ == "__main__":
473473
unittest.main()
474-

src/aks-agent/azext_aks_agent/tests/latest/test_user_feedback.py renamed to src/aks-agent/azext_aks_agent/tests/latest/test_aks_agent_user_feedback.py

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -70,35 +70,7 @@ def test_show_download_progress_no_tty(self):
7070
# Should not call console when not TTY
7171
self.mock_console.print.assert_not_called()
7272

73-
def test_show_download_progress_no_console_holmes_available(self):
74-
"""Test download progress without console but Holmes available."""
75-
mock_holmes_console = Mock()
76-
77-
with patch('holmes.utils.console.logging.init_logging', return_value=mock_holmes_console), \
78-
patch('sys.stdout.isatty', return_value=True):
79-
ProgressReporter.show_download_progress(
80-
downloaded=250,
81-
total=1000,
82-
filename="holmes.bin"
83-
)
84-
85-
mock_holmes_console.print.assert_called_once()
86-
87-
@patch('builtins.print')
88-
def test_show_download_progress_no_console_no_holmes(self, mock_print):
89-
"""Test download progress fallback when Holmes not available."""
90-
with patch('holmes.utils.console.logging.init_logging',
91-
side_effect=ImportError("Holmes not available")):
92-
ProgressReporter.show_download_progress(
93-
downloaded=750,
94-
total=1000,
95-
filename="fallback.bin"
96-
)
97-
98-
mock_print.assert_called_once()
99-
call_args = mock_print.call_args[0][0]
100-
self.assertIn("Downloading fallback.bin", call_args)
101-
self.assertIn("75.0%", call_args)
73+
10274

10375
def test_show_status_message_all_levels(self):
10476
"""Test status messages with different levels."""
@@ -121,23 +93,7 @@ def test_show_status_message_all_levels(self):
12193

12294
self.mock_console.print.assert_called_once_with(expected_style)
12395

124-
def test_show_status_message_no_console_holmes_available(self):
125-
"""Test status message without console but Holmes available."""
126-
mock_holmes_console = Mock()
127-
128-
with patch('holmes.utils.console.logging.init_logging', return_value=mock_holmes_console):
129-
ProgressReporter.show_status_message("Test message", "info")
130-
131-
mock_holmes_console.print.assert_called_once_with("[cyan]Test message[/cyan]")
132-
133-
@patch('builtins.print')
134-
def test_show_status_message_no_console_no_holmes(self, mock_print):
135-
"""Test status message fallback when Holmes not available."""
136-
with patch('holmes.utils.console.logging.init_logging',
137-
side_effect=ImportError("Holmes not available")):
138-
ProgressReporter.show_status_message("Fallback message", "error")
139-
140-
mock_print.assert_called_once_with("[ERROR] Fallback message")
96+
14197

14298
def test_show_binary_setup_status(self):
14399
"""Test binary setup status message."""
@@ -215,4 +171,3 @@ def test_progress_bar_formatting(self):
215171

216172
if __name__ == '__main__':
217173
unittest.main()
218-

src/aks-agent/azext_aks_agent/tests/latest/test_validators.py renamed to src/aks-agent/azext_aks_agent/tests/latest/test_aks_agent_validators.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright (c) Microsoft Corporation. All rights reserved.
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# --------------------------------------------------------------------------------------------
5+
# This test module was renamed to avoid name collision with 'acs' module tests.
56
import os
67
import shutil
78
import tempfile

0 commit comments

Comments
 (0)