Skip to content

Commit f919bdd

Browse files
committed
Update tests
Signed-off-by: Damon P. Cortesi <[email protected]>
1 parent 59b1fc1 commit f919bdd

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

src/spark_history_mcp/config/config.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,6 @@ class Config(BaseSettings):
9292
env_file_encoding="utf-8",
9393
)
9494

95-
@classmethod
96-
def from_file(cls, file_path: str) -> "Config":
97-
"""Load configuration from a YAML file."""
98-
if not os.path.exists(file_path):
99-
return Config()
100-
101-
with open(file_path, "r") as f:
102-
config_data = yaml.safe_load(f)
103-
104-
return cls.model_validate(config_data)
105-
10695
@classmethod
10796
def settings_customise_sources(
10897
cls,

tests/emr/test_emr_integration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ def test_spark_client_with_emr_session(self, mock_initialize):
6363
self.assertEqual(apps, [])
6464

6565
@patch("spark_history_mcp.core.app.EMRPersistentUIClient")
66-
@patch("spark_history_mcp.core.app.Config.from_file")
66+
@patch("spark_history_mcp.core.app.Config")
6767
def test_app_lifespan_with_emr_config(
68-
self, mock_config_from_file, mock_emr_client_class
68+
self, mock_config_class, mock_emr_client_class
6969
):
7070
"""Test app_lifespan context manager with EMR configuration."""
7171
import asyncio
@@ -97,7 +97,7 @@ def test_app_lifespan_with_emr_config(
9797
emr_cluster_arn=self.emr_cluster_arn, default=True, verify_ssl=True
9898
)
9999
}
100-
mock_config_from_file.return_value = mock_config
100+
mock_config_class.return_value = mock_config
101101

102102
# Use the app_lifespan context manager
103103
async def test_lifespan():

tests/unit/config.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ def test_config_from_file(self):
3939
temp_file_path = temp_file.name
4040

4141
try:
42-
# Load config from the file
43-
config = Config.from_file(temp_file_path)
42+
# Load config from the file using SHS_MCP_CONFIG env var
43+
with patch.dict(os.environ, {"SHS_MCP_CONFIG": temp_file_path}):
44+
config = Config()
4445

4546
# Verify the loaded configuration
4647
self.assertEqual(config.mcp.address, "test_host")
@@ -63,9 +64,10 @@ def test_config_from_file(self):
6364
os.unlink(temp_file_path)
6465

6566
def test_nonexistent_config_file(self):
66-
"""Test behavior when config file doesn't exist."""
67+
"""Test behavior when explicitly specified config file doesn't exist."""
6768
with self.assertRaises(FileNotFoundError):
68-
Config.from_file("nonexistent_file.yaml")
69+
with patch.dict(os.environ, {"SHS_MCP_CONFIG": "nonexistent_file.yaml"}):
70+
Config()
6971

7072
@patch.dict(
7173
os.environ,
@@ -89,7 +91,8 @@ def test_config_from_env_vars(self):
8991
temp_file_path = temp_file.name
9092

9193
try:
92-
config = Config.from_file(temp_file_path)
94+
with patch.dict(os.environ, {"SHS_MCP_CONFIG": temp_file_path}):
95+
config = Config()
9396

9497
# Verify MCP config from env vars
9598
self.assertEqual(config.mcp.address, "env_host")
@@ -122,7 +125,8 @@ def test_env_vars_override_file_config(self):
122125
temp_file_path = temp_file.name
123126

124127
try:
125-
config = Config.from_file(temp_file_path)
128+
with patch.dict(os.environ, {"SHS_MCP_CONFIG": temp_file_path}):
129+
config = Config()
126130

127131
# Verify that env vars override file config
128132
self.assertEqual(config.mcp.address, "override_host")
@@ -147,7 +151,8 @@ def test_default_values(self):
147151
temp_file_path = temp_file.name
148152

149153
try:
150-
config = Config.from_file(temp_file_path)
154+
with patch.dict(os.environ, {"SHS_MCP_CONFIG": temp_file_path}):
155+
config = Config()
151156

152157
# Check MCP defaults
153158
self.assertEqual(config.mcp.address, "localhost")

0 commit comments

Comments
 (0)