-
Notifications
You must be signed in to change notification settings - Fork 100
Created a new patchflow that can generate unit tests #998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
03a1667
initial changes
plon-Susk7 e9b54b3
Patched /home/priyash7/Desktop/open-source/patchwork/patchwork/patchf…
00a6f53
final changes
plon-Susk7 faeaca9
Merge pull request #1 from plon-Susk7/generatereadme-dev
plon-Susk7 05988b6
intermediate changes
plon-Susk7 196a00f
Merge branch 'dev' of github.com:plon-Susk7/patchwork into dev
plon-Susk7 7c5b9a6
made changes to modifyCode step
plon-Susk7 3c0eb1e
added README and fixed code
plon-Susk7 b268a82
partition changes
plon-Susk7 5b027e9
added test to CI
plon-Susk7 ff97b53
added default extension to yaml
plon-Susk7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
patchwork/patchflows/GenerateUnitTests/GenerateUnitTests.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import json | ||
| from pathlib import Path | ||
| import yaml | ||
|
|
||
| from patchwork.common.utils.step_typing import validate_steps_with_inputs | ||
| from patchwork.step import Step | ||
| from patchwork.steps import ( | ||
| LLM, | ||
| CallCode2Prompt, | ||
| ModifyCode, | ||
| PR | ||
| ) | ||
|
|
||
| _DEFAULT_INPUT_FILE = Path(__file__).parent / "defaults.yml" | ||
| _DEFAULT_PROMPT_JSON = Path(__file__).parent / "default_prompt.json" | ||
|
|
||
| class GenerateUnitTests(Step): | ||
| def __init__(self, inputs): | ||
| super().__init__(inputs) | ||
|
|
||
| final_inputs = yaml.safe_load(_DEFAULT_INPUT_FILE.read_text()) | ||
| if final_inputs is None: | ||
| final_inputs = {} | ||
|
|
||
| final_inputs.update(inputs) | ||
|
|
||
| final_inputs["prompt_id"] = "GenerateUnitTests" | ||
| if "folder_path" not in final_inputs.keys(): | ||
| final_inputs["folder_path"] = Path.cwd() | ||
| else: | ||
| final_inputs["folder_path"] = Path(final_inputs["folder_path"]) | ||
|
|
||
| if "prompt_template_file" not in final_inputs: | ||
| final_inputs["prompt_template_file"] = _DEFAULT_PROMPT_JSON | ||
|
|
||
| final_inputs["pr_title"] = f"PatchWork Unit Tests generated" | ||
| final_inputs["branch_prefix"] = f"{self.__class__.__name__.lower()}-" | ||
|
|
||
| validate_steps_with_inputs( | ||
| set(final_inputs.keys()).union({"prompt_values","files_to_patch"}), LLM, CallCode2Prompt,ModifyCode,PR | ||
| ) | ||
| self.inputs = final_inputs | ||
|
|
||
| def run(self): | ||
| outputs = CallCode2Prompt(self.inputs).run() | ||
| new_file_name = f"test_file.{self.inputs['test_file_extension']}" | ||
| new_file_path = Path(outputs['uri']).with_name(new_file_name) | ||
| Path(outputs['uri']).rename(new_file_path) | ||
| outputs['uri'] = str(new_file_path) | ||
| self.inputs["response_partitions"] = {"patch": ["```", "\n", "```"]} | ||
| self.inputs["files_to_patch"] = self.inputs["prompt_values"] = [outputs] | ||
| outputs = LLM(self.inputs).run() | ||
| self.inputs.update(outputs) | ||
| outputs = ModifyCode(self.inputs).run() | ||
| self.inputs.update(outputs) | ||
| number = len(self.inputs["modified_code_files"]) | ||
| self.inputs["pr_header"] = f"This pull request from patchwork adds tests." | ||
| outputs = PR(self.inputs).run() | ||
| self.inputs.update(outputs) | ||
|
|
||
| return self.inputs | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ## Code Documentation | ||
|
|
||
| ### Inputs | ||
| - The code reads default inputs from a YAML file (`defaults.yml`) and a JSON file (`default_prompt.json`). | ||
| - The code takes user inputs and updates the default inputs accordingly. | ||
| - The code expects inputs like `folder_path`, `prompt_template_file`, `test_file_extension`, etc. | ||
|
|
||
| ### Outputs | ||
| - The code generates unit tests based on the provided inputs. | ||
| - It creates a new test file with the specified extension. | ||
| - The code updates various parameters in the inputs dictionary during its execution. | ||
| - The final output includes the modified inputs after running the unit test generation process. |
Empty file.
15 changes: 15 additions & 0 deletions
15
patchwork/patchflows/GenerateUnitTests/default_prompt.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| [ | ||
| { | ||
| "id": "GenerateUnitTests", | ||
| "prompts": [ | ||
| { | ||
| "role": "system", | ||
| "content": "You are a senior software tester who is highly skilled at writing unit tests across various programming languages. Users will specify classes or functions to test, and you will generate appropriate unit tests using the most relevant framework for the detected language. Output the code directly with no additional text, formatting, or triple quotes. The response should appear as if directly pasted into an editor." | ||
| }, | ||
| { | ||
| "role": "user", | ||
| "content": "Code: {{fullContent}}" | ||
| } | ||
| ] | ||
| } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # CallLLM Inputs | ||
| # openai_api_key: required-for-chatgpt | ||
| # google_api_key: required-for-gemini | ||
| # model: gpt-4o | ||
| # client_base_url: https://api.openai.com/v1 | ||
| # Example HF model | ||
| # client_base_url: https://api-inference.huggingface.co/models/codellama/CodeLlama-70b-Instruct-hf/v1 | ||
| # model: codellama/CodeLlama-70b-Instruct-hf | ||
| # model_temperature: 0.2 | ||
| # model_top_p: 0.95 | ||
| # model_max_tokens: 2000 | ||
|
|
||
| # folder_path : path/to/folder/with/class | ||
|
|
||
| # Default value | ||
| test_file_extension : py | ||
|
|
||
| # CommitChanges Inputs | ||
| disable_branch: false | ||
|
|
||
| # CreatePR Inputs | ||
| disable_pr: false | ||
| force_pr_creation: true | ||
| # github_api_key: required-for-github-scm | ||
| # gitlab_api_key: required-for-gitlab-scm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.