Skip to content

Commit

Permalink
Merge 180200a into 5c8b3ca
Browse files Browse the repository at this point in the history
  • Loading branch information
f-str committed May 7, 2021
2 parents 5c8b3ca + 180200a commit 1b2699e
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions mutpy/operators/misc.py
Expand Up @@ -26,23 +26,46 @@ class ConstantReplacement(MutationOperator):
FIRST_CONST_STRING = 'mutpy'
SECOND_CONST_STRING = 'python'

def mutate_Num(self, node):
return ast.Num(n=node.n + 1)

def mutate_Str(self, node):
def help_str(self, node):
if utils.is_docstring(node):
raise MutationResign()

if node.s != self.FIRST_CONST_STRING:
return ast.Str(s=self.FIRST_CONST_STRING)
return self.FIRST_CONST_STRING
else:
return ast.Str(s=self.SECOND_CONST_STRING)
return self.SECOND_CONST_STRING

def mutate_Str_empty(self, node):
def help_str_empty(self, node):
if not node.s or utils.is_docstring(node):
raise MutationResign()
return ''

def mutate_Constant_num(self, node):
if isinstance(node.value, (int, float)) and not isinstance(node.value, bool):
return ast.Constant(n=node.n + 1)
else:
raise MutationResign()

def mutate_Constant_str(self, node):
if isinstance(node.value, str):
return ast.Constant(s=self.help_str(node))
else:
raise MutationResign()

def mutate_Constant_str_empty(self, node):
if isinstance(node.value, str):
return ast.Constant(s=self.help_str_empty(node))
else:
raise MutationResign()

def mutate_Num(self, node):
return ast.Num(n=node.n + 1)

return ast.Str(s='')
def mutate_Str(self, node):
return ast.Str(s=self.help_str(node))

def mutate_Str_empty(self, node):
return ast.Str(s=self.help_str_empty(node))

@classmethod
def name(cls):
Expand Down

0 comments on commit 1b2699e

Please sign in to comment.