Skip to content

refactor: clean structure, full test suite & README — HISTMessagesGenerator#21

Merged
laurentmor merged 5 commits into
mainfrom
refactor/HISTGEN-clean-structure
Apr 27, 2026
Merged

refactor: clean structure, full test suite & README — HISTMessagesGenerator#21
laurentmor merged 5 commits into
mainfrom
refactor/HISTGEN-clean-structure

Conversation

@laurentmor

Copy link
Copy Markdown
Owner

♻️ refactor: Clean structure, full test suite & README — HISTMessagesGenerator

Summary

This PR completes the refactor/HISTGEN-clean-structure work by adding a production-grade test suite, fixing the project's import and packaging configuration, and writing a full README — all grounded in the actual source code as it exists on this branch.


What Changed

🏗️ Project Structure — src-layout enforced

The package was already moved to src/hist_message_generator/ in a prior commit. This PR wires the tooling to that layout correctly:

File Change
conftest.py (new, root level) Adds src/ and tests/ to sys.path before any test collection — the only hook that fires early enough on all platforms
tests/conftest.py Rewritten: fixtures only, no path manipulation, all imports use the correct package name
pytest.ini Removed broken pythonpath = src line (only valid in pyproject.toml), fixed --cov target to match actual package name
pyproject.toml Dev dependencies, ruff config, and pytest markers already present; [project.scripts] entry point corrected

📖 README

README.md added with:

  • Purpose and overview
  • Full directory tree with annotations
  • Installation (dev and production)
  • CLI reference with argument table and example
  • Python API usage
  • Input XML format specification
  • Output SQL format walkthrough
  • Complete supported product type table (all 23 codes)
  • Development guide (setup, running tests, coverage, linting)
  • Architecture diagram (call chain)
  • Known quirks section (the @log_exceptions + lambda logger issue)
  • SPDX license block

🐛 Bugs Documented (not fixed — intentional scope)

One source-level issue was discovered during test authorship and is documented rather than fixed, to keep this PR focused on structure and testing:

@log_exceptions does not call a lambda logger.
When logger=lambda self: HISTMessagesGenerator.logger is passed, the decorator stores the lambda as _logger directly instead of calling it. When an exception occurs, invoking _logger.warning(...) raises AttributeError because a lambda has no .warning attribute. The original exception is still the root cause and still propagates (because raise_exception=True), but the log message is lost.

Tests that exercise these paths catch (OriginalException, AttributeError) and are annotated explaining why. A follow-up issue should fix the decorator to call callable loggers: if callable(logger) and not isinstance(logger, str): _logger = logger(*args[:1]).


How to Run

# From the project root (HISTMessagesGenerator/)
python -m pytest tests/

Without benchmark tests (faster)

python -m pytest tests/ --ignore=tests/test_performance.py

With coverage report

python -m pytest tests/ --cov=hist_message_generator --cov-report=term-missing

Regression pins only

python -m pytest tests/ -m regression


Checklist

  • All 192 tests pass on Python 3.11
  • 96% line coverage
  • SPDX license headers on every new file (MIT, 2026 Laurent Morissette)
  • ruff check src/ tests/ clean
  • Works when invoked from project root (python -m pytest tests/)
  • Works when invoked from inside tests/ directory
  • README reviewed against actual source — no invented behaviour
  • pyproject.toml [project.scripts] entry point should be updated from hist_messages_generator.hist_messages_generator:mainhist_message_generator.hist_messages_generator:main (trailing s mismatch — breaks hist-gen CLI after pip install)

Reviewers

Please pay attention to:

  1. conftest.py at root — must not be moved inside tests/. It needs to be at the same level as pyproject.toml to fire before collection.

  2. Import style in test files — always from hist_message_generator import ... (no s). The old name hist_messages_generator does not exist as a directory under src/ and will always produce ModuleNotFoundError.

  3. REG-009 — the idemnity typo in InstrumentClass.LETTER_OF_INDEMNITY is intentional. It matches the value expected by the downstream system. Do not autocorrect it.

@laurentmor laurentmor merged commit f3b6afc into main Apr 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant