1
0
forked from VimPlug/jedi

Print the location and the completions for sith.py run

This commit is contained in:
Aaron Meurer
2013-07-28 11:43:19 -05:00
parent 1f54e71a0d
commit 607f66c974

31
sith.py
View File

@@ -95,12 +95,16 @@ class TestCase(object):
column = random.randint(0, len(lines[line - 1])) column = random.randint(0, len(lines[line - 1]))
return cls(operation, path, line, column) return cls(operation, path, line, column)
def run(self, debugger, record=None): def run(self, debugger, record=None, print_completions=False):
try: try:
with open(self.path) as f: with open(self.path) as f:
script = jedi.Script(f.read(), self.line, self.column, self.file = f.read()
self.script = jedi.Script(self.file, self.line, self.column,
self.path) self.path)
getattr(script, self.operation)() self.completions = getattr(self.script, self.operation)()
if print_completions:
self.show_location()
self.show_completions()
except jedi.NotFoundError: except jedi.NotFoundError:
pass pass
except Exception: except Exception:
@@ -108,7 +112,7 @@ class TestCase(object):
if record is not None: if record is not None:
with open(record, 'w') as f: with open(record, 'w') as f:
json.dump(self.__dict__, f) json.dump(self.__dict__, f)
self.show() self.show_errors()
if debugger: if debugger:
einfo = sys.exc_info() einfo = sys.exc_info()
pdb = __import__(debugger) pdb = __import__(debugger)
@@ -118,7 +122,20 @@ class TestCase(object):
pdb.post_mortem(einfo[2]) pdb.post_mortem(einfo[2])
exit(1) exit(1)
def show(self): def show_location(self):
# Three lines ought to be enough
show = 3
lower = self.line - show if self.line - show > 0 else 0
for i, line in enumerate(self.file.split('\n')[lower:self.line]):
print(lower + i + 1, line)
print(' '*(self.column + len(str(self.line))), '^')
def show_completions(self):
print("Completions:")
for completion in self.completions:
print(completion.name)
def show_errors(self):
print(self.traceback) print(self.traceback)
print(("Error with running Script(...).{operation}() with\n" print(("Error with running Script(...).{operation}() with\n"
"\tpath: {path}\n" "\tpath: {path}\n"
@@ -138,13 +155,13 @@ def main(arguments):
if arguments['redo'] or arguments['show']: if arguments['redo'] or arguments['show']:
t = TestCase.from_cache(record) t = TestCase.from_cache(record)
if arguments['show']: if arguments['show']:
t.show() t.show_errors()
else: else:
t.run(debugger) t.run(debugger)
elif arguments['run']: elif arguments['run']:
TestCase(arguments['<operation>'], arguments['<path>'], TestCase(arguments['<operation>'], arguments['<path>'],
int(arguments['<line>']), int(arguments['<column>']) int(arguments['<line>']), int(arguments['<column>'])
).run(debugger) ).run(debugger, print_completions=True)
else: else:
for _ in range(int(arguments['--maxtries'])): for _ in range(int(arguments['--maxtries'])):
t = TestCase.generate(arguments['<path>'] or '.') t = TestCase.generate(arguments['<path>'] or '.')