mirror of
https://github.com/davidhalter/jedi.git
synced 2026-01-28 19:52:11 +08:00
move some tests into specific directories
This commit is contained in:
0
test/evaluate/__init__.py
Normal file
0
test/evaluate/__init__.py
Normal file
39
test/evaluate/test_absolute_import.py
Normal file
39
test/evaluate/test_absolute_import.py
Normal file
@@ -0,0 +1,39 @@
|
||||
"""
|
||||
Tests ``from __future__ import absolute_import`` (only important for
|
||||
Python 2.X)
|
||||
"""
|
||||
import jedi
|
||||
from jedi.parser import Parser
|
||||
from .. import helpers
|
||||
|
||||
|
||||
def test_explicit_absolute_imports():
|
||||
"""
|
||||
Detect modules with ``from __future__ import absolute_import``.
|
||||
"""
|
||||
parser = Parser("from __future__ import absolute_import", "test.py")
|
||||
assert parser.module.has_explicit_absolute_import
|
||||
|
||||
|
||||
def test_no_explicit_absolute_imports():
|
||||
"""
|
||||
Detect modules without ``from __future__ import absolute_import``.
|
||||
"""
|
||||
parser = Parser("1", "test.py")
|
||||
assert not parser.module.has_explicit_absolute_import
|
||||
|
||||
|
||||
def test_dont_break_imports_without_namespaces():
|
||||
"""
|
||||
The code checking for ``from __future__ import absolute_import`` shouldn't
|
||||
assume that all imports have non-``None`` namespaces.
|
||||
"""
|
||||
src = "from __future__ import absolute_import\nimport xyzzy"
|
||||
parser = Parser(src, "test.py")
|
||||
assert parser.module.has_explicit_absolute_import
|
||||
|
||||
|
||||
@helpers.cwd_at("test/absolute_import")
|
||||
def test_can_complete_when_shadowing():
|
||||
script = jedi.Script(path="unittest.py")
|
||||
assert script.completions()
|
||||
36
test/evaluate/test_compiled.py
Normal file
36
test/evaluate/test_compiled.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from jedi._compatibility import builtins
|
||||
from jedi.parser.representation import Function
|
||||
from jedi.evaluate import compiled
|
||||
from jedi.evaluate import Evaluator
|
||||
|
||||
|
||||
def test_simple():
|
||||
e = Evaluator()
|
||||
bltn = compiled.CompiledObject(builtins)
|
||||
obj = compiled.CompiledObject('_str_', bltn)
|
||||
upper = e.find_types(obj, 'upper')
|
||||
assert len(upper) == 1
|
||||
objs = list(e.execute(upper[0]))
|
||||
assert len(objs) == 1
|
||||
assert objs[0].obj is str
|
||||
|
||||
|
||||
def test_fake_loading():
|
||||
assert isinstance(compiled.create(next), Function)
|
||||
|
||||
string = compiled.builtin.get_subscope_by_name('str')
|
||||
from_name = compiled._create_from_name(compiled.builtin, string, '__init__')
|
||||
assert isinstance(from_name, Function)
|
||||
|
||||
|
||||
def test_fake_docstr():
|
||||
assert compiled.create(next).docstr == next.__doc__
|
||||
|
||||
|
||||
def test_parse_function_doc_illegal_docstr():
|
||||
docstr = """
|
||||
test_func(o
|
||||
|
||||
doesn't have a closing bracket.
|
||||
"""
|
||||
assert ('', '') == compiled._parse_function_doc(docstr)
|
||||
61
test/evaluate/test_docstring.py
Normal file
61
test/evaluate/test_docstring.py
Normal file
@@ -0,0 +1,61 @@
|
||||
"""
|
||||
Testing of docstring related issues and especially ``jedi.docstrings``.
|
||||
"""
|
||||
|
||||
import jedi
|
||||
from ..helpers import unittest
|
||||
|
||||
|
||||
class TestDocstring(unittest.TestCase):
|
||||
def test_function_doc(self):
|
||||
defs = jedi.Script("""
|
||||
def func():
|
||||
'''Docstring of `func`.'''
|
||||
func""").goto_definitions()
|
||||
self.assertEqual(defs[0].raw_doc, 'Docstring of `func`.')
|
||||
|
||||
@unittest.skip('need evaluator class for that')
|
||||
def test_attribute_docstring(self):
|
||||
defs = jedi.Script("""
|
||||
x = None
|
||||
'''Docstring of `x`.'''
|
||||
x""").goto_definitions()
|
||||
self.assertEqual(defs[0].raw_doc, 'Docstring of `x`.')
|
||||
|
||||
@unittest.skip('need evaluator class for that')
|
||||
def test_multiple_docstrings(self):
|
||||
defs = jedi.Script("""
|
||||
def func():
|
||||
'''Original docstring.'''
|
||||
x = func
|
||||
'''Docstring of `x`.'''
|
||||
x""").goto_definitions()
|
||||
docs = [d.raw_doc for d in defs]
|
||||
self.assertEqual(docs, ['Original docstring.', 'Docstring of `x`.'])
|
||||
|
||||
def test_completion(self):
|
||||
assert jedi.Script('''
|
||||
class DocstringCompletion():
|
||||
#? []
|
||||
""" asdfas """''').completions()
|
||||
|
||||
def test_docstrings_type_dotted_import(self):
|
||||
s = """
|
||||
def func(arg):
|
||||
'''
|
||||
:type arg: threading.Thread
|
||||
'''
|
||||
arg."""
|
||||
names = [c.name for c in jedi.Script(s).completions()]
|
||||
assert 'start' in names
|
||||
|
||||
def test_docstrings_type_str(self):
|
||||
s = """
|
||||
def func(arg):
|
||||
'''
|
||||
:type arg: str
|
||||
'''
|
||||
arg."""
|
||||
|
||||
names = [c.name for c in jedi.Script(s).completions()]
|
||||
assert 'join' in names
|
||||
26
test/evaluate/test_imports.py
Normal file
26
test/evaluate/test_imports.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import pytest
|
||||
|
||||
import jedi
|
||||
from jedi._compatibility import find_module_py33
|
||||
from ..helpers import cwd_at
|
||||
|
||||
|
||||
@pytest.mark.skipif('sys.version_info < (3,3)')
|
||||
def test_find_module_py33():
|
||||
"""Needs to work like the old find_module."""
|
||||
print(find_module_py33('_io'))
|
||||
assert find_module_py33('_io') == (None, '_io', False)
|
||||
|
||||
|
||||
@cwd_at('test/not_in_sys_path/pkg')
|
||||
def test_import_not_in_sys_path():
|
||||
"""
|
||||
non-direct imports (not in sys.path)
|
||||
"""
|
||||
a = jedi.Script(path='module.py', line=5).goto_definitions()
|
||||
assert a[0].name == 'int'
|
||||
|
||||
a = jedi.Script(path='module.py', line=6).goto_definitions()
|
||||
assert a[0].name == 'str'
|
||||
a = jedi.Script(path='module.py', line=7).goto_definitions()
|
||||
assert a[0].name == 'str'
|
||||
Reference in New Issue
Block a user