Fix some warnings.

This commit is contained in:
Dave Halter
2017-05-25 12:24:12 -04:00
parent 6a320147ac
commit ef2e2f343e
7 changed files with 20 additions and 16 deletions

View File

@@ -425,7 +425,7 @@ def defined_names(source, path=None, encoding='utf-8'):
Use :func:`names` instead. Use :func:`names` instead.
.. todo:: Remove! .. todo:: Remove!
""" """
warnings.warn("Use call_signatures instead.", DeprecationWarning) warnings.warn("Use names instead.", DeprecationWarning)
return names(source, path, encoding) return names(source, path, encoding)

View File

@@ -1,5 +1,6 @@
from textwrap import dedent from textwrap import dedent
import inspect import inspect
import warnings
from ..helpers import TestCase from ..helpers import TestCase
from jedi import Script from jedi import Script
@@ -267,12 +268,15 @@ def test_signature_is_definition():
dont_scan = ['defined_names', 'parent', 'goto_assignments', 'params'] dont_scan = ['defined_names', 'parent', 'goto_assignments', 'params']
if attr_name.startswith('_') or attr_name in dont_scan: if attr_name.startswith('_') or attr_name in dont_scan:
continue continue
attribute = getattr(definition, attr_name)
signature_attribute = getattr(signature, attr_name) # Might trigger some deprecation warnings.
if inspect.ismethod(attribute): with warnings.catch_warnings(record=True):
assert attribute() == signature_attribute() attribute = getattr(definition, attr_name)
else: signature_attribute = getattr(signature, attr_name)
assert attribute == signature_attribute if inspect.ismethod(attribute):
assert attribute() == signature_attribute()
else:
assert attribute == signature_attribute
def test_no_signature(): def test_no_signature():

View File

@@ -94,7 +94,7 @@ def test_function_call_signature_in_doc():
def f(x, y=1, z='a'): def f(x, y=1, z='a'):
pass pass
f""").goto_definitions() f""").goto_definitions()
doc = defs[0].doc doc = defs[0].docstring()
assert "f(x, y=1, z='a')" in str(doc) assert "f(x, y=1, z='a')" in str(doc)
@@ -104,7 +104,7 @@ def test_class_call_signature():
def __init__(self, x, y=1, z='a'): def __init__(self, x, y=1, z='a'):
pass pass
Foo""").goto_definitions() Foo""").goto_definitions()
doc = defs[0].doc doc = defs[0].docstring()
assert "Foo(self, x, y=1, z='a')" in str(doc) assert "Foo(self, x, y=1, z='a')" in str(doc)

View File

@@ -4,7 +4,7 @@ Tests for `api.defined_names`.
from textwrap import dedent from textwrap import dedent
from jedi import defined_names, names from jedi import names
from ..helpers import TestCase from ..helpers import TestCase
@@ -76,7 +76,7 @@ class TestDefinedNames(TestCase):
def test_follow_imports(): def test_follow_imports():
# github issue #344 # github issue #344
imp = defined_names('import datetime')[0] imp = names('import datetime')[0]
assert imp.name == 'datetime' assert imp.name == 'datetime'
datetime_names = [str(d.name) for d in imp.defined_names()] datetime_names = [str(d.name) for d in imp.defined_names()]
assert 'timedelta' in datetime_names assert 'timedelta' in datetime_names

View File

@@ -61,7 +61,7 @@ class TestFullDefinedName(TestCase):
""" """
def check(self, source, desired): def check(self, source, desired):
definitions = jedi.defined_names(textwrap.dedent(source)) definitions = jedi.names(textwrap.dedent(source))
full_names = [d.full_name for d in definitions] full_names = [d.full_name for d in definitions]
self.assertEqual(full_names, desired) self.assertEqual(full_names, desired)

View File

@@ -20,7 +20,7 @@ class TestDocstring(unittest.TestCase):
def func(): def func():
'''Docstring of `func`.''' '''Docstring of `func`.'''
func""").goto_definitions() func""").goto_definitions()
self.assertEqual(defs[0].raw_doc, 'Docstring of `func`.') self.assertEqual(defs[0].docstring(raw=True), 'Docstring of `func`.')
@unittest.skip('need evaluator class for that') @unittest.skip('need evaluator class for that')
def test_attribute_docstring(self): def test_attribute_docstring(self):
@@ -28,7 +28,7 @@ class TestDocstring(unittest.TestCase):
x = None x = None
'''Docstring of `x`.''' '''Docstring of `x`.'''
x""").goto_definitions() x""").goto_definitions()
self.assertEqual(defs[0].raw_doc, 'Docstring of `x`.') self.assertEqual(defs[0].docstring(raw=True), 'Docstring of `x`.')
@unittest.skip('need evaluator class for that') @unittest.skip('need evaluator class for that')
def test_multiple_docstrings(self): def test_multiple_docstrings(self):
@@ -38,7 +38,7 @@ class TestDocstring(unittest.TestCase):
x = func x = func
'''Docstring of `x`.''' '''Docstring of `x`.'''
x""").goto_definitions() x""").goto_definitions()
docs = [d.raw_doc for d in defs] docs = [d.docstring(raw=True) for d in defs]
self.assertEqual(docs, ['Original docstring.', 'Docstring of `x`.']) self.assertEqual(docs, ['Original docstring.', 'Docstring of `x`.'])
def test_completion(self): def test_completion(self):

View File

@@ -18,7 +18,7 @@ def test_keyword():
""" github jedi-vim issue #44 """ """ github jedi-vim issue #44 """
defs = Script("print").goto_definitions() defs = Script("print").goto_definitions()
if is_py3: if is_py3:
assert [d.doc for d in defs] assert [d.docstring() for d in defs]
else: else:
assert defs == [] assert defs == []