Skip to content

Commit 784825e

Browse files
test: clean organization in tests and update the schema
1 parent 258e15f commit 784825e

3 files changed

Lines changed: 41 additions & 120 deletions

File tree

tests/unit/test_logger.py

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
"""
2+
Unit tests for logger utilities.
3+
24
Unit test organization:
3-
- Nominal Case Tests
4-
- Negative Case Tests
5-
- Edge Case Tests
6-
- Regression Unit Tests
5+
- Nominal Case Tests: Test the nominal case where the function is expected
6+
to work correctly with typical input values.
7+
- Negative Case Tests: Test cases that involve invalid input values or
8+
scenarios where the function should handle errors gracefully.
9+
- Edge Case Tests: Test cases that involve boundary conditions or unusual
10+
input values that may not be common but should still be handled correctly
11+
by the function.
12+
- Regression Unit Tests: Test cases that ensure that previously fixed bugs
13+
do not reoccur and that existing functionality remains intact after
14+
changes to the codebase.
715
"""
816

917
from __future__ import annotations
@@ -29,8 +37,9 @@
2937
list_loggers,
3038
)
3139

40+
3241
# =============================================================================
33-
# ==== Fixtures
42+
# ==== Fixtures and Setup
3443
# =============================================================================
3544

3645
@pytest.fixture(autouse=True)
@@ -128,8 +137,9 @@ def fallback_logging_config_file(tmp_path, fallback_logging_config):
128137
return cfg
129138

130139

140+
131141
# =============================================================================
132-
# ==== Initialize Logging Tests
142+
# ==== Class Test Cases
133143
# =============================================================================
134144

135145
class TestInitializeLogging:
@@ -176,10 +186,6 @@ def test_no_duplicate_handlers(self, minimal_logging_config):
176186
assert before == after
177187

178188

179-
# =============================================================================
180-
# ==== Get Logger Tests
181-
# =============================================================================
182-
183189
class TestGetLogger:
184190
"""Tests for get_logger validation and behavior."""
185191

@@ -244,10 +250,6 @@ def test_logger_propagates_but_root_has_no_handlers(self):
244250
get_logger("test")
245251

246252

247-
# =============================================================================
248-
# ==== Configuration Behavior Tests
249-
# =============================================================================
250-
251253
class TestLoggingConfiguration:
252254
"""Tests for configuration transformations and filesystem effects."""
253255

@@ -270,10 +272,6 @@ def test_timestamped_filename(self, tmp_path, minimal_logging_config):
270272
assert len(files) > 0
271273

272274

273-
# =============================================================================
274-
# ==== Fallback Behavior Tests
275-
# =============================================================================
276-
277275
class TestFallbackBehavior:
278276
"""Tests for fallback handler behavior."""
279277

@@ -336,11 +334,6 @@ def test_no_fallback_if_root_has_handlers(self, tmp_path, monkeypatch):
336334
handler_types = {type(h).__name__ for h in root.handlers}
337335
assert handler_types == {"StreamHandler"}
338336

339-
340-
# =============================================================================
341-
# ==== Logger Introspection Tests
342-
# =============================================================================
343-
344337
class TestLoggerIntrospection:
345338
"""Tests for logger discovery utilities."""
346339

@@ -350,10 +343,6 @@ def test_list_loggers_contains_registered(self, initialized_logging):
350343
assert "test_logger" in names
351344

352345

353-
# =============================================================================
354-
# ==== Internal Coverage Tests
355-
# =============================================================================
356-
357346
class TestLoggerInternals:
358347
"""Tests targeting uncovered internal branches."""
359348

