automatic_test_case_generator¶
Automatic Test Case Generator Module.
This module provides functionality to automatically generate test case templates for Python functions using LibCST. It analyzes function definitions and generates test function skeletons that can be used as starting points for unit tests.
Example
>>> from haive.tools.toolkits.dev.python.cst_toolkit.visitors.automatic_test_case_generator import generate_tests
>>> generate_tests("/path/to/file.py")
def test_calculate_total():
# TODO: Add assertions
assert calculate_total(amount, tax_rate) is not None
- def test_format_currency():
# TODO: Add assertions assert format_currency(value, currency_symbol) is not None
Classes¶
Generates test cases from function signatures. |
Functions¶
|
Generate test case templates for functions in a Python file. |
Module Contents¶
- class automatic_test_case_generator.TestGenerator¶
Bases:
libcst.CSTVisitor
Generates test cases from function signatures.
This visitor analyzes function definitions in Python code and generates test function skeletons based on the function signatures, providing a starting point for writing unit tests.
- generate_tests() str ¶
Return the generated test cases as a string.
This method joins all the generated test function templates into a single string that can be printed or written to a file.
- Returns:
String containing all generated test function templates
- Return type:
- get_tests() list[str] ¶
Get the list of generated test function strings.
- Returns:
List of generated test function templates
- Return type:
List[str]
- visit_FunctionDef(node: libcst.FunctionDef) None ¶
Generate a basic test function based on function signature during the AST. traversal.
This method analyzes a function definition and creates a test function template with a basic assertion for the function, based on its parameters.
- Parameters:
node (cst.FunctionDef) – The function definition node being visited
- automatic_test_case_generator.generate_tests(filepath: str) str ¶
Generate test case templates for functions in a Python file.
This function analyzes a Python file, identifies all function definitions, and generates test function templates that can be used as starting points for unit tests.
- Parameters:
filepath (str) – Path to the Python file to analyze
- Returns:
String containing all generated test function templates
- Return type:
- Raises:
FileNotFoundError – If the specified file does not exist
IOError – If there are issues reading from the file