Skip to content

Conversation

@robtaylor
Copy link
Contributor

Summary

This PR adds doctest infrastructure to validate code examples in the documentation and fixes the existing failing test.

Branched from: refactor/restructure-codebase (as requested)

Changes Made

Phase 1: Fix Existing Failing Test ✅

  • Fixed import path in chipflow-toml-guide.rst doctest
  • Changed from chipflow_lib.config to chipflow_lib.config.parser
  • Existing doctest now passes

Phase 2: Add Doctest Infrastructure ✅

  • Added doctest_global_setup in docs/conf.py
  • Provides common imports for all doctest blocks:
    • Amaranth modules (Module, wiring, In, Out, etc.)
    • ChipFlow signatures (UART, GPIO, SPI, etc.)
    • Other common utilities
  • Reduces boilerplate in test examples

Phase 3: Convert Strategic Examples ✅

  • Converted 2 complete examples from .. code-block:: to .. testcode::
  • Added assertions to verify classes can be instantiated
  • Examples chosen: complete, self-contained, using only public APIs
  • Examples converted:
    • using-pin-signatures.rst: MySoC basic example
    • architecture.rst: MySoC with elaborate() example

Phase 4: Document Testing Strategy ✅

  • Added comprehensive comments in conf.py explaining the approach
  • Clarified when to use testcode vs code-block
  • Documented selective testing philosophy

Testing Strategy

The approach balances automatic validation with documentation readability:

  1. Complete, runnable examples use .. testcode:: → validated automatically
  2. Illustrative fragments remain as .. code-block:: → kept for readability
  3. Global setup provides common imports → reduces boilerplate

Test Results

All doctests pass:

Doctest summary
===============
    3 tests
    0 failures in tests
    0 failures in setup code
    0 failures in cleanup code

Run tests with: pdm test-docs

Benefits

✅ Code examples are automatically validated against API changes
✅ CI can catch documentation that breaks with code changes
✅ Maintains documentation readability (no excessive test boilerplate)
✅ Clear guidance for contributors on which examples to test

What's Not Tested

By design, the following remain as illustrative code-block examples:

  • Incomplete code fragments (partial __init__ calls, etc.)
  • Examples requiring external deps (chipflow_digital_ip)
  • Pseudo-code/conceptual illustrations
  • Implementation details (internal APIs)

This keeps docs readable while ensuring core public API examples are validated.

🤖 Generated with Claude Code

@github-actions
Copy link

github-actions bot commented Oct 26, 2025

Tests Skipped Failures Errors Time
41 4 💤 0 ❌ 0 🔥 20.972s ⏱️

@robtaylor robtaylor force-pushed the refactor/restructure-codebase branch 2 times, most recently from fba3cf5 to fd3a449 Compare October 26, 2025 23:52
@robtaylor robtaylor force-pushed the feature/doctest-improvements branch from fbb8f64 to 4e33f5b Compare October 27, 2025 21:17
@github-actions
Copy link

github-actions bot commented Oct 27, 2025

PR Preview Action v1.6.2

🚀 View preview at
https://chipflow-lib.docs.chipflow-infra.com/pr-preview/pr-145/

Built to branch gh-pages at 2025-10-28 14:31 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@robtaylor robtaylor force-pushed the refactor/restructure-codebase branch 2 times, most recently from 95acef4 to 126bd42 Compare October 28, 2025 12:51
@robtaylor robtaylor force-pushed the feature/doctest-improvements branch from 4e33f5b to 4a33a0d Compare October 28, 2025 13:28
@robtaylor robtaylor force-pushed the refactor/restructure-codebase branch from b568bf8 to 1dc2906 Compare October 28, 2025 13:39
@robtaylor robtaylor force-pushed the feature/doctest-improvements branch from 4a33a0d to 9cc71c3 Compare October 28, 2025 13:40
@robtaylor robtaylor force-pushed the refactor/restructure-codebase branch from 1dc2906 to 8397916 Compare October 28, 2025 13:56
robtaylor and others added 3 commits October 28, 2025 13:56
Phase 1 & 2 of doctest improvements:
- Fix import path in chipflow-toml-guide.rst doctest (_parse_config_file from config.parser)
- Add doctest_global_setup in conf.py with common imports for test examples
- Existing doctest now passes

The global setup imports common modules (Amaranth, ChipFlow signatures) so
that doctests can focus on demonstrating API usage without repetitive imports.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Phase 3 of doctest improvements:
- Convert complete MySoC examples to testcode blocks with assertions
- Two examples converted: using-pin-signatures.rst and architecture.rst
- Examples now validate that classes can be instantiated correctly
- All doctests pass (3 tests total)

Strategy: Convert only complete, self-contained examples that use documented
public APIs. Keep illustrative fragments as code-block for readability.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Phase 4 of doctest improvements:
- Add detailed comments in conf.py explaining testing philosophy
- Clarify when to use testcode vs code-block
- Document the selective testing approach for maintainability
- Provide guidance for future contributors

The strategy balances automatic validation with documentation readability,
testing complete examples while keeping fragments illustrative.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@robtaylor robtaylor force-pushed the feature/doctest-improvements branch 2 times, most recently from 62987f9 to e7ef8c3 Compare October 28, 2025 14:23
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.

2 participants