pyggi.patch module¶
This module contains Patch class.
-
class
pyggi.patch.
Patch
(program)[source]¶ Bases:
object
Patch is a sequence of edit operators: both atomic and custom. During search iteration, PYGGI modifies the source code of the target program by applying a candidate patch. Subsequently, it runs the test script to collect dynamic information, such as the execution time or any other user-provided properties, via the predefined format that PYGGI recognises.
-
add
(edit)[source]¶ Add an edit to the edit list
Parameters: edit ( atomic_operator.AtomicOperator
orcustom_operator.CustomOperator
) – The edit to be addedReturns: None
-
apply
()[source]¶ This method applies the patch to the target program. It does not directly modify the source code of the original program, but modifies the copied program within the temporary directory.
Returns: The contents of the patch-applied program, See Hint. Return type: dict(str, list(str)) Hint
- key: The target file name(path) related to the program root path
- value: The contents of the file
-
clone
()[source]¶ Create a new patch which has the same sequence of edits with the current one.
Returns: The created Patch Return type: Patch
-
diff
¶ Compare the source codes of original program and the patch-applied program using difflib module(https://docs.python.org/3.6/library/difflib.html).
Returns: The file comparison result Return type: str
-
get_atomics
(atomic_class_name=None)[source]¶ Combine all the atomic operators of the edits. A custom operator is originally a sequence of atomic operators, and a patch is a sequence of the edits. So this is a sort of flattening process.
Returns: The atomic operators, see Hint. Return type: list( atomic_operator.AtomicOperator
)
-
remove
(index: int)[source]¶ Remove an edit from the edit list
Parameters: index (int) – The index of edit to delete
-
run_test
(timeout=15, result_parser=<bound method TestResult.pyggi_result_parser of <class 'pyggi.test_result.TestResult'>>)[source]¶ Run the test script provided by the user which is placed within the project directory.
Parameters: - timeout (float) – The time limit of test run (unit: seconds)
- result_parser (None or callable((str, str),
TestResult
)) – The parser of test output (default:TestResult.pyggi_result_parser()
)
Returns: The parsed output of test script execution
Return type:
-