hamilton
hamilton copied to clipboard
Unit test stub autogenerator
Address #74
Changes
- Added new command create-tests in cli module.
- Wrote logic for generating testcase of given python file
How I tested this
- Tested with file
test1.py
def pr(b: int, c: int) -> int:
return b + c
def divide(b: pd.Series, c: pd.Series) -> pd.Series:
return b/c
OUTPUT: test_test1.py
from pandas.core.series import Series
def test_divide():
b: Series = Series() #TODO fill in
c: Series = Series() #TODO fill in
expected: Series = Series() #TODO fill in
assert expected == test1.divide()
def test_pr():
b: int = int() #TODO fill in
c: int = int() #TODO fill in
expected: int = int() #TODO fill in
assert expected == test1.pr()
Notes
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.
@swapdewalkar thanks for this. Been a little busy so I haven't tested this out yet. @zilto if you have time mind taking it for a spin?
Yes, sorry for the delay, got sick last Wednesday, but starting to feel better. Putting this on my TODO for tomorrow morning!
Hey @swapdewalkar! I tried running hamilton create-tests
locally on a few files from examples/
and always received ModuleNotFoundError
. Looking at the code, I think it makes a few assumptions about imports that will be difficult to uphold for CLI usage.
Could you add a minimal example under examples/testgen
with a README including the steps you take for the command to work? After I'm able to try the feature, I'll have more feedback on it and the code