static analysis import tests

This commit is contained in:
Dave Halter
2014-05-11 15:18:48 +02:00
parent c92113a7b1
commit 7b525285bd
4 changed files with 11 additions and 8 deletions

View File

@@ -588,14 +588,12 @@ class Script(object):
def _analysis(self): def _analysis(self):
statements = set(chain(*self._parser.module().used_names.values())) statements = set(chain(*self._parser.module().used_names.values()))
for stmt in statements: for stmt in statements:
if stmt.start_pos[0] != 254:
continue
if isinstance(stmt, pr.Import): if isinstance(stmt, pr.Import):
imports.strip_imports(self._evaluator, [stmt]) imports.strip_imports(self._evaluator, [stmt])
else: else:
self._evaluator.eval_statement(stmt) self._evaluator.eval_statement(stmt)
analysis = self._evaluator.analysis analysis = [a for a in self._evaluator.analysis if self.path == a.path]
return sorted(analysis, key=lambda x: x.line) return sorted(analysis, key=lambda x: x.line)

View File

@@ -13,7 +13,7 @@ CODES = {
class Error(object): class Error(object):
def __init__(self, name, module_path, start_pos): def __init__(self, name, module_path, start_pos):
self._module_path = module_path self.path = module_path
self._start_pos = start_pos self._start_pos = start_pos
self.name = name self.name = name
@@ -39,7 +39,7 @@ class Error(object):
def __repr__(self): def __repr__(self):
return '<%s %s: %s@%s,%s' % (self.__class__.__name__, return '<%s %s: %s@%s,%s' % (self.__class__.__name__,
self.name, self._module_path, self.name, self.path,
self._start_pos[0], self._start_pos[1]) self._start_pos[0], self._start_pos[1])

View File

@@ -98,13 +98,13 @@ class StaticAnalysisCase(object):
for line_nr, line in enumerate(self._source.splitlines(), 1): for line_nr, line in enumerate(self._source.splitlines(), 1):
if line.startswith('#! '): if line.startswith('#! '):
rest = line[3:] rest = line[3:]
cases.append((line_nr, rest)) cases.append((line_nr + 1, rest))
return cases return cases
def run(self, compare_cb): def run(self, compare_cb):
analysis = jedi.Script(self._source)._analysis() analysis = jedi.Script(self._source, path=self._path)._analysis()
analysis = [(r.line, r.name) for r in analysis] analysis = [(r.line, r.name) for r in analysis]
assert compare_cb(self, analysis, self.collect_comparison()) compare_cb(self, analysis, self.collect_comparison())
def __repr__(self): def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__, os.path.basename(self._path)) return "<%s: %s>" % (self.__class__.__name__, os.path.basename(self._path))

View File

@@ -0,0 +1,5 @@
#! import-error
import not_existing
import os