-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support generating reliability test programs and inputs (#1802)
* Commit Signed-off-by: dbczumar <[email protected]> * fix Signed-off-by: dbczumar <[email protected]> * fix Signed-off-by: dbczumar <[email protected]> * fix Signed-off-by: dbczumar <[email protected]> * fix Signed-off-by: dbczumar <[email protected]> * fix Signed-off-by: dbczumar <[email protected]> --------- Signed-off-by: dbczumar <[email protected]>
- Loading branch information
Showing
8 changed files
with
888 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 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 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,38 @@ | ||
import os | ||
from typing import List, Optional | ||
|
||
from tests.reliability.generate.utils import ( | ||
GeneratedTestCase, | ||
generate_test_inputs, | ||
generate_test_program, | ||
load_generated_cases, | ||
load_generated_program, | ||
) | ||
|
||
|
||
def generate_test_cases( | ||
dst_path: str, | ||
num_inputs: int = 1, | ||
program_instructions: Optional[str] = None, | ||
input_instructions: Optional[str] = None, | ||
) -> List[GeneratedTestCase]: | ||
os.makedirs(dst_path, exist_ok=True) | ||
if _directory_contains_program(dst_path): | ||
print(f"Found an existing test program at path {dst_path}. Generating new" f" test inputs for this program.") | ||
else: | ||
print("Generating a new test program and test inputs") | ||
generate_test_program( | ||
dst_path=dst_path, | ||
additional_instructions=program_instructions, | ||
) | ||
generate_test_inputs( | ||
dst_path=os.path.join(dst_path, "inputs"), | ||
program_path=os.path.join(dst_path, "program.py"), | ||
num_inputs=num_inputs, | ||
additional_instructions=input_instructions, | ||
) | ||
return load_generated_cases(dir_path=dst_path) | ||
|
||
|
||
def _directory_contains_program(dir_path: str) -> bool: | ||
return any(file == "program.py" for file in os.listdir(dir_path)) |
This file contains 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,29 @@ | ||
import argparse | ||
|
||
from tests.reliability.generate import generate_test_cases | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser( | ||
description="Generate test cases by specifying configuration and input instructions." | ||
) | ||
parser.add_argument( | ||
"-d", "--dst_path", type=str, required=True, help="Destination path where generated test cases will be saved." | ||
) | ||
parser.add_argument( | ||
"-n", "--num_inputs", type=int, default=1, help="Number of input cases to generate (default: 1)." | ||
) | ||
parser.add_argument( | ||
"-p", "--program_instructions", type=str, help="Additional instructions for the generated test program." | ||
) | ||
parser.add_argument( | ||
"-i", "--input_instructions", type=str, help="Additional instructions for generating test inputs." | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
generate_test_cases( | ||
dst_path=args.dst_path, | ||
num_inputs=args.num_inputs, | ||
program_instructions=args.program_instructions, | ||
input_instructions=args.input_instructions, | ||
) |
Oops, something went wrong.