Merge pull request #101 from PR0M3TH3AN/codex/update-logging-configuration-and-format-files

Tweak logging for tests
This commit is contained in:
thePR0M3TH3AN
2025-07-01 15:26:53 -04:00
committed by GitHub
7 changed files with 55 additions and 22 deletions

View File

@@ -1,6 +1,7 @@
[pytest]
log_cli = true
log_cli_level = INFO
log_cli_level = WARNING
log_level = WARNING
testpaths = src/tests
markers =
network: tests that require network connectivity

View File

@@ -21,17 +21,21 @@ try:
# -----------------------------------
APP_DIR = Path.home() / ".seedpass"
APP_DIR.mkdir(exist_ok=True, parents=True) # Ensure the directory exists
logging.info(f"Application directory created at {APP_DIR}")
if logger.isEnabledFor(logging.DEBUG):
logger.info(f"Application directory created at {APP_DIR}")
except Exception as e:
logging.error(f"Failed to create application directory: {e}")
logging.error(traceback.format_exc()) # Log full traceback
if logger.isEnabledFor(logging.DEBUG):
logger.error(f"Failed to create application directory: {e}")
logger.error(traceback.format_exc()) # Log full traceback
try:
PARENT_SEED_FILE = APP_DIR / "parent_seed.enc" # Encrypted parent seed
logging.info(f"Parent seed file path set to {PARENT_SEED_FILE}")
if logger.isEnabledFor(logging.DEBUG):
logger.info(f"Parent seed file path set to {PARENT_SEED_FILE}")
except Exception as e:
logging.error(f"Error setting file paths: {e}")
logging.error(traceback.format_exc()) # Log full traceback
if logger.isEnabledFor(logging.DEBUG):
logger.error(f"Error setting file paths: {e}")
logger.error(traceback.format_exc()) # Log full traceback
# -----------------------------------
# Checksum Files for Integrity
@@ -40,10 +44,12 @@ try:
SCRIPT_CHECKSUM_FILE = (
APP_DIR / "seedpass_script_checksum.txt"
) # Checksum for main script
logging.info(f"Checksum file path set: Script {SCRIPT_CHECKSUM_FILE}")
if logger.isEnabledFor(logging.DEBUG):
logger.info(f"Checksum file path set: Script {SCRIPT_CHECKSUM_FILE}")
except Exception as e:
logging.error(f"Error setting checksum file paths: {e}")
logging.error(traceback.format_exc()) # Log full traceback
if logger.isEnabledFor(logging.DEBUG):
logger.error(f"Error setting checksum file paths: {e}")
logger.error(traceback.format_exc()) # Log full traceback
# -----------------------------------
# Password Generation Constants

View File

@@ -3,12 +3,16 @@
import logging
import traceback
logger = logging.getLogger(__name__)
try:
from .bip85 import BIP85
logging.info("BIP85 module imported successfully.")
if logger.isEnabledFor(logging.DEBUG):
logger.info("BIP85 module imported successfully.")
except Exception as e:
logging.error(f"Failed to import BIP85 module: {e}")
logging.error(traceback.format_exc()) # Log full traceback
if logger.isEnabledFor(logging.DEBUG):
logger.error(f"Failed to import BIP85 module: {e}")
logger.error(traceback.format_exc()) # Log full traceback
__all__ = ["BIP85"]

7
src/tests/conftest.py Normal file
View File

@@ -0,0 +1,7 @@
import logging
import pytest
@pytest.fixture(autouse=True)
def mute_logging():
logging.getLogger().setLevel(logging.WARNING)

View File

@@ -19,14 +19,22 @@ def _try_lock(path: Path, wait_time: mp.Value):
wait_time.value = time.perf_counter() - t0
def test_exclusive_lock_blocks_until_released(tmp_path: Path):
def test_exclusive_lock_blocks_until_released(tmp_path: Path) -> None:
file_path = tmp_path / "locktest.txt"
started = mp.Event()
wait_time = mp.Value("d", 0.0)
# Use 'fork' start method when available for more deterministic timing on
# platforms like macOS where the default 'spawn' method can delay process
# startup significantly.
if "fork" in mp.get_all_start_methods():
ctx = mp.get_context("fork")
else:
ctx = mp.get_context()
p1 = mp.Process(target=_hold_lock, args=(file_path, 1.0, started))
p2 = mp.Process(target=_try_lock, args=(file_path, wait_time))
started = ctx.Event()
wait_time = ctx.Value("d", 0.0)
p1 = ctx.Process(target=_hold_lock, args=(file_path, 1.0, started))
p2 = ctx.Process(target=_try_lock, args=(file_path, wait_time))
p1.start()
started.wait()

View File

@@ -2,6 +2,7 @@ import builtins
from itertools import cycle
import pytest
import logging
from utils import password_prompt
@@ -15,10 +16,12 @@ def test_prompt_new_password(monkeypatch):
assert result == "goodpass"
def test_prompt_new_password_retry(monkeypatch):
def test_prompt_new_password_retry(monkeypatch, caplog):
seq = iter(["pass1", "pass2", "passgood", "passgood"])
monkeypatch.setattr(password_prompt.getpass, "getpass", lambda prompt: next(seq))
caplog.set_level(logging.WARNING)
result = password_prompt.prompt_new_password()
assert "User entered a password shorter" in caplog.text
assert result == "passgood"

View File

@@ -3,6 +3,8 @@
import logging
import traceback
logger = logging.getLogger(__name__)
try:
from .file_lock import exclusive_lock, shared_lock
from .key_derivation import (
@@ -15,10 +17,12 @@ try:
from .checksum import calculate_checksum, verify_checksum
from .password_prompt import prompt_for_password
logging.info("Modules imported successfully.")
if logger.isEnabledFor(logging.DEBUG):
logger.info("Modules imported successfully.")
except Exception as e:
logging.error(f"Failed to import one or more modules: {e}")
logging.error(traceback.format_exc()) # Log full traceback
if logger.isEnabledFor(logging.DEBUG):
logger.error(f"Failed to import one or more modules: {e}")
logger.error(traceback.format_exc()) # Log full traceback
__all__ = [
"derive_key_from_password",