41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
import argparse
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
import instrument
|
|
|
|
ROOT_DIR = os.path.dirname(__file__)
|
|
IN_SOURCE_DIR = os.path.join(ROOT_DIR, "benchmark")
|
|
IN_TEST_DIR = os.path.join(ROOT_DIR, "tests")
|
|
OUT_DIR = os.path.join(ROOT_DIR, "tests")
|
|
|
|
|
|
def run_mutpy(test_path: str, source_path: str):
|
|
stream = os.popen(f'mut.py --target \'{source_path}\' --unit-test \'{test_path}\'')
|
|
output = stream.read()
|
|
score = re.search('Mutation score \[.*\]: (\d+\.\d+)\%', output).group(1)
|
|
print(output, file=sys.stderr)
|
|
print(f"Score is: {score}")
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(prog='muttest.py',
|
|
description='Runs MutPy over generated test suite.')
|
|
parser.add_argument('file', type=str, help="Source file to test",
|
|
nargs="*")
|
|
|
|
files = parser.parse_args().file
|
|
if len(files) == 0:
|
|
to_test = instrument.get_benchmark().keys()
|
|
else:
|
|
to_test = [os.path.splitext(os.path.basename(file))[0] for file in files]
|
|
|
|
for filename in to_test:
|
|
source_path = os.path.join(IN_SOURCE_DIR, f"{filename}.py")
|
|
test_path = os.path.join(IN_TEST_DIR, f"test_{filename}.py")
|
|
run_mutpy(test_path, source_path)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|