Skip to content

Commit a59ba0e

Browse files
authored
Merge pull request #233 from tisnik/lcore-303-fixed-pylint-issues
LCORE-303: fixed Pylint issues + new config tests
2 parents 0578b21 + f570ac2 commit a59ba0e

File tree

4 files changed

+60
-17
lines changed

4 files changed

+60
-17
lines changed

tests/unit/auth/test_noop_with_token.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async def test_noop_with_token_auth_dependency_no_token():
6969

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

7474
assert exc_info.value.status_code == 400
7575
assert exc_info.value.detail == "No Authorization header found"
@@ -90,7 +90,7 @@ async def test_noop_with_token_auth_dependency_no_bearer():
9090

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

9595
assert exc_info.value.status_code == 400
9696
assert exc_info.value.detail == "No token found in Authorization header"

tests/unit/auth/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Unit tests for functions defined in auth/utils.py"""
22

3-
from auth.utils import extract_user_token
43
from fastapi import HTTPException
4+
from auth.utils import extract_user_token
55

66

77
def test_extract_user_token():

tests/unit/test_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
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+
"""Test if Llama Stack can be initialized in library client mode."""
1111
cfg = LLamaStackConfiguration(
1212
url=None,
1313
api_key=None,
@@ -20,6 +20,7 @@ def test_get_llama_stack_library_client() -> None:
2020

2121

2222
def test_get_llama_stack_remote_client() -> None:
23+
"""Test if Llama Stack can be initialized in remove client (server) mode."""
2324
cfg = LLamaStackConfiguration(
2425
url="http://localhost:8321",
2526
api_key=None,
@@ -32,6 +33,7 @@ def test_get_llama_stack_remote_client() -> None:
3233

3334

3435
def test_get_llama_stack_wrong_configuration() -> None:
36+
"""Test if configuration is checked before Llama Stack is initialized."""
3537
cfg = LLamaStackConfiguration(
3638
url=None,
3739
api_key=None,
@@ -48,6 +50,7 @@ def test_get_llama_stack_wrong_configuration() -> None:
4850

4951

5052
async def test_get_async_llama_stack_library_client() -> None:
53+
"""Test the initialization of asynchronous Llama Stack client in library mode."""
5154
cfg = LLamaStackConfiguration(
5255
url=None,
5356
api_key=None,
@@ -60,6 +63,7 @@ async def test_get_async_llama_stack_library_client() -> None:
6063

6164

6265
async def test_get_async_llama_stack_remote_client() -> None:
66+
"""Test the initialization of asynchronous Llama Stack client in server mode."""
6367
cfg = LLamaStackConfiguration(
6468
url="http://localhost:8321",
6569
api_key=None,
@@ -72,6 +76,7 @@ async def test_get_async_llama_stack_remote_client() -> None:
7276

7377

7478
async def test_get_async_llama_stack_wrong_configuration() -> None:
79+
"""Test if configuration is checked before Llama Stack is initialized."""
7580
cfg = LLamaStackConfiguration(
7681
url=None,
7782
api_key=None,

tests/unit/test_configuration.py

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,49 @@
66

77

88
def test_default_configuration() -> None:
9+
"""Test that configuration attributes are not accessible for uninitialized app."""
910
cfg = AppConfig()
1011
assert cfg is not None
1112

1213
# configuration is not loaded
1314
with pytest.raises(Exception, match="logic error: configuration is not loaded"):
1415
# try to read property
15-
cfg.configuration
16+
cfg.configuration # pylint: disable=pointless-statement
1617

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

2122
with pytest.raises(Exception, match="logic error: configuration is not loaded"):
2223
# try to read property
23-
cfg.user_data_collection_configuration
24+
cfg.llama_stack_configuration # pylint: disable=pointless-statement
25+
26+
with pytest.raises(Exception, match="logic error: configuration is not loaded"):
27+
# try to read property
28+
cfg.user_data_collection_configuration # pylint: disable=pointless-statement
29+
30+
with pytest.raises(Exception, match="logic error: configuration is not loaded"):
31+
# try to read property
32+
cfg.mcp_servers # pylint: disable=pointless-statement
33+
34+
with pytest.raises(Exception, match="logic error: configuration is not loaded"):
35+
# try to read property
36+
cfg.authentication_configuration # pylint: disable=pointless-statement
37+
38+
with pytest.raises(Exception, match="logic error: configuration is not loaded"):
39+
# try to read property
40+
cfg.customization # pylint: disable=pointless-statement
2441

2542

2643
def test_configuration_is_singleton() -> None:
44+
"""Test that configuration is singleton."""
2745
cfg1 = AppConfig()
2846
cfg2 = AppConfig()
2947
assert cfg1 == cfg2
3048

3149

3250
def test_init_from_dict() -> None:
51+
"""Test the configuration initialization from dictionary with config values."""
3352
config_dict = {
3453
"name": "foo",
3554
"service": {
@@ -126,8 +145,9 @@ def test_init_from_dict_with_mcp_servers() -> None:
126145

127146

128147
def test_load_proper_configuration(tmpdir) -> None:
148+
"""Test loading proper configuration from YAML file."""
129149
cfg_filename = tmpdir / "config.yaml"
130-
with open(cfg_filename, "w") as fout:
150+
with open(cfg_filename, "w", encoding="utf-8") as fout:
131151
fout.write(
132152
"""
133153
name: foo bar baz
@@ -159,7 +179,7 @@ def test_load_proper_configuration(tmpdir) -> None:
159179
def test_load_configuration_with_mcp_servers(tmpdir) -> None:
160180
"""Test loading configuration from YAML file with MCP servers."""
161181
cfg_filename = tmpdir / "config.yaml"
162-
with open(cfg_filename, "w") as fout:
182+
with open(cfg_filename, "w", encoding="utf-8") as fout:
163183
fout.write(
164184
"""
165185
name: test service
@@ -273,7 +293,7 @@ def test_configuration_not_loaded():
273293
with pytest.raises(
274294
AssertionError, match="logic error: configuration is not loaded"
275295
):
276-
cfg.configuration
296+
cfg.configuration # pylint: disable=pointless-statement
277297

278298

279299
def test_service_configuration_not_loaded():
@@ -282,7 +302,7 @@ def test_service_configuration_not_loaded():
282302
with pytest.raises(
283303
AssertionError, match="logic error: configuration is not loaded"
284304
):
285-
cfg.service_configuration
305+
cfg.service_configuration # pylint: disable=pointless-statement
286306

287307

288308
def test_llama_stack_configuration_not_loaded():
@@ -291,7 +311,7 @@ def test_llama_stack_configuration_not_loaded():
291311
with pytest.raises(
292312
AssertionError, match="logic error: configuration is not loaded"
293313
):
294-
cfg.llama_stack_configuration
314+
cfg.llama_stack_configuration # pylint: disable=pointless-statement
295315

296316

297317
def test_user_data_collection_configuration_not_loaded():
@@ -300,7 +320,7 @@ def test_user_data_collection_configuration_not_loaded():
300320
with pytest.raises(
301321
AssertionError, match="logic error: configuration is not loaded"
302322
):
303-
cfg.user_data_collection_configuration
323+
cfg.user_data_collection_configuration # pylint: disable=pointless-statement
304324

305325

306326
def test_mcp_servers_not_loaded():
@@ -309,17 +329,35 @@ def test_mcp_servers_not_loaded():
309329
with pytest.raises(
310330
AssertionError, match="logic error: configuration is not loaded"
311331
):
312-
cfg.mcp_servers
332+
cfg.mcp_servers # pylint: disable=pointless-statement
333+
334+
335+
def test_authentication_configuration_not_loaded():
336+
"""Test that accessing authentication_configuration before loading raises an error."""
337+
cfg = AppConfig()
338+
with pytest.raises(
339+
AssertionError, match="logic error: configuration is not loaded"
340+
):
341+
cfg.authentication_configuration # pylint: disable=pointless-statement
342+
343+
344+
def test_customization_not_loaded():
345+
"""Test that accessing customization before loading raises an error."""
346+
cfg = AppConfig()
347+
with pytest.raises(
348+
AssertionError, match="logic error: configuration is not loaded"
349+
):
350+
cfg.customization # pylint: disable=pointless-statement
313351

314352

315353
def test_load_configuration_with_customization_system_prompt_path(tmpdir) -> None:
316354
"""Test loading configuration from YAML file with customization."""
317355
system_prompt_filename = tmpdir / "system_prompt.txt"
318-
with open(system_prompt_filename, "w") as fout:
356+
with open(system_prompt_filename, "w", encoding="utf-8") as fout:
319357
fout.write("this is system prompt")
320358

321359
cfg_filename = tmpdir / "config.yaml"
322-
with open(cfg_filename, "w") as fout:
360+
with open(cfg_filename, "w", encoding="utf-8") as fout:
323361
fout.write(
324362
f"""
325363
name: test service
@@ -359,7 +397,7 @@ def test_load_configuration_with_customization_system_prompt_path(tmpdir) -> Non
359397
def test_load_configuration_with_customization_system_prompt(tmpdir) -> None:
360398
"""Test loading configuration from YAML file with system_prompt in the customization."""
361399
cfg_filename = tmpdir / "config.yaml"
362-
with open(cfg_filename, "w") as fout:
400+
with open(cfg_filename, "w", encoding="utf-8") as fout:
363401
fout.write(
364402
"""
365403
name: test service

0 commit comments

Comments
 (0)