Skip to content

Add unit tests for doctrine infrastructure #130

@monkeypants

Description

@monkeypants

Problem

The doctrine tests depend on infrastructure that has zero test coverage:

  • core/parsers/ast.py (559 lines) — AST/griffe-based class extraction
  • core/infrastructure/repositories/introspection/bounded_context.py (285 lines) — filesystem BC discovery
  • core/use_cases/generic_crud.py (106 lines) — CRUD base classes for downstream projects

If any of these have a bug, doctrine tests produce false negatives (violations
pass silently). The parser in particular is the foundation — every doctrine test
routes through it.

Proposal

Add three test files, all pure additions with no changes to existing code:

core/parsers/tests/test_ast.py

  • parse_python_classes() — finds classes in a directory of .py files
  • parse_python_classes_from_file() — single-file extraction
  • Class extraction: names, bases, fields, methods, docstrings
  • _imported_class_names() — detects re-exported Request/Response classes
  • parse_module_docstring() — extracts module-level docstrings
  • Edge cases: empty files, syntax errors, non-existent paths, _-prefixed files
  • parse_pipelines_from_file() — pipeline class detection with decorator/method checks

core/infrastructure/repositories/introspection/tests/test_bounded_context.py

  • Discovers BCs with entities/ or use_cases/ directories
  • Skips reserved words, dot-prefixed, non-packages
  • Handles nested solutions (contrib/ containing BCs)
  • Detects structural markers correctly
  • Caching and cache invalidation
  • get() by slug

core/use_cases/tests/test_generic_crud.py

  • GetUseCase._get_by_id() — returns entity, raises EntityNotFoundError
  • ListUseCase._list_all() — delegates to repo
  • CreateUseCase._create() — generates ID, builds entity, saves
  • UpdateUseCase._update_by_id() — fetches, applies model_copy, saves

All tests use tmp_path fixtures and in-memory fakes. No changes to
production code required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions