Skip to content

Commit 7b29914

Browse files
authored
Merge pull request lightspeed-core#1457 from tisnik/lcore-1609-improved-docstrings-in-unit-tests
LCORE-1608: improved docstrings in unit tests
2 parents a01d45e + 61ffa8c commit 7b29914

25 files changed

Lines changed: 507 additions & 54 deletions

tests/unit/models/config/test_authentication_configuration.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,17 @@ def test_authentication_configuration_rh_identity_one_entitlement() -> None:
115115

116116

117117
def test_authentication_configuration_rh_identity_more_entitlements() -> None:
118-
"""Test the AuthenticationConfiguration with RH identity token."""
118+
"""Test the AuthenticationConfiguration with RH identity token.
119+
120+
Verify AuthenticationConfiguration accepts an RH Identity configuration
121+
with multiple required entitlements.
122+
123+
Asserts that the configuration's module is set to RH Identity, the provided
124+
RHIdentityConfiguration is attached and returned by the
125+
rh_identity_configuration property, the required_entitlements list is
126+
preserved as ["foo", "bar", "baz"], and TLS/Kubernetes-related fields and
127+
the skip_for_health_probes flag match the inputs.
128+
"""
119129
auth_config = AuthenticationConfiguration(
120130
module=AUTH_MOD_RH_IDENTITY,
121131
skip_tls_verification=False,
@@ -369,7 +379,15 @@ def test_authentication_configuration_skip_readiness_probe() -> None:
369379

370380

371381
def test_authentication_configuration_in_config_k8s() -> None:
372-
"""Test the authentication configuration in main config."""
382+
"""Test the authentication configuration in main config.
383+
384+
Verify K8S authentication settings are preserved when embedded in the main Configuration.
385+
386+
Asserts that the configuration's authentication section uses the K8S module
387+
and that the following fields match the provided values:
388+
`skip_tls_verification` is True, `k8s_ca_cert_path` equals
389+
Path("tests/configuration/server.crt"), and `k8s_cluster_api` is None.
390+
"""
373391
# pylint: disable=no-member
374392
cfg = Configuration(
375393
name="test_name",
@@ -584,6 +602,12 @@ def test_rh_identity_max_header_size_validation(
584602
585603
Verify that PositiveInt accepts valid custom values and rejects zero and
586604
negative values.
605+
606+
Parameters:
607+
- max_header_size (int): The max header size to validate.
608+
- expectation (AbstractContextManager): A context manager that asserts
609+
either successful construction or that a ValidationError is raised
610+
for invalid values.
587611
"""
588612
with expectation:
589613
config = RHIdentityConfiguration(max_header_size=max_header_size)

tests/unit/models/config/test_byok_rag.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@
1515

1616

1717
def test_byok_rag_configuration_default_values() -> None:
18-
"""Test the ByokRag constructor."""
18+
"""Test the ByokRag constructor.
19+
20+
Verify that ByokRag initializes correctly when only required fields are provided.
21+
22+
Asserts that the instance stores the given `rag_id`, `vector_db_id`, and
23+
`db_path`, and that unspecified fields use the module's default values for
24+
`rag_type`, `embedding_model`, `embedding_dimension`, and
25+
`score_multiplier`.
26+
"""
1927
byok_rag = ByokRag( # pyright: ignore[reportCallIssue]
2028
rag_id="rag_id",
2129
vector_db_id="vector_db_id",
@@ -58,7 +66,13 @@ def test_byok_rag_configuration_nondefault_values() -> None:
5866

5967

6068
def test_byok_rag_configuration_wrong_dimension() -> None:
61-
"""Test the ByokRag constructor."""
69+
"""Test the ByokRag constructor.
70+
71+
Verify constructing ByokRag with embedding_dimension less than or equal to
72+
zero raises a ValidationError.
73+
74+
The raised ValidationError's message must contain "should be greater than 0".
75+
"""
6276
with pytest.raises(ValidationError, match="should be greater than 0"):
6377
_ = ByokRag(
6478
rag_id="rag_id",
@@ -71,7 +85,13 @@ def test_byok_rag_configuration_wrong_dimension() -> None:
7185

7286

7387
def test_byok_rag_configuration_empty_rag_id() -> None:
74-
"""Test the ByokRag constructor."""
88+
"""Test the ByokRag constructor.
89+
90+
Validate that constructing a ByokRag with an empty `rag_id` raises a validation error.
91+
92+
Expects a `pydantic.ValidationError` whose message contains "String should
93+
have at least 1 character".
94+
"""
7595
with pytest.raises(
7696
ValidationError, match="String should have at least 1 character"
7797
):
@@ -108,7 +128,13 @@ def test_byok_rag_configuration_empty_rag_type() -> None:
108128

109129

110130
def test_byok_rag_configuration_empty_embedding_model() -> None:
111-
"""Test the ByokRag constructor."""
131+
"""Test the ByokRag constructor.
132+
133+
Verify that constructing a ByokRag with an empty `embedding_model` raises a validation error.
134+
135+
Expects a pydantic.ValidationError whose message contains "String should
136+
have at least 1 character".
137+
"""
112138
with pytest.raises(
113139
ValidationError, match="String should have at least 1 character"
114140
):
@@ -123,7 +149,13 @@ def test_byok_rag_configuration_empty_embedding_model() -> None:
123149

124150

125151
def test_byok_rag_configuration_empty_vector_db_id() -> None:
126-
"""Test the ByokRag constructor."""
152+
"""Test the ByokRag constructor.
153+
154+
Ensure constructing a ByokRag with an empty `vector_db_id` raises a ValidationError.
155+
156+
Asserts that Pydantic validation fails with a message containing "String
157+
should have at least 1 character".
158+
"""
127159
with pytest.raises(
128160
ValidationError, match="String should have at least 1 character"
129161
):

tests/unit/models/config/test_conversation_history.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,17 @@ def test_conversation_cache_no_type_but_configured(subtests: SubTests) -> None:
120120

121121

122122
def test_conversation_cache_multiple_configurations(subtests: SubTests) -> None:
123-
"""Test how multiple configurations are handled."""
123+
"""Test how multiple configurations are handled.
124+
125+
Verify that selecting a cache type while providing multiple backend
126+
configurations raises validation errors.
127+
128+
Asserts that constructing ConversationHistoryConfiguration with more than
129+
one backend config fails and produces the specific validation messages:
130+
- For memory type: "Only memory cache config must be provided"
131+
- For SQLite type: "Only SQLite cache config must be provided"
132+
- For PostgreSQL type: "Only PostgreSQL cache config must be provided"
133+
"""
124134
d = PostgreSQLDatabaseConfiguration(
125135
db="db",
126136
user="user",

tests/unit/models/config/test_customization.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,30 @@ def test_service_customization(subtests: SubTests) -> None:
5858

5959

6060
def test_service_customization_wrong_system_prompt_path() -> None:
61-
"""Check the service customization class."""
61+
"""Check the service customization class.
62+
63+
Verify that providing a non-existent `system_prompt_path` raises a `ValidationError`.
64+
65+
Asserts that constructing `Customization` with a path that does not point
66+
to a file raises `pydantic.ValidationError` with a message matching "Path
67+
does not point to a file".
68+
"""
6269
with pytest.raises(ValidationError, match="Path does not point to a file"):
6370
_ = Customization(system_prompt_path=Path("/path/does/not/exists"))
6471

6572

6673
def test_service_customization_correct_system_prompt_path(subtests: SubTests) -> None:
67-
"""Check the service customization class."""
74+
"""Check the service customization class.
75+
76+
Validate that Customization loads system_prompt from a provided file for
77+
both single-line and multi-line prompts.
78+
79+
One subtest verifies that a one-line prompt file yields the exact string
80+
"This is system prompt." Another subtest verifies that a multi-line prompt
81+
file is loaded and contains the expected substrings: "You are OpenShift
82+
Lightspeed", "Here are your instructions", and "Here are some basic facts
83+
about OpenShift".
84+
"""
6885
with subtests.test(msg="One line system prompt"):
6986
# pass a file containing system prompt
7087
c = Customization(

tests/unit/models/config/test_database_configuration.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ def test_database_configuration(subtests: SubTests) -> None:
4343

4444

4545
def test_no_databases_configuration() -> None:
46-
"""Test if no databases configuration is checked."""
46+
"""Test if no databases configuration is checked.
47+
48+
Verify default database selection and error behavior when no database
49+
configuration is present.
50+
51+
Asserts that a newly constructed DatabaseConfiguration defaults to SQLite
52+
(db_type == "sqlite"), and that if both `sqlite` and `postgres` are set to
53+
None, accessing the `db_type` or `config` properties raises a `ValueError`
54+
with message "No database configuration found".
55+
"""
4756
d = DatabaseConfiguration() # pyright: ignore[reportCallIssue]
4857
assert d is not None
4958

tests/unit/models/config/test_inference_configuration.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ def test_inference_default_model_missing() -> None:
4141

4242
def test_inference_default_provider_missing() -> None:
4343
"""
44-
Test case where only default model is set, should fail
44+
Test case where only default model is set, should fail.
45+
46+
Checks that constructing InferenceConfiguration with only `default_model`
47+
set raises a ValueError.
48+
49+
Asserts the error message equals "Default provider must be specified when
50+
default model is set".
4551
"""
4652
with pytest.raises(
4753
ValueError,

tests/unit/models/config/test_jwt_role_rule.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ def test_jwt_role_rule_no_roles_specified() -> None:
7272

7373

7474
def test_jwt_role_rule_star_role_specified() -> None:
75-
"""Check the JwtRoleRule config class."""
75+
"""Check the JwtRoleRule config class.
76+
77+
Asserts that specifying the wildcard '*' role in JwtRoleRule raises a ValidationError.
78+
79+
Instantiates JwtRoleRule with roles=['*'] and expects a ValidationError
80+
whose message contains "The wildcard role is not allowed in role
81+
rules".
82+
"""
7683
with pytest.raises(
7784
ValidationError, match="The wildcard '\\*' role is not allowed in role rules"
7885
):

tests/unit/models/config/test_llama_stack_configuration.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,16 @@ def test_llama_stack_wrong_configuration_constructor_library_mode_off() -> None:
8383

8484

8585
def test_llama_stack_wrong_configuration_no_config_file() -> None:
86-
"""Test the LlamaStackConfiguration constructor."""
86+
"""Test the LlamaStackConfiguration constructor.
87+
88+
Verify that enabling library-client mode without providing a configuration
89+
file path raises a ValueError.
90+
91+
Asserts that constructing LlamaStackConfiguration with
92+
use_as_library_client=True and no library_client_config_path raises a
93+
ValueError whose message is "Llama stack library client mode is enabled but
94+
a configuration file path is not specified".
95+
"""
8796
m = "Llama stack library client mode is enabled but a configuration file path is not specified"
8897
with pytest.raises(ValueError, match=m):
8998
LlamaStackConfiguration(

tests/unit/models/config/test_model_context_protocol_server.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,15 @@ def test_configuration_multiple_mcp_servers() -> None:
145145
def test_model_context_protocol_server_with_authorization_headers(
146146
tmp_path: Path,
147147
) -> None:
148-
"""Test ModelContextProtocolServer with authorization headers."""
148+
"""Test ModelContextProtocolServer with authorization headers.
149+
150+
Verify that authorization headers supplied as file paths are preserved and resolved.
151+
152+
Creates temporary files for header secrets, constructs a ModelContextProtocolServer with
153+
authorization_headers mapping header names to those file paths, and asserts that:
154+
- the model retains the original mapping to file paths, and
155+
- resolved_authorization_headers contains the file contents for each header.
156+
"""
149157
auth_file = tmp_path / "auth.txt"
150158
auth_file.write_text("my-secret")
151159
api_key_file = tmp_path / "api_key.txt"

tests/unit/models/config/test_postgresql_database_configuration.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,16 @@ def test_postgresql_database_configuration() -> None:
3232

3333

3434
def test_postgresql_database_configuration_namespace_specification() -> None:
35-
"""Test the PostgreSQLDatabaseConfiguration model."""
35+
"""Test the PostgreSQLDatabaseConfiguration model.
36+
37+
Verify that an explicit `namespace` is preserved and other fields use their defaults.
38+
39+
Asserts that providing `namespace="foo"` results in `namespace` set to
40+
"foo", `host` defaulting to "localhost", `port` defaulting to 5432, `db`
41+
and `user` preserved, `password` stored as a secret whose
42+
`get_secret_value()` returns the original, `ssl_mode` and `gss_encmode`
43+
matching their PostgreSQL defaults, and `ca_cert_path` being `None`.
44+
"""
3645
# pylint: disable=no-member
3746
c = PostgreSQLDatabaseConfiguration(
3847
db="db", user="user", password="password", namespace="foo"

0 commit comments

Comments
 (0)