mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
static analysis start positions are now tested
This commit is contained in:
@@ -97,14 +97,15 @@ class StaticAnalysisCase(object):
|
|||||||
def collect_comparison(self):
|
def collect_comparison(self):
|
||||||
cases = []
|
cases = []
|
||||||
for line_nr, line in enumerate(self._source.splitlines(), 1):
|
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:
|
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
|
return cases
|
||||||
|
|
||||||
def run(self, compare_cb):
|
def run(self, compare_cb):
|
||||||
analysis = jedi.Script(self._source, path=self._path)._analysis()
|
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())
|
compare_cb(self, analysis, self.collect_comparison())
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ class Cls():
|
|||||||
self.input = input
|
self.input = input
|
||||||
|
|
||||||
def f(self):
|
def f(self):
|
||||||
#! attribute-error
|
#! 12 attribute-error
|
||||||
return self.not_existing
|
return self.not_existing
|
||||||
|
|
||||||
def undefined_object(self, obj):
|
def undefined_object(self, obj):
|
||||||
@@ -20,10 +20,10 @@ class Cls():
|
|||||||
`obj` is defined by a call into this function.
|
`obj` is defined by a call into this function.
|
||||||
"""
|
"""
|
||||||
obj.upper
|
obj.upper
|
||||||
#! attribute-error
|
#! 4 attribute-error
|
||||||
obj.arbitrary_lookup
|
obj.arbitrary_lookup
|
||||||
|
|
||||||
#! name-error
|
#! 13 name-error
|
||||||
class_attr = a
|
class_attr = a
|
||||||
|
|
||||||
Cls().defined_lookup('')
|
Cls().defined_lookup('')
|
||||||
@@ -31,16 +31,16 @@ Cls().defined_lookup('')
|
|||||||
c = Cls()
|
c = Cls()
|
||||||
c.class_attr
|
c.class_attr
|
||||||
Cls.class_attr
|
Cls.class_attr
|
||||||
#! attribute-error
|
#! 4 attribute-error
|
||||||
Cls.class_attr_error
|
Cls.class_attr_error
|
||||||
c.instance_attr
|
c.instance_attr
|
||||||
#! attribute-error
|
#! 2 attribute-error
|
||||||
c.instance_attr_error
|
c.instance_attr_error
|
||||||
|
|
||||||
|
|
||||||
c.something = None
|
c.something = None
|
||||||
|
|
||||||
#! name-error
|
#! 12 name-error
|
||||||
something = a
|
something = a
|
||||||
something
|
something
|
||||||
|
|
||||||
@@ -50,28 +50,28 @@ something
|
|||||||
|
|
||||||
# should not raise anything.
|
# should not raise anything.
|
||||||
for loop_variable in [1, 2]:
|
for loop_variable in [1, 2]:
|
||||||
#! name-error
|
#! 4 name-error
|
||||||
x = undefined
|
x = undefined
|
||||||
loop_variable
|
loop_variable
|
||||||
|
|
||||||
#! name-error
|
#! 28 name-error
|
||||||
for loop_variable in [1, 2, undefined]:
|
for loop_variable in [1, 2, undefined]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
#! attribute-error
|
#! 7 attribute-error
|
||||||
[1, ''.undefined_attr]
|
[1, ''.undefined_attr]
|
||||||
|
|
||||||
|
|
||||||
def return_one(something):
|
def return_one(something):
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
#! attribute-error
|
#! 14 attribute-error
|
||||||
return_one(''.undefined_attribute)
|
return_one(''.undefined_attribute)
|
||||||
|
|
||||||
#! name-error
|
#! 12 name-error
|
||||||
[r for r in undefined]
|
[r for r in undefined]
|
||||||
|
|
||||||
#! name-error
|
#! 1 name-error
|
||||||
[undefined for r in [1, 2]]
|
[undefined for r in [1, 2]]
|
||||||
|
|
||||||
[r for r in [1, 2]]
|
[r for r in [1, 2]]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
def generator():
|
def generator():
|
||||||
yield 1
|
yield 1
|
||||||
|
|
||||||
#! type-error-generator
|
#! 11 type-error-generator
|
||||||
generator()[0]
|
generator()[0]
|
||||||
|
|
||||||
list(generator())[0]
|
list(generator())[0]
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from os.path import not_existing
|
|||||||
from datetime import date
|
from datetime import date
|
||||||
date.today
|
date.today
|
||||||
|
|
||||||
#! attribute-error
|
#! 5 attribute-error
|
||||||
date.not_existing_attribute
|
date.not_existing_attribute
|
||||||
|
|
||||||
#! import-error
|
#! import-error
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
try:
|
try:
|
||||||
#! attribute-error
|
#! 4 attribute-error
|
||||||
str.not_existing
|
str.not_existing
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
@@ -7,7 +7,7 @@ except TypeError:
|
|||||||
try:
|
try:
|
||||||
str.not_existing
|
str.not_existing
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
#! attribute-error
|
#! 4 attribute-error
|
||||||
str.not_existing
|
str.not_existing
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ except ImportError:
|
|||||||
except (NotImplementedError, AttributeError): pass
|
except (NotImplementedError, AttributeError): pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
#! attribute-error
|
#! 4 attribute-error
|
||||||
str.not_existing
|
str.not_existing
|
||||||
except (TypeError, NotImplementedError): pass
|
except (TypeError, NotImplementedError): pass
|
||||||
|
|
||||||
@@ -46,6 +46,6 @@ try:
|
|||||||
str.not_existing
|
str.not_existing
|
||||||
except ((AttributeError)): pass
|
except ((AttributeError)): pass
|
||||||
try:
|
try:
|
||||||
#! attribute-error
|
#! 4 attribute-error
|
||||||
str.not_existing
|
str.not_existing
|
||||||
except [AttributeError]: pass
|
except [AttributeError]: pass
|
||||||
|
|||||||
Reference in New Issue
Block a user