Skip to content

Commit 83126f9

Browse files
committed
pylint near done
1 parent 59a7e79 commit 83126f9

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

.github/workflows/pylint.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ jobs:
1919
python -m pip install --upgrade pip
2020
pip install python-levenshtein
2121
pip install tabulate
22+
pip install comby
2223
pip install pylint
2324
- name: Analysing the code with pylint
2425
run: |
25-
pylint $(git ls-files '*.py') --disable C0207,C0104,C0201,W0718,C0206,C0410,C0411,W0611,C0115,W0613,C0301,C0114,C0116,C0103,W1514,R1732,W1509,R0913,R0914,R1702,R0912,R0915,R0801,R0911,R0917
26+
pylint $(git ls-files '*.py') --disable C0207,C0415,E0401,C0104,C0201,W0718,C0206,C0410,C0411,W0611,C0115,W0613,C0301,C0114,C0116,C0103,W1514,R1732,W1509,R0913,R0914,R1702,R0912,R0915,R0801,R0911,R0917

universalmutator/genmutants.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def toGarbage(code):
7777
newCode += "Q"
7878
return newCode
7979

80+
cmd = None
8081

8182
def main():
8283
global cmd
@@ -416,7 +417,7 @@ def main():
416417
if handlers[language].dumb:
417418
noFastCheck = True
418419
dumbHandler = True
419-
except:
420+
except BaseException:
420421
pass
421422
handler = handlers[language].handler
422423
else:
@@ -539,7 +540,7 @@ def main():
539540
valid_rate = 0 if totalMutants == 0 else (len(validMutants) * 100.0)/totalMutants
540541
print(f"Valid Percentage: {valid_rate}%")
541542

542-
(rules, ignoreRules, skipRules) = mutator.parseRules(rules, comby= comby)
543+
(rules, _, _) = mutator.parseRules(rules, comby= comby)
543544

544545
if printStat:
545546
source = sourceJoined if comby else None
@@ -568,10 +569,15 @@ def dumpToFile(fileName, mutants):
568569
sys.stdout.flush()
569570

570571
fis.write(f"{i}.\n")
571-
fis.write(mutant[2][0]); fis.write('\n')
572+
fis.write(mutant[2][0])
573+
fis.write('\n')
572574
if source is not None:
573-
fis.write("source:\n"); fis.write(source[mutant[0][0]:mutant[0][1]]); fis.write('\n')
574-
fis.write("mutant:\n"); fis.write(mutant[1]); fis.write('\n\n')
575+
fis.write("source:\n")
576+
fis.write(source[mutant[0][0]:mutant[0][1]])
577+
fis.write('\n')
578+
fis.write("mutant:\n")
579+
fis.write(mutant[1])
580+
fis.write('\n\n')
575581
fis.close()
576582

577583
validMutants, invalidMutants, redundantMutants = mutants
@@ -600,7 +606,7 @@ def printRulesStat(rules, validMutants, invalidMutants):
600606
table = []
601607
table.append(["#","Rule","No. of Valids", "No. of Invalids"])
602608

603-
for ((lhs, rhs), ruleUsed) in rules:
609+
for ((lhs, rhs), _) in rules:
604610
if (lhs,rhs) not in valid_cnt:
605611
valid_cnt[(lhs,rhs)] = 0
606612
if (lhs,rhs) not in invalid_cnt:

universalmutator/mutator.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def parseRules(ruleFiles, comby=False):
5353
continue # Allow blank lines and comments, just ignore lines without a transformation
5454
else:
5555
s = r.split(" ==> ")
56-
56+
5757
if comby:
5858
lhs = s[0]
5959
lhs = lhs.rstrip() # Trailing whitespace in rule file will be treated significantly unless stripped, so strip it. If matching trailing whitespace is desired, then regex holes should be used.
@@ -80,14 +80,16 @@ def parseRules(ruleFiles, comby=False):
8080

8181

8282

