run black reformatter

pull/2302/head
bohendo 9 months ago
parent e47f4e1b94
commit 924252e420
No known key found for this signature in database
  1. 38
      slither/tools/mutator/__main__.py
  2. 20
      slither/tools/mutator/mutators/abstract_mutator.py
  3. 1
      slither/tools/mutator/utils/file_handling.py
  4. 9
      slither/tools/mutator/utils/testing_generated_mutant.py

@ -200,7 +200,7 @@ def main() -> (None): # pylint: disable=too-many-statements,too-many-branches,t
# run and time tests, abort if they're broken
start_time = time.time()
if not run_test_cmd(test_command, None, None): # no timeout or target_file during the first run
if not run_test_cmd(test_command, None, None): # no timeout or target_file during the first run
logger.error(red("Test suite fails before mutation, aborting"))
return
elapsed_time = round(time.time() - start_time)
@ -212,10 +212,18 @@ def main() -> (None): # pylint: disable=too-many-statements,too-many-branches,t
else:
timeout = int(timeout)
if timeout < elapsed_time:
logger.info(red(f"Provided timeout {timeout} is too short for tests that run in {elapsed_time} seconds"))
logger.info(
red(
f"Provided timeout {timeout} is too short for tests that run in {elapsed_time} seconds"
)
)
return
logger.info(green(f"Test suite passes in {elapsed_time} seconds, commencing mutation campaign with a timeout of {timeout} seconds\n"))
logger.info(
green(
f"Test suite passes in {elapsed_time} seconds, commencing mutation campaign with a timeout of {timeout} seconds\n"
)
)
for filename in sol_file_list: # pylint: disable=too-many-nested-blocks
file_name = os.path.split(filename)[1].split(".sol")[0]
@ -278,18 +286,34 @@ def main() -> (None): # pylint: disable=too-many-statements,too-many-branches,t
total_mutant_counts[0] += total_counts[0]
uncaught_mutant_counts[0] += uncaught_counts[0]
if verbose:
logger.info(magenta(f"Mutator {m.NAME} found {uncaught_counts[0]} uncaught revert mutants (out of {total_counts[0]} that compile)"))
logger.info(
magenta(
f"Mutator {m.NAME} found {uncaught_counts[0]} uncaught revert mutants (out of {total_counts[0]} that compile)"
)
)
elif m.NAME == "CR":
total_mutant_counts[1] += total_counts[1]
uncaught_mutant_counts[1] += uncaught_counts[1]
if verbose:
logger.info(magenta(f"Mutator {m.NAME} found {uncaught_counts[1]} uncaught comment mutants (out of {total_counts[1]} that compile)"))
logger.info(
magenta(
f"Mutator {m.NAME} found {uncaught_counts[1]} uncaught comment mutants (out of {total_counts[1]} that compile)"
)
)
else:
total_mutant_counts[2] += total_counts[2]
uncaught_mutant_counts[2] += uncaught_counts[2]
if verbose:
logger.info(magenta(f"Mutator {m.NAME} found {uncaught_counts[2]} uncaught tweak mutants (out of {total_counts[2]} that compile)"))
logger.info(magenta(f"Running total: found {uncaught_mutant_counts[2]} uncaught tweak mutants (out of {total_mutant_counts[2]} that compile)"))
logger.info(
magenta(
f"Mutator {m.NAME} found {uncaught_counts[2]} uncaught tweak mutants (out of {total_counts[2]} that compile)"
)
)
logger.info(
magenta(
f"Running total: found {uncaught_mutant_counts[2]} uncaught tweak mutants (out of {total_mutant_counts[2]} that compile)"
)
)
dont_mutate_lines = lines_list
if comprehensive_flag:

@ -81,7 +81,7 @@ class AbstractMutator(
logger.debug("No patches found by %s", self.NAME)
return ([0, 0, 0], [0, 0, 0], self.dont_mutate_line)
for file in all_patches["patches"]: # Note: This should only loop over a single file
for file in all_patches["patches"]: # Note: This should only loop over a single file
original_txt = self.slither.source_code[file].encode("utf8")
patches = all_patches["patches"][file]
patches.sort(key=lambda x: x["start"])
@ -131,14 +131,16 @@ class AbstractMutator(
if self.very_verbose:
if self.NAME == "RR":
logger.info(f"Found {self.uncaught_mutant_counts[0]} uncaught revert mutants so far (out of {self.total_mutant_counts[0]} that compile)")
logger.info(
f"Found {self.uncaught_mutant_counts[0]} uncaught revert mutants so far (out of {self.total_mutant_counts[0]} that compile)"
)
elif self.NAME == "CR":
logger.info(f"Found {self.uncaught_mutant_counts[1]} uncaught comment mutants so far (out of {self.total_mutant_counts[1]} that compile)")
logger.info(
f"Found {self.uncaught_mutant_counts[1]} uncaught comment mutants so far (out of {self.total_mutant_counts[1]} that compile)"
)
else:
logger.info(f"Found {self.uncaught_mutant_counts[2]} uncaught tweak mutants so far (out of {self.total_mutant_counts[2]} that compile)")
logger.info(
f"Found {self.uncaught_mutant_counts[2]} uncaught tweak mutants so far (out of {self.total_mutant_counts[2]} that compile)"
)
return (
self.total_mutant_counts,
self.uncaught_mutant_counts,
self.dont_mutate_line
)
return (self.total_mutant_counts, self.uncaught_mutant_counts, self.dont_mutate_line)

@ -49,6 +49,7 @@ def transfer_and_delete(files_dict: Dict) -> None:
global_counter = {}
def create_mutant_file(file: str, rule: str) -> None:
"""function to create new mutant file"""
try:

@ -45,7 +45,7 @@ def run_test_cmd(cmd: str, timeout: int | None, target_file: str | None) -> bool
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
timeout=timeout,
check=False # True: Raises a CalledProcessError if the return code is non-zero
check=False, # True: Raises a CalledProcessError if the return code is non-zero
)
except subprocess.TimeoutExpired:
@ -68,6 +68,7 @@ def run_test_cmd(cmd: str, timeout: int | None, target_file: str | None) -> bool
return False
# return 0 if uncaught, 1 if caught, and 2 if compilation fails
def test_patch( # pylint: disable=too-many-arguments
file: str,
@ -99,7 +100,7 @@ def test_patch( # pylint: disable=too-many-arguments
)
)
reset_file(file)
return 0 # uncaught
return 0 # uncaught
else:
if very_verbose:
logger.info(
@ -109,7 +110,7 @@ def test_patch( # pylint: disable=too-many-arguments
)
reset_file(file)
return 2 # compile failure
return 2 # compile failure
if verbose:
logger.info(
@ -119,4 +120,4 @@ def test_patch( # pylint: disable=too-many-arguments
)
reset_file(file)
return 1 # caught
return 1 # caught

Loading…
Cancel
Save