62 lines
2.2 KiB
Python
62 lines
2.2 KiB
Python
|
import argparse
|
||
|
import os
|
||
|
from mutmut.__main__ import do_run, run_mutation_tests
|
||
|
from mutmut import mutations_by_type
|
||
|
|
||
|
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_mutmut(test_path: str, source_path: str):
|
||
|
run_mutation_tests(config=config, progress=progress, mutations_by_file=mutations_by_file)
|
||
|
|
||
|
do_run(None, source_path, None, None,
|
||
|
'python -m unittest ' + test_path, os.path.dirname(test_path), 0.0, 0.0,
|
||
|
False, False, '', None, None,
|
||
|
None, '', True, False, False, True)
|
||
|
|
||
|
|
||
|
# def run_mutpy(test_path: str, source_path: str):
|
||
|
# # run_genetic([source_path], random.randint(0, 500))
|
||
|
#
|
||
|
# argv = ['-t', source_path, '-u', test_path, '-m']
|
||
|
# argv = ['-t', source_path, '-u', test_path, '-m']
|
||
|
# cfg = commandline.build_parser().parse_args(args=argv)
|
||
|
#
|
||
|
# mutation_controller = commandline.build_controller(cfg)
|
||
|
# mutation_controller.run()
|
||
|
#
|
||
|
# # stream = os.popen(f'mut.py --target \'{source_path}\' --unit-test \'{test_path}\' -m | tee log.txt')
|
||
|
# # 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='mutmuttest.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:
|
||
|
files = [os.path.splitext(f) for f in os.listdir(IN_SOURCE_DIR)]
|
||
|
to_test = [file[0] for file in files if file[1] == ".py"]
|
||
|
else:
|
||
|
to_test = [os.path.splitext(os.path.basename(file))[0] for file in files]
|
||
|
|
||
|
for filename in to_test:
|
||
|
for i in range(10):
|
||
|
source_path = os.path.join(IN_SOURCE_DIR, f"{filename}.py")
|
||
|
test_path = os.path.join(IN_TEST_DIR, f"test_{filename}.py")
|
||
|
run_mutmut(test_path, source_path)
|
||
|
break
|
||
|
break
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|