Skip to content

feat(cli): add create-tests command for autogenerating unit test stubs (#74) - #1748

Open
AlexandruAchilleF wants to merge 1 commit into
apache:mainfrom
AlexandruAchilleF:feature/cli-create-tests
Open

AlexandruAchilleF wants to merge 1 commit into
apache:mainfrom
AlexandruAchilleF:feature/cli-create-tests

Conversation

@AlexandruAchilleF

Copy link
Copy Markdown

Closes #74

Adds a new CLI command create-tests to automatically generate pytest-style unit test stubs for Hamilton functions in a specified module.

Changes

  • Implemented create_test_stubs and AST/signature inspect helpers in hamilton/cli/logic.py to scan functions and construct unit test stubs.
  • Added parameter default value generation, type hints propagation, and expected assertions (with specialized support for pandas Series/DataFrames).
  • Preserves existing test files by appending only missing tests and skipping already implemented function tests.
  • Exposed create_tests in hamilton/cli/commands.py and registered the Typer command in hamilton/cli/__main__.py.
  • Added automated unit tests in tests/cli/test_logic.py.

How I tested this

  • Ran pytest tests/cli/test_logic.py locally (all 4 tests passed).
  • Manually verified CLI generation using a sample flow file and confirmed idempotent behavior (no duplicate stubs added on subsequent runs).

Notes

N/A

Checklist

  • PR has an informative and human-readable title (this will be pulled into the release notes)
  • Changes are limited to a single goal (no scope creep)
  • Code passed the pre-commit check & code is left cleaner/nicer than when first encountered.
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future TODOs are captured in comments
  • Project documentation has been updated if adding/changing functionality.

This branch has not been deployed

No deployments
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.

Unit test stub autogenerator

1 participant