@@ -437,7 +426,7 @@ def test_initialize_logging_file_already_initialized(self, tmp_path, minimal_log
437426

438427

439428
# =============================================================================
440-
# ==== Additional Internal/Utility Tests (Missing Coverage)
429+
# ==== Function Test Cases
441430
# =============================================================================
442431

443432
def test_logfilemanager_create_log_directories(tmp_path):

tests/unit/test_schema.py

Lines changed: 12 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@
22
Unit tests for schema validation utilities.
33
44
Unit test organization:
5-
- Nominal Case Tests: Test the nominal case where the function is expected
6-
to work correctly with typical input values.
7-
8-
- Negative Case Tests: Test cases that involve invalid input values or
9-
scenarios where the function should handle errors gracefully.
10-
11-
- Edge Case Tests: Test cases that involve boundary conditions or unusual
12-
input values that may not be common but should still be handled correctly
13-
by the function.
14-
15-
- Regression Unit Tests: Test cases that ensure that previously fixed bugs
16-
do not reoccur and that existing functionality remains intact after
17-
changes to the codebase.
5+
- Nominal Case Tests: Test the nominal case where the function is expected
6+
to work correctly with typical input values.
7+
- Negative Case Tests: Test cases that involve invalid input values or
8+
scenarios where the function should handle errors gracefully.
9+
- Edge Case Tests: Test cases that involve boundary conditions or unusual
10+
input values that may not be common but should still be handled correctly
11+
by the function.
12+
- Regression Unit Tests: Test cases that ensure that previously fixed bugs
13+
do not reoccur and that existing functionality remains intact after
14+
changes to the codebase.
1815
"""
1916

2017
from __future__ import annotations
@@ -27,10 +24,7 @@
2724
from pydantic import ValidationError
2825

2926
# Local imports
30-
from pkg_infra.schema import (
31-
validate_settings,
32-
_format_validation_errors,
33-
)
27+
from pkg_infra.schema import validate_settings
3428

3529
# =============================================================================
3630
# ==== Fixtures and Setup
@@ -70,6 +64,7 @@ def valid_config_dict() -> dict[str, object]:
7064
'formatters': {},
7165
'handlers': {},
7266
'loggers': {},
67+
'filters': {},
7368
'root': {
7469
'level': 'WARNING',
7570
'handlers': [],
@@ -154,65 +149,4 @@ def test_validation_error_preserves_offending_field_name(
154149
assert 'my_custon_field_app' in str(exc_info.value)
155150

156151

157-
class TestFormatValidationErrors:
158-
"""Test cases for _format_validation_errors."""
159-
160-
# ---- Nominal Case Tests
161-
def test_single_error_is_formatted_correctly(
162-
self,
163-
valid_config_dict: dict[str, object],
164-
) -> None:
165-
"""Test that a single validation error is rendered compactly."""
166-
invalid_config = deepcopy(valid_config_dict)
167-
invalid_config['my_custon_field_app'] = {
168-
'name': 'demo',
169-
'environment': 'dev',
170-
'logger': 'default',
171-
}
172-
173-
with pytest.raises(ValidationError) as exc_info:
174-
validate_settings(invalid_config)
175-
176-
formatted_errors = _format_validation_errors(exc_info.value)
177-
178-
assert formatted_errors == [
179-
'my_custon_field_app: Extra inputs are not permitted'
180-
]
181-
182-
# ---- Edge Case Tests
183-
def test_nested_error_locations_are_formatted_with_dots(
184-
self,
185-
valid_config_dict: dict[str, object],
186-
) -> None:
187-
"""Test that nested validation locations are joined with dots."""
188-
invalid_config = deepcopy(valid_config_dict)
189-
invalid_config['app']['logger'] = 42
190-
191-
with pytest.raises(ValidationError) as exc_info:
192-
validate_settings(invalid_config)
193-
194-
formatted_errors = _format_validation_errors(exc_info.value)
195-
196-
assert formatted_errors == ['app.logger: Input should be a valid string']
197-
198-
# ---- Regression Unit Tests
199-
def test_formatted_errors_keep_exact_field_path_text(
200-
self,
201-
valid_config_dict: dict[str, object],
202-
) -> None:
203-
"""Test that formatted errors keep exact offending field names."""
204-
invalid_config = deepcopy(valid_config_dict)
205-
invalid_config['my_custon_field_app'] = {
206-
'name': 'demo',
207-
'environment': 'dev',
208-
'logger': 'default',
209-
}
210-
211-
with pytest.raises(ValidationError) as exc_info:
212-
validate_settings(invalid_config)
213-
214-
formatted_errors = _format_validation_errors(exc_info.value)
215152

216-
assert 'my_custon_field_app: Extra inputs are not permitted' in (
217-
formatted_errors
218-
)

tests/unit/test_session.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
"""
2-
Unit test organization:
3-
- Nominal Case Tests: Test the nominal case where the function is expected
4-
to work correctly with typical input values.
5-
6-
- Negative Case Tests: Test cases that involve invalid input values or
7-
scenarios where the function should handle errors gracefully.
8-
9-
- Edge Case Tests: Test cases that involve boundary conditions or unusual
10-
input values that may not be common but should still be handled correctly
11-
by the function.
12-
13-
- Regression Unit Tests: Test cases that ensure that previously fixed bugs
14-
do not reoccur and that existing functionality remains intact after
15-
changes to the codebase.
2+
Unit tests for session management utilities.
163
4+
Unit test organization:
5+
- Nominal Case Tests: Test the nominal case where the function is expected
6+
to work correctly with typical input values.
7+
- Negative Case Tests: Test cases that involve invalid input values or
8+
scenarios where the function should handle errors gracefully.
9+
- Edge Case Tests: Test cases that involve boundary conditions or unusual
10+
input values that may not be common but should still be handled correctly
11+
by the function.
12+
- Regression Unit Tests: Test cases that ensure that previously fixed bugs
13+
do not reoccur and that existing functionality remains intact after
14+
changes to the codebase.
1715
"""
1816

1917
# Standard imports

0 commit comments

Comments
 (0)