static analysis start positions are now tested

This commit is contained in:
Dave Halter
2014-05-16 15:03:59 +02:00
parent 552502a2e9
commit 0f7a17090c
5 changed files with 22 additions and 21 deletions

View File

@@ -97,14 +97,15 @@ class StaticAnalysisCase(object):
def collect_comparison(self):
cases = []
for line_nr, line in enumerate(self._source.splitlines(), 1):
match = re.match(r'\s*#! (.*)$', line)
match = re.match(r'(\s*)#! (\d+ )?(.*)$', line)
if match is not None:
cases.append((line_nr + 1, match.group(1)))
column = int(match.group(2) or 0) + len(match.group(1))
cases.append((line_nr + 1, column, match.group(3)))
return cases
def run(self, compare_cb):
analysis = jedi.Script(self._source, path=self._path)._analysis()
analysis = [(r.line, r.name) for r in analysis]
analysis = [(r.line, r.column, r.name) for r in analysis]
compare_cb(self, analysis, self.collect_comparison())
def __repr__(self):

View File

@@ -5,7 +5,7 @@ class Cls():
self.input = input
def f(self):
#! attribute-error
#! 12 attribute-error
return self.not_existing
def undefined_object(self, obj):
@@ -20,10 +20,10 @@ class Cls():
`obj` is defined by a call into this function.
"""
obj.upper
#! attribute-error
#! 4 attribute-error
obj.arbitrary_lookup
#! name-error
#! 13 name-error
class_attr = a
Cls().defined_lookup('')
@@ -31,16 +31,16 @@ Cls().defined_lookup('')
c = Cls()
c.class_attr
Cls.class_attr
#! attribute-error
#! 4 attribute-error
Cls.class_attr_error
c.instance_attr
#! attribute-error
#! 2 attribute-error
c.instance_attr_error
c.something = None
#! name-error
#! 12 name-error
something = a
something
@@ -50,28 +50,28 @@ something
# should not raise anything.
for loop_variable in [1, 2]:
#! name-error
#! 4 name-error
x = undefined
loop_variable
#! name-error
#! 28 name-error
for loop_variable in [1, 2, undefined]:
pass
#! attribute-error
#! 7 attribute-error
[1, ''.undefined_attr]
def return_one(something):
return 1
#! attribute-error
#! 14 attribute-error
return_one(''.undefined_attribute)
#! name-error
#! 12 name-error
[r for r in undefined]
#! name-error
#! 1 name-error
[undefined for r in [1, 2]]
[r for r in [1, 2]]

View File

@@ -1,7 +1,7 @@
def generator():
yield 1
#! type-error-generator
#! 11 type-error-generator
generator()[0]
list(generator())[0]

View File

@@ -11,7 +11,7 @@ from os.path import not_existing
from datetime import date
date.today
#! attribute-error
#! 5 attribute-error
date.not_existing_attribute
#! import-error

View File

@@ -1,5 +1,5 @@
try:
#! attribute-error
#! 4 attribute-error
str.not_existing
except TypeError:
pass
@@ -7,7 +7,7 @@ except TypeError:
try:
str.not_existing
except AttributeError:
#! attribute-error
#! 4 attribute-error
str.not_existing
pass
@@ -35,7 +35,7 @@ except ImportError:
except (NotImplementedError, AttributeError): pass
try:
#! attribute-error
#! 4 attribute-error
str.not_existing
except (TypeError, NotImplementedError): pass
@@ -46,6 +46,6 @@ try:
str.not_existing
except ((AttributeError)): pass
try:
#! attribute-error
#! 4 attribute-error
str.not_existing
except [AttributeError]: pass