Skip to content

Commit 8062cdf

Browse files
committed
refactor: update code formatting and test structure
- Update pyproject.toml configuration - Refactor modules.py and testing.py - Update test_pytest__runtime_mode_swap.py structure - Update conftest.py configuration
1 parent da9f245 commit 8062cdf

File tree

5 files changed

+31
-37
lines changed

5 files changed

+31
-37
lines changed

pyproject.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,6 @@ ignore = [
219219
"TC003", # Move standard library import into TYPE_CHECKING block (too pedantic with __future__ annotations)
220220

221221
# "TRY300", # Consider moving this statement to an `else` block
222-
223-
# because the apathetic_utils library
224-
# specifically uses CamelCase to match the stdlib we extend,
225-
# don't complain:
226-
"N802", # invalid-function-name (function names should be lowercase)
227-
"N806", # Variable `MockBaseClass` in function should be lowercase
228-
"N815", # mixed-case-variable-in-class-scope (class variables should be lowercase)
229-
"N816", # mixed-case-variable-in-global-scope (global variables should be lowercase)
230222
]
231223

232224
[tool.ruff.lint.per-file-ignores]

src/apathetic_utils/modules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ def detect_packages_from_files( # noqa: C901, PLR0912, PLR0915
192192
# Detect all directory levels between base and file
193193
# (excluding the file itself and the base)
194194
# More than base + first level + file
195-
MIN_NESTED_PARTS = 3
196-
if len(rel_path.parts) >= MIN_NESTED_PARTS:
195+
min_nested_parts = 3
196+
if len(rel_path.parts) >= min_nested_parts:
197197
# Walk from base to file, detecting intermediate dirs
198198
current = base_path
199199
for part in rel_path.parts[:-1]: # Exclude filename

src/apathetic_utils/testing.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ def _short_path(path: str | None) -> str:
2828
if not path:
2929
return "n/a"
3030
# Use a simple approach: show last MAX_PATH_COMPONENTS or full path if shorter
31-
MAX_PATH_COMPONENTS = 3
31+
max_path_components = 3
3232
path_obj = Path(path)
3333
parts = path_obj.parts
34-
if len(parts) > MAX_PATH_COMPONENTS:
35-
return str(Path(*parts[-MAX_PATH_COMPONENTS:]))
34+
if len(parts) > max_path_components:
35+
return str(Path(*parts[-max_path_components:]))
3636
return path
3737

3838
@staticmethod
@@ -108,7 +108,7 @@ def method(self: Any, *a: Any, **kw: Any) -> Any:
108108

109109
return method
110110

111-
MockBaseClass = type(
111+
mock_base_class = type(
112112
"MockBaseClass",
113113
(),
114114
{camel_case_method_name: create_method(camel_method_unbound)},
@@ -117,11 +117,11 @@ def method(self: Any, *a: Any, **kw: Any) -> Any:
117117
# Create test class: mixin first, then base class
118118
# MRO: TestLogger -> Mixin -> MockBaseClass -> object
119119
# When super() is called from Mixin, it resolves to MockBaseClass
120-
class TestClass(mixin_class, MockBaseClass): # type: ignore[misc, valid-type]
120+
class TestClass(mixin_class, mock_base_class): # type: ignore[misc, valid-type]
121121
"""Test class with controlled MRO for super() resolution."""
122122

123123
def __init__(self) -> None:
124-
MockBaseClass.__init__(self) # type: ignore[misc]
124+
mock_base_class.__init__(self) # type: ignore[misc]
125125

126126
# Create an instance of our test class
127127
test_instance = TestClass()
@@ -134,7 +134,7 @@ def __init__(self) -> None:
134134

135135
# Mock the base class method (what super() resolves to)
136136
mock_method = MagicMock(wraps=camel_method_unbound)
137-
monkeypatch.setattr(MockBaseClass, camel_case_method_name, mock_method)
137+
monkeypatch.setattr(mock_base_class, camel_case_method_name, mock_method)
138138
# Call the snake_case method on our test instance
139139
# Some methods may raise (e.g., invalid arguments)
140140
# That's okay - we just want to verify the mock was called

tests/00_tooling/test_pytest__runtime_mode_swap.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
# Helpers
3838
# ---------------------------------------------------------------------------
3939

40-
safeTrace = mod_logging.makeSafeTrace("🪞")
40+
safe_trace = mod_logging.makeSafeTrace("🪞")
4141

4242
# Debug: show which apathetic_logging module we're using in the test
4343
mod_logging_source = getattr(mod_logging, "__file__", "unknown")
44-
safeTrace(f"🔍 test: Using apathetic_logging from: {mod_logging_source}")
44+
safe_trace(f"🔍 test: Using apathetic_logging from: {mod_logging_source}")
4545

4646
SRC_ROOT = PROJ_ROOT / "src"
4747
DIST_ROOT = PROJ_ROOT / "dist"
@@ -51,7 +51,7 @@ def list_important_modules() -> list[str]:
5151
"""Return all importable submodules under the package, if available."""
5252
important: list[str] = []
5353
if not hasattr(amod_utils_runtime, "__path__"):
54-
safeTrace("pkgutil.walk_packages skipped — standalone runtime (no __path__)")
54+
safe_trace("pkgutil.walk_packages skipped — standalone runtime (no __path__)")
5555
important.append(amod_utils_runtime.__name__)
5656
else:
5757
for _, name, _ in pkgutil.walk_packages(
@@ -67,30 +67,30 @@ def dump_snapshot(*, include_full: bool = False) -> None:
6767
"""Prints a summary of key modules and (optionally) a full sys.modules dump."""
6868
mode: str = os.getenv("RUNTIME_MODE", "installed")
6969

70-
safeTrace("========== SNAPSHOT ===========")
71-
safeTrace(f"RUNTIME_MODE={mode}")
70+
safe_trace("========== SNAPSHOT ===========")
71+
safe_trace(f"RUNTIME_MODE={mode}")
7272

7373
important_modules = list_important_modules()
7474

7575
# Summary: the modules we care about most
76-
safeTrace("======= IMPORTANT MODULES =====")
76+
safe_trace("======= IMPORTANT MODULES =====")
7777
for name in important_modules:
7878
mod = sys.modules.get(name)
7979
if not mod:
8080
continue
8181
origin = getattr(mod, "__file__", None)
82-
safeTrace(f" {name:<25} {origin}")
82+
safe_trace(f" {name:<25} {origin}")
8383

8484
if include_full:
8585
# Full origin dump
86-
safeTrace("======== OTHER MODULES ========")
86+
safe_trace("======== OTHER MODULES ========")
8787
for name, mod in sorted(sys.modules.items()):
8888
if name in important_modules:
8989
continue
9090
origin = getattr(mod, "__file__", None)
91-
safeTrace(f" {name:<38} {origin}")
91+
safe_trace(f" {name:<38} {origin}")
9292

93-
safeTrace("===============================")
93+
safe_trace("===============================")
9494

9595

9696
# ---------------------------------------------------------------------------
@@ -133,8 +133,8 @@ def test_pytest_runtime_cache_integrity() -> None:
133133
amod_utils_runtime_actual = amod_utils_runtime
134134
utils_file = str(inspect.getsourcefile(amod_utils_runtime_actual))
135135
# --- execute ---
136-
safeTrace(f"RUNTIME_MODE={mode}")
137-
safeTrace(f"{PROGRAM_PACKAGE}.runtime → {utils_file}")
136+
safe_trace(f"RUNTIME_MODE={mode}")
137+
safe_trace(f"{PROGRAM_PACKAGE}.runtime → {utils_file}")
138138

139139
if os.getenv("TRACE"):
140140
dump_snapshot()
@@ -165,16 +165,16 @@ def test_pytest_runtime_cache_integrity() -> None:
165165
else:
166166
# Module is from installed package, but that's OK as long as
167167
# detect_runtime_mode() correctly returns "standalone"
168-
safeTrace(
168+
safe_trace(
169169
f"Note: apathetic_utils.version loaded from installed package "
170170
f"({utils_file}), but runtime_mode correctly detected as 'standalone'"
171171
)
172172

173173
# troubleshooting info
174-
safeTrace(
174+
safe_trace(
175175
f"sys.modules['{PROGRAM_PACKAGE}'] = {sys.modules.get(PROGRAM_PACKAGE)}",
176176
)
177-
safeTrace(
177+
safe_trace(
178178
f"sys.modules['{PROGRAM_PACKAGE}.runtime']"
179179
f" = {sys.modules.get(f'{PROGRAM_PACKAGE}.runtime')}",
180180
)
@@ -217,7 +217,7 @@ def test_debug_dump_all_module_origins() -> None:
217217

218218
# show total module count for quick glance
219219
count = sum(1 for name in sys.modules if name.startswith(PROGRAM_PACKAGE))
220-
safeTrace(f"Loaded {count} {PROGRAM_PACKAGE} modules total")
220+
safe_trace(f"Loaded {count} {PROGRAM_PACKAGE} modules total")
221221

222222
# force visible failure for debugging runs
223223
xmsg = f"Intentional fail — {count} {PROGRAM_PACKAGE} modules listed above."

tests/conftest.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,22 @@
5252
mod_logging_source = getattr(mod_logging, "__file__", "unknown")
5353
was_in_sys_modules = False
5454

55-
safeTrace = mod_logging.makeSafeTrace("⚡️")
55+
safe_trace = mod_logging.makeSafeTrace("⚡️")
5656

5757
# Debug: show which apathetic_logging module we're using
5858
if was_in_sys_modules:
59-
safeTrace(
59+
safe_trace(
6060
f"🔍 conftest: Using apathetic_logging from sys.modules: {mod_logging_source}"
6161
)
6262
else:
63-
safeTrace(f"🔍 conftest: Imported apathetic_logging normally: {mod_logging_source}")
63+
safe_trace(
64+
f"🔍 conftest: Imported apathetic_logging normally: {mod_logging_source}"
65+
)
6466

6567
# Register a logger name so getLogger() returns a named logger (not root)
6668
# This ensures getLogger() returns a Logger instance with trace method
6769
mod_logging.registerLogger(PROGRAM_PACKAGE)
68-
safeTrace(
70+
safe_trace(
6971
f"🔍 conftest: Registered logger '{PROGRAM_PACKAGE}' "
7072
f"using apathetic_logging from: {mod_logging_source}"
7173
)

0 commit comments

Comments
 (0)