1
0
forked from VimPlug/jedi

Report attacking by "."

This commit is contained in:
Takafumi Arakaki
2013-05-22 23:31:42 +02:00
parent 2dee71ff4b
commit 8bf5f9d539

33
sith.py
View File

@@ -11,6 +11,11 @@ import random
import sys
import traceback
try:
from itertools import izip as zip
except ImportError:
pass
import jedi
@@ -105,6 +110,31 @@ class MixinLoader(object):
self.load_record(record)
class AttackReporter(object):
def __init__(self):
self.tries = 0
self.errors = 0
def __iter__(self):
return self
def __next__(self):
self.tries += 1
sys.stderr.write('.')
sys.stderr.flush()
return self.tries
next = __next__
def error(self):
self.errors += 1
sys.stderr.write('\n')
sys.stderr.flush()
print('{0}th error is encountered after {1} tries.'
.format(self.errors, self.tries))
class RandomAtaccker(MixinPrinter, BaseAttacker):
operations = [
@@ -122,13 +152,16 @@ class RandomAtaccker(MixinPrinter, BaseAttacker):
def do_run(self, record, rootpath, maxtries):
finder = SourceFinder(rootpath)
reporter = AttackReporter()
for (operation, args) in self.generate_attacks(maxtries, finder):
reporter.next()
try:
self.attack(operation, *args)
except jedi.NotFoundError:
pass
except Exception:
self.add_record(sys.exc_info(), operation, args)
reporter.error()
self.print_record()
raise
self.save_record(record)