From b791817c667f85e9b58a0da79fe330bb6acbc76f Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Fri, 9 Aug 2013 11:29:24 +0200 Subject: [PATCH 1/6] Sith PEP8 --- sith.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sith.py b/sith.py index 9e15a42d..af3b9526 100755 --- a/sith.py +++ b/sith.py @@ -172,7 +172,7 @@ class TestCase(object): if os.path.abspath(completion.module_path) == os.path.abspath(self.path): self.show_location(completion.line, completion.column) - show_goto_assignments = show_goto_definitions + show_goto_assignments = show_goto_definitions def show_errors(self): print(self.traceback) @@ -181,6 +181,7 @@ class TestCase(object): "\tline: {line}\n" "\tcolumn: {column}").format(**self.__dict__)) + def main(arguments): debugger = 'pdb' if arguments['--pdb'] else \ 'ipdb' if arguments['--ipdb'] else \ @@ -191,16 +192,17 @@ def main(arguments): if arguments['--debug']: jedi.set_debug_function() - if arguments['redo'] or arguments['show']: + if arguments['redo'] or arguments['show']: t = TestCase.from_cache(record) if arguments['show']: t.show_errors() else: t.run(debugger) elif arguments['run']: - TestCase(arguments[''], arguments[''], + TestCase( + arguments[''], arguments[''], int(arguments['']), int(arguments['']) - ).run(debugger, print_result=True) + ).run(debugger, print_result=True) else: for _ in range(int(arguments['--maxtries'])): t = TestCase.generate(arguments[''] or '.') From a8bdee00513e010320b60ba3789148f727fa5a93 Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Fri, 9 Aug 2013 11:34:19 +0200 Subject: [PATCH 2/6] Fixed bug in sith.py related to recording / serialization --- sith.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sith.py b/sith.py index af3b9526..999b9973 100755 --- a/sith.py +++ b/sith.py @@ -77,6 +77,11 @@ class TestCase(object): def __init__(self, operation, path, line, column, traceback=None): if operation not in self.operations: raise ValueError("%s is not a valid operation" % operation) + + # Store call arguments + self.call_args = (operation, path, line, column, traceback) + + # Set other attributes self.operation = operation self.path = path self.line = line @@ -86,8 +91,8 @@ class TestCase(object): @classmethod def from_cache(cls, record): with open(record) as f: - dct = json.load(f) - return cls(**dct) + args = json.load(f) + return cls(*args) operations = [ 'completions', 'goto_assignments', 'goto_definitions', 'usages', @@ -124,7 +129,7 @@ class TestCase(object): self.traceback = traceback.format_exc() if record is not None: with open(record, 'w') as f: - json.dump(self.__dict__, f) + json.dump(self.call_args, f) self.show_errors() if debugger: einfo = sys.exc_info() From 2d31f33038b6113ea5b6bb70e08b98a0701ff693 Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Fri, 9 Aug 2013 13:26:11 +0200 Subject: [PATCH 3/6] Move call_args definition to recording --- sith.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sith.py b/sith.py index 999b9973..524821ce 100755 --- a/sith.py +++ b/sith.py @@ -78,9 +78,6 @@ class TestCase(object): if operation not in self.operations: raise ValueError("%s is not a valid operation" % operation) - # Store call arguments - self.call_args = (operation, path, line, column, traceback) - # Set other attributes self.operation = operation self.path = path @@ -128,8 +125,9 @@ class TestCase(object): except Exception: self.traceback = traceback.format_exc() if record is not None: + call_args = (self.operation, self.path, self.line, self.column, self.traceback) with open(record, 'w') as f: - json.dump(self.call_args, f) + json.dump(call_args, f) self.show_errors() if debugger: einfo = sys.exc_info() From 1762cb2ef84d7d3dcc96deedbe2e3c2a1c10e8b5 Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Fri, 9 Aug 2013 13:28:01 +0200 Subject: [PATCH 4/6] Added record.json to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4755f455..b4fce685 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ /docs/_build/ /dist/ jedi.egg-info/ +record.json From 78061199119c1c72da383bff49c55114c6d804db Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Fri, 9 Aug 2013 13:32:43 +0200 Subject: [PATCH 5/6] Verify that path in "random" operation is a directory --- sith.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sith.py b/sith.py index 9e15a42d..27e1c483 100755 --- a/sith.py +++ b/sith.py @@ -61,6 +61,7 @@ class SourceFinder(object): @staticmethod def fetch(file_path): + assert os.path.isdir(file_path), 'Path must be a directory, not a file.' for root, dirnames, filenames in os.walk(file_path): for name in filenames: if name.endswith('.py'): @@ -202,6 +203,9 @@ def main(arguments): int(arguments['']), int(arguments['']) ).run(debugger, print_result=True) else: + if not os.path.isdir(arguments['']): + print('Error: Path must be a directory, not a file.') + sys.exit(1) for _ in range(int(arguments['--maxtries'])): t = TestCase.generate(arguments[''] or '.') t.run(debugger, record) From b6b510693b7fbb2e284f373e1841a2a39baba4e2 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Sat, 10 Aug 2013 10:39:19 -0600 Subject: [PATCH 6/6] Make sith.py random work with files --- sith.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sith.py b/sith.py index 83e4cea6..42dbf48e 100755 --- a/sith.py +++ b/sith.py @@ -61,7 +61,9 @@ class SourceFinder(object): @staticmethod def fetch(file_path): - assert os.path.isdir(file_path), 'Path must be a directory, not a file.' + if not os.path.isdir(file_path): + yield file_path + return for root, dirnames, filenames in os.walk(file_path): for name in filenames: if name.endswith('.py'): @@ -208,9 +210,6 @@ def main(arguments): int(arguments['']), int(arguments['']) ).run(debugger, print_result=True) else: - if not os.path.isdir(arguments['']): - print('Error: Path must be a directory, not a file.') - sys.exit(1) for _ in range(int(arguments['--maxtries'])): t = TestCase.generate(arguments[''] or '.') t.run(debugger, record)