Skip to content

Commit 7e6f78c

Browse files
📝 Add docstrings to lcore-303-fixed-pylint-issues
Docstrings generation was requested by @tisnik. * #233 (comment) The following files were modified: * `tests/unit/auth/test_noop_with_token.py` * `tests/unit/test_client.py` * `tests/unit/test_configuration.py`
1 parent 0578b21 commit 7e6f78c

File tree

3 files changed

+132
-26
lines changed

3 files changed

+132
-26
lines changed

tests/unit/auth/test_noop_with_token.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ async def test_noop_with_token_auth_dependency_custom_user_id():
5555

5656

5757
async def test_noop_with_token_auth_dependency_no_token():
58-
"""Test the NoopWithTokenAuthDependency class with no token."""
58+
"""
59+
Test that NoopWithTokenAuthDependency raises an HTTPException when no Authorization header is present in the request.
60+
61+
Asserts that the exception has a status code of 400 and the detail message "No Authorization header found".
62+
"""
5963
dependency = NoopWithTokenAuthDependency()
6064

6165
# Create a mock request without token
@@ -69,14 +73,18 @@ async def test_noop_with_token_auth_dependency_no_token():
6973

7074
# Assert that an HTTPException is raised when no Authorization header is found
7175
with pytest.raises(HTTPException) as exc_info:
72-
user_id, username, user_token = await dependency(request)
76+
await dependency(request)
7377

7478
assert exc_info.value.status_code == 400
7579
assert exc_info.value.detail == "No Authorization header found"
7680

7781

7882
async def test_noop_with_token_auth_dependency_no_bearer():
79-
"""Test the NoopWithTokenAuthDependency class with no token."""
83+
"""
84+
Test that NoopWithTokenAuthDependency raises an HTTPException when the Authorization header does not contain a Bearer token.
85+
86+
Asserts that the exception has a 400 status code and the detail message "No token found in Authorization header".
87+
"""
8088
dependency = NoopWithTokenAuthDependency()
8189

8290
# Create a mock request without token
@@ -90,7 +98,7 @@ async def test_noop_with_token_auth_dependency_no_bearer():
9098

9199
# Assert that an HTTPException is raised when no Authorization header is found
92100
with pytest.raises(HTTPException) as exc_info:
93-
user_id, username, user_token = await dependency(request)
101+
await dependency(request)
94102

95103
assert exc_info.value.status_code == 400
96104
assert exc_info.value.detail == "No token found in Authorization header"

tests/unit/test_client.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
from models.config import LLamaStackConfiguration
77

88

