|
6 | 6 |
|
7 | 7 |
|
8 | 8 | def test_default_configuration() -> None: |
| 9 | + """ |
| 10 | + Verify that accessing any configuration-related property on an uninitialized AppConfig instance raises an exception indicating the configuration is not loaded. |
| 11 | + """ |
9 | 12 | cfg = AppConfig() |
10 | 13 | assert cfg is not None |
11 | 14 |
|
12 | 15 | # configuration is not loaded |
13 | 16 | with pytest.raises(Exception, match="logic error: configuration is not loaded"): |
14 | 17 | # try to read property |
15 | | - cfg.configuration |
| 18 | + cfg.configuration # pylint: disable=pointless-statement |
16 | 19 |
|
17 | 20 | with pytest.raises(Exception, match="logic error: configuration is not loaded"): |
18 | 21 | # try to read property |
19 | | - cfg.llama_stack_configuration |
| 22 | + cfg.service_configuration # pylint: disable=pointless-statement |
20 | 23 |
|
21 | 24 | with pytest.raises(Exception, match="logic error: configuration is not loaded"): |
22 | 25 | # try to read property |
23 | | - cfg.user_data_collection_configuration |
| 26 | + cfg.llama_stack_configuration # pylint: disable=pointless-statement |
| 27 | + |
| 28 | + with pytest.raises(Exception, match="logic error: configuration is not loaded"): |
| 29 | + # try to read property |
| 30 | + cfg.user_data_collection_configuration # pylint: disable=pointless-statement |
| 31 | + |
| 32 | + with pytest.raises(Exception, match="logic error: configuration is not loaded"): |
| 33 | + # try to read property |
| 34 | + cfg.mcp_servers # pylint: disable=pointless-statement |
| 35 | + |
| 36 | + with pytest.raises(Exception, match="logic error: configuration is not loaded"): |
| 37 | + # try to read property |
| 38 | + cfg.authentication_configuration # pylint: disable=pointless-statement |
| 39 | + |
| 40 | + with pytest.raises(Exception, match="logic error: configuration is not loaded"): |
| 41 | + # try to read property |
| 42 | + cfg.customization # pylint: disable=pointless-statement |
24 | 43 |
|
25 | 44 |
|
26 | 45 | def test_configuration_is_singleton() -> None: |
| 46 | + """ |
| 47 | + Verify that multiple instances of AppConfig refer to the same singleton configuration object. |
| 48 | + """ |
27 | 49 | cfg1 = AppConfig() |
28 | 50 | cfg2 = AppConfig() |
29 | 51 | assert cfg1 == cfg2 |
30 | 52 |
|
31 | 53 |
|
32 | 54 | def test_init_from_dict() -> None: |
| 55 | + """ |
| 56 | + Verify that initializing AppConfig from a dictionary correctly sets all configuration subsections and their attributes. |
| 57 | + """ |
33 | 58 | config_dict = { |
34 | 59 | "name": "foo", |
35 | 60 | "service": { |
@@ -126,8 +151,13 @@ def test_init_from_dict_with_mcp_servers() -> None: |
126 | 151 |
|
127 | 152 |
|
128 | 153 | def test_load_proper_configuration(tmpdir) -> None: |
| 154 | + """ |
| 155 | + Test that a valid YAML configuration file can be loaded and all configuration subsections are accessible. |
| 156 | + |
| 157 | + Creates a sample configuration file, loads it using `AppConfig`, and asserts that the main configuration and its subsections are properly initialized. |
| 158 | + """ |
129 | 159 | cfg_filename = tmpdir / "config.yaml" |
130 | | - with open(cfg_filename, "w") as fout: |
| 160 | + with open(cfg_filename, "w", encoding="utf-8") as fout: |
131 | 161 | fout.write( |
132 | 162 | """ |
133 | 163 | name: foo bar baz |
@@ -157,9 +187,11 @@ def test_load_proper_configuration(tmpdir) -> None: |
157 | 187 |
|
158 | 188 |
|
159 | 189 | def test_load_configuration_with_mcp_servers(tmpdir) -> None: |
160 | | - """Test loading configuration from YAML file with MCP servers.""" |
| 190 | + """ |
| 191 | + Test that loading a YAML configuration file with multiple MCP servers correctly initializes the `mcp_servers` property, including handling of default and custom `provider_id` values. |
| 192 | + """ |
161 | 193 | cfg_filename = tmpdir / "config.yaml" |
162 | | - with open(cfg_filename, "w") as fout: |
| 194 | + with open(cfg_filename, "w", encoding="utf-8") as fout: |
163 | 195 | fout.write( |
164 | 196 | """ |
165 | 197 | name: test service |
@@ -268,58 +300,95 @@ def test_mcp_servers_property_with_servers() -> None: |
268 | 300 |
|
269 | 301 |
|
270 | 302 | def test_configuration_not_loaded(): |
271 | | - """Test that accessing configuration before loading raises an error.""" |
| 303 | + """ |
| 304 | + Test that accessing the `configuration` property on an uninitialized `AppConfig` instance raises an AssertionError with the expected message. |
| 305 | + """ |
272 | 306 | cfg = AppConfig() |
273 | 307 | with pytest.raises( |
274 | 308 | AssertionError, match="logic error: configuration is not loaded" |
275 | 309 | ): |
276 | | - cfg.configuration |
| 310 | + cfg.configuration # pylint: disable=pointless-statement |
277 | 311 |
|
278 | 312 |
|
279 | 313 | def test_service_configuration_not_loaded(): |
280 | | - """Test that accessing service_configuration before loading raises an error.""" |
| 314 | + """ |
| 315 | + Test that accessing the service_configuration property on an uninitialized AppConfig instance raises an AssertionError with the expected message. |
| 316 | + """ |
281 | 317 | cfg = AppConfig() |
282 | 318 | with pytest.raises( |
283 | 319 | AssertionError, match="logic error: configuration is not loaded" |
284 | 320 | ): |
285 | | - cfg.service_configuration |
| 321 | + cfg.service_configuration # pylint: disable=pointless-statement |
286 | 322 |
|
287 | 323 |
|
288 | 324 | def test_llama_stack_configuration_not_loaded(): |
289 | | - """Test that accessing llama_stack_configuration before loading raises an error.""" |
| 325 | + """ |
| 326 | + Test that accessing the llama_stack_configuration property on an uninitialized AppConfig instance raises an AssertionError with the expected message. |
| 327 | + """ |
290 | 328 | cfg = AppConfig() |
291 | 329 | with pytest.raises( |
292 | 330 | AssertionError, match="logic error: configuration is not loaded" |
293 | 331 | ): |
294 | | - cfg.llama_stack_configuration |
| 332 | + cfg.llama_stack_configuration # pylint: disable=pointless-statement |
295 | 333 |
|
296 | 334 |
|
297 | 335 | def test_user_data_collection_configuration_not_loaded(): |
298 | | - """Test that accessing user_data_collection_configuration before loading raises an error.""" |
| 336 | + """ |
| 337 | + Test that accessing the user data collection configuration property before loading raises an AssertionError with the expected message. |
| 338 | + """ |
299 | 339 | cfg = AppConfig() |
300 | 340 | with pytest.raises( |
301 | 341 | AssertionError, match="logic error: configuration is not loaded" |
302 | 342 | ): |
303 | | - cfg.user_data_collection_configuration |
| 343 | + cfg.user_data_collection_configuration # pylint: disable=pointless-statement |
304 | 344 |
|
305 | 345 |
|
306 | 346 | def test_mcp_servers_not_loaded(): |
307 | | - """Test that accessing mcp_servers before loading raises an error.""" |
| 347 | + """ |
| 348 | + Test that accessing the `mcp_servers` property on an uninitialized `AppConfig` instance raises an AssertionError with the expected message. |
| 349 | + """ |
| 350 | + cfg = AppConfig() |
| 351 | + with pytest.raises( |
| 352 | + AssertionError, match="logic error: configuration is not loaded" |
| 353 | + ): |
| 354 | + cfg.mcp_servers # pylint: disable=pointless-statement |
| 355 | + |
| 356 | + |
| 357 | +def test_authentication_configuration_not_loaded(): |
| 358 | + """ |
| 359 | + Test that accessing the authentication_configuration property on an uninitialized AppConfig instance raises an AssertionError with the expected message. |
| 360 | + """ |
| 361 | + cfg = AppConfig() |
| 362 | + with pytest.raises( |
| 363 | + AssertionError, match="logic error: configuration is not loaded" |
| 364 | + ): |
| 365 | + cfg.authentication_configuration # pylint: disable=pointless-statement |
| 366 | + |
| 367 | + |
| 368 | +def test_customization_not_loaded(): |
| 369 | + """ |
| 370 | + Test that accessing the `customization` property on an uninitialized `AppConfig` instance raises an AssertionError with the expected message. |
| 371 | + """ |
308 | 372 | cfg = AppConfig() |
309 | 373 | with pytest.raises( |
310 | 374 | AssertionError, match="logic error: configuration is not loaded" |
311 | 375 | ): |
312 | | - cfg.mcp_servers |
| 376 | + cfg.customization # pylint: disable=pointless-statement |
313 | 377 |
|
314 | 378 |
|
315 | 379 | def test_load_configuration_with_customization_system_prompt_path(tmpdir) -> None: |
316 | | - """Test loading configuration from YAML file with customization.""" |
| 380 | + """ |
| 381 | + Test that loading a YAML configuration file with a customization section specifying a system prompt file path correctly loads the system prompt content from the referenced file. |
| 382 | + |
| 383 | + Parameters: |
| 384 | + tmpdir: Temporary directory fixture provided by pytest for file operations. |
| 385 | + """ |
317 | 386 | system_prompt_filename = tmpdir / "system_prompt.txt" |
318 | | - with open(system_prompt_filename, "w") as fout: |
| 387 | + with open(system_prompt_filename, "w", encoding="utf-8") as fout: |
319 | 388 | fout.write("this is system prompt") |
320 | 389 |
|
321 | 390 | cfg_filename = tmpdir / "config.yaml" |
322 | | - with open(cfg_filename, "w") as fout: |
| 391 | + with open(cfg_filename, "w", encoding="utf-8") as fout: |
323 | 392 | fout.write( |
324 | 393 | f""" |
325 | 394 | name: test service |
@@ -357,9 +426,11 @@ def test_load_configuration_with_customization_system_prompt_path(tmpdir) -> Non |
357 | 426 |
|
358 | 427 |
|
359 | 428 | def test_load_configuration_with_customization_system_prompt(tmpdir) -> None: |
360 | | - """Test loading configuration from YAML file with system_prompt in the customization.""" |
| 429 | + """ |
| 430 | + Test that loading a YAML configuration file with an inline `system_prompt` in the customization section correctly sets the `system_prompt` property of the loaded configuration. |
| 431 | + """ |
361 | 432 | cfg_filename = tmpdir / "config.yaml" |
362 | | - with open(cfg_filename, "w") as fout: |
| 433 | + with open(cfg_filename, "w", encoding="utf-8") as fout: |
363 | 434 | fout.write( |
364 | 435 | """ |
365 | 436 | name: test service |
|
0 commit comments