83-
def mutants_comby(source, ruleFiles=["universal.rules"], mutateTestCode=False, mutateBoth=False,
83+
def mutants_comby(source, ruleFiles=None, mutateTestCode=False, mutateBoth=False,
8484
ignorePatterns=None, ignoreStringOnly=False, fuzzing=False, language=".generic"):
85+
if ruleFiles is None:
86+
ruleFiles = ["universal.rules"]
8587
comby = Comby()
8688
print("MUTATING WITH RULES (COMBY):", ", ".join(ruleFiles))
87-
(rules, ignoreRules, skipRules) = parseRules(ruleFiles, True)
89+
(rules, ignoreRules, _) = parseRules(ruleFiles, True)
8890
for lhs in ignorePatterns:
89-
ignoreRules.append(lhs)
90-
source = ''.join(source)
91+
ignoreRules.append(lhs)
92+
source = ''.join(source)
9193
mutants = []
9294

9395
# Lines that match with DO_NOT_MUTATE and other ignore rules will be skipped
@@ -100,9 +102,9 @@ def mutants_comby(source, ruleFiles=["universal.rules"], mutateTestCode=False, m
100102

101103
# Instead of line-by-line x rule-by-rule iterate rule-by-rule x match-by-match.
102104
for ((lhs, rhs), ruleUsed) in rules:
103-
try:
105+
try:
104106
for match in comby.matches(source, lhs, language=language):
105-
environment = dict()
107+
environment = {}
106108
for entry in match.environment:
107109
environment[entry] = match.environment.get(entry).fragment
108110
mutant = comby.substitute(rhs, environment)
@@ -115,18 +117,20 @@ def mutants_comby(source, ruleFiles=["universal.rules"], mutateTestCode=False, m
115117
if line in ignoreLines:
116118
skipMutant = True
117119
break
118-
120+
119121
if not skipMutant:
120122
mutants.append((substitutionRange, mutant, ruleUsed, lineRange, (lhs,rhs)))
121-
except JSONDecodeError as e:
123+
except JSONDecodeError:
122124
continue
123125
except Exception as e:
124126
print(f"WARNING: Got exception {e} running rule {ruleUsed}")
125127
continue
126128
return mutants
127129

128-
def mutants(source, ruleFiles=["universal.rules"], mutateTestCode=False, mutateBoth=False,
130+
def mutants(source, ruleFiles=None, mutateTestCode=False, mutateBoth=False,
129131
ignorePatterns=None, ignoreStringOnly=False, fuzzing=False):
132+
if ruleFiles is None:
133+
ruleFiles = ["universal.rules"]
130134
print("MUTATING WITH RULES:", ", ".join(ruleFiles))
131135

132136
(rules, ignoreRules, skipRules) = parseRules(ruleFiles)
@@ -180,8 +184,8 @@ def mutants(source, ruleFiles=["universal.rules"], mutateTestCode=False, mutateB
180184
skipp = skipRule.search(l, 0)
181185
if skipp and (skipp.start() < skipPos):
182186
skipPos = skipp.start()
183-
184-
187+
188+
185189
p = lhs.search(l, 0)
186190

187191
# skip mutating if match occurs at index >= skipPos
@@ -235,7 +239,7 @@ def mutants(source, ruleFiles=["universal.rules"], mutateTestCode=False, mutateB
235239
if (mutant != l) and ((lineno, mutant) not in produced) and (not skipDueToString):
236240
mutants.append((lineno, mutant, ruleUsed, (lhs,rhs)))
237241
produced[(lineno, mutant)] = True
238-
242+
239243
p = lhs.search(l, p.start()+1) #search from the next position of the current match
240244
if abandon:
241245
break

universalmutator/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ def d(m1, m2, changeWeight=5.0, origWeight=0.1, mutantWeight=0.1, codeWeight=0.5
145145
return d
146146

147147

148-
def FPF(mlist, N, f=None, d=d, cutoff=0.0, verbose=True, avoid=[], mutantDir=None, sourceDir=None):
148+
def FPF(mlist, N, f=None, d=d, cutoff=0.0, verbose=True, avoid=None, mutantDir=None, sourceDir=None):
149+
if avoid is None:
150+
avoid = []
149151
if len(mlist) == 0:
150152
return mlist
151153
start = time.time()

0 commit comments

Comments
 (0)