Test Writing Module
This module contains the CodeTester
class, which is designed to automatically generate and write test cases for given source code files. It uses a runnable chain to generate tests for either specific functions, classes, or entire code files.
Classes
CodeTester
- class CodeTester(chain)
The
CodeTester
class is responsible for initializing with a runnable chain and writing tests for code.- __init__(chain: RunnableSerializable[Dict, Any])
Initializes the
CodeTester
class with a runnable chain.- Parameters:
chain – A
RunnableSerializable
object capable of executing tasks.
- write_tests(filename: str | Path, function: str | None = None, classname: str | None = None, outfile: str | None = None)
Writes tests for the code specified in the given file by invoking the runnable chain. The tests can be generated for a specific function, class, or the entire file. The generated test code is then written to an output file.
- Parameters:
filename – The path to the code file for which tests are to be generated.
function – (Optional) The name of the function within the file to generate tests for. Default is None, indicating that tests should not be limited to a specific function.
classname – (Optional) The name of the class within the file to generate tests for. Default is None, indicating that tests should not be limited to a specific class.
outfile – (Optional) The path to the output file where the generated test code should be written. If not specified, tests are written to a default directory with a filename prefixed with
test_
.