9-
# [tisnik] Need to resolve dependencies on CI to be able to run this tests
109
def test_get_llama_stack_library_client() -> None:
10+
"""
11+
Tests initialization of the Llama Stack client in library client mode using a valid configuration file.
12+
"""
1113
cfg = LLamaStackConfiguration(
1214
url=None,
1315
api_key=None,
@@ -20,6 +22,11 @@ def test_get_llama_stack_library_client() -> None:
2022

2123

2224
def test_get_llama_stack_remote_client() -> None:
25+
"""
26+
Test initialization of Llama Stack in remote (server) client mode.
27+
28+
Verifies that a Llama Stack client can be successfully created using a configuration with `use_as_library_client` set to False and a valid server URL.
29+
"""
2330
cfg = LLamaStackConfiguration(
2431
url="http://localhost:8321",
2532
api_key=None,
@@ -32,6 +39,11 @@ def test_get_llama_stack_remote_client() -> None:
3239

3340

3441
def test_get_llama_stack_wrong_configuration() -> None:
42+
"""
43+
Test that initializing a Llama Stack client in library mode without a configuration path raises an exception.
44+
45+
Verifies that an exception with the expected error message is raised if `library_client_config_path` is not set when `use_as_library_client` is True.
46+
"""
3547
cfg = LLamaStackConfiguration(
3648
url=None,
3749
api_key=None,
@@ -48,6 +60,11 @@ def test_get_llama_stack_wrong_configuration() -> None:
4860

4961

5062
async def test_get_async_llama_stack_library_client() -> None:
63+
"""
64+
Test asynchronous initialization of a Llama Stack client in library mode.
65+
66+
Verifies that the AsyncLlamaStackClientHolder can be successfully loaded with a configuration specifying library client mode and a valid configuration path.
67+
"""
5168
cfg = LLamaStackConfiguration(
5269
url=None,
5370
api_key=None,
@@ -60,6 +77,11 @@ async def test_get_async_llama_stack_library_client() -> None:
6077

6178

6279
async def test_get_async_llama_stack_remote_client() -> None:
80+
"""
81+
Test asynchronous initialization of a Llama Stack client in remote (server) mode.
82+
83+
Verifies that the AsyncLlamaStackClientHolder can be successfully loaded with a configuration specifying remote server mode.
84+
"""
6385
cfg = LLamaStackConfiguration(
6486
url="http://localhost:8321",
6587
api_key=None,
@@ -72,6 +94,11 @@ async def test_get_async_llama_stack_remote_client() -> None:
7294

7395

7496
async def test_get_async_llama_stack_wrong_configuration() -> None:
97+
"""
98+
Test that initializing AsyncLlamaStackClientHolder with missing library_client_config_path raises an exception.
99+
100+
Verifies that an exception with the expected error message is raised when attempting to load the client in library client mode without specifying the required configuration path.
101+
"""
75102
cfg = LLamaStackConfiguration(
76103
url=None,
77104
api_key=None,

tests/unit/test_configuration.py

Lines changed: 92 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,55 @@
66

77

88
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+
"""
912
cfg = AppConfig()
1013
assert cfg is not None
1114

1215
# configuration is not loaded
1316
with pytest.raises(Exception, match="logic error: configuration is not loaded"):
1417
# try to read property
15-
cfg.configuration
18+
cfg.configuration # pylint: disable=pointless-statement
1619

1720
with pytest.raises(Exception, match="logic error: configuration is not loaded"):
1821
# try to read property
19-
cfg.llama_stack_configuration
22+
cfg.service_configuration # pylint: disable=pointless-statement
2023

2124
with pytest.raises(Exception, match="logic error: configuration is not loaded"):
2225
# 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
2443

2544

2645
def test_configuration_is_singleton() -> None:
46+
"""
47+
Verify that multiple instances of AppConfig refer to the same singleton configuration object.
48+
"""
2749
cfg1 = AppConfig()
2850
cfg2 = AppConfig()
2951
assert cfg1 == cfg2
3052

3153

3254
def test_init_from_dict() -> None:
55+
"""
56+
Verify that initializing AppConfig from a dictionary correctly sets all configuration subsections and their attributes.
57+
"""
3358
config_dict = {
3459
"name": "foo",
3560
"service": {
@@ -126,8 +151,13 @@ def test_init_from_dict_with_mcp_servers() -> None:
126151

127152

128153
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+
"""
129159
cfg_filename = tmpdir / "config.yaml"
130-
with open(cfg_filename, "w") as fout:
160+
with open(cfg_filename, "w", encoding="utf-8") as fout:
131161
fout.write(
132162
"""
133163
name: foo bar baz
@@ -157,9 +187,11 @@ def test_load_proper_configuration(tmpdir) -> None:
157187

158188

159189
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+
"""
161193
cfg_filename = tmpdir / "config.yaml"
162-
with open(cfg_filename, "w") as fout:
194+
with open(cfg_filename, "w", encoding="utf-8") as fout:
163195
fout.write(
164196
"""
165197
name: test service
@@ -268,58 +300,95 @@ def test_mcp_servers_property_with_servers() -> None:
268300

269301

270302
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+
"""
272306
cfg = AppConfig()
273307
with pytest.raises(
274308
AssertionError, match="logic error: configuration is not loaded"
275309
):
276-
cfg.configuration
310+
cfg.configuration # pylint: disable=pointless-statement
277311

278312

279313
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+
"""
281317
cfg = AppConfig()
282318
with pytest.raises(
283319
AssertionError, match="logic error: configuration is not loaded"
284320
):
285-
cfg.service_configuration
321+
cfg.service_configuration # pylint: disable=pointless-statement
286322

287323

288324
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+
"""
290328
cfg = AppConfig()
291329
with pytest.raises(
292330
AssertionError, match="logic error: configuration is not loaded"
293331
):
294-
cfg.llama_stack_configuration
332+
cfg.llama_stack_configuration # pylint: disable=pointless-statement
295333

296334

297335
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+
"""
299339
cfg = AppConfig()
300340
with pytest.raises(
301341
AssertionError, match="logic error: configuration is not loaded"
302342
):
303-
cfg.user_data_collection_configuration
343+
cfg.user_data_collection_configuration # pylint: disable=pointless-statement
304344

305345

306346
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+
"""
308372
cfg = AppConfig()
309373
with pytest.raises(
310374
AssertionError, match="logic error: configuration is not loaded"
311375
):
312-
cfg.mcp_servers
376+
cfg.customization # pylint: disable=pointless-statement
313377

314378

315379
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+
"""
317386
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:
319388
fout.write("this is system prompt")
320389

321390
cfg_filename = tmpdir / "config.yaml"
322-
with open(cfg_filename, "w") as fout:
391+
with open(cfg_filename, "w", encoding="utf-8") as fout:
323392
fout.write(
324393
f"""
325394
name: test service
@@ -357,9 +426,11 @@ def test_load_configuration_with_customization_system_prompt_path(tmpdir) -> Non
357426

358427

359428
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+
"""
361432
cfg_filename = tmpdir / "config.yaml"
362-
with open(cfg_filename, "w") as fout:
433+
with open(cfg_filename, "w", encoding="utf-8") as fout:
363434
fout.write(
364435
"""
365436
name: test service

0 commit comments

Comments
 (0)