mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
Use locals() for tests in TestInterpreterAPI
It is better to check that Interpreter does not fail with the real name space. Previously the doctest using locals() failed because of the bug in _import_raw_namespace.
This commit is contained in:
11
jedi/api.py
11
jedi/api.py
@@ -576,17 +576,18 @@ class Interpreter(Script):
|
||||
"""
|
||||
scope = self._parser.scope
|
||||
for (variable, obj) in raw_namespace.items():
|
||||
objname = getattr(obj, '__name__', None)
|
||||
|
||||
# Import functions and classes
|
||||
module = getattr(obj, '__module__', None)
|
||||
if module:
|
||||
fakeimport = self._make_fakeimport(module, obj.__name__,
|
||||
variable)
|
||||
if module and objname:
|
||||
fakeimport = self._make_fakeimport(module, objname, variable)
|
||||
scope.add_import(fakeimport)
|
||||
continue
|
||||
|
||||
# Import modules
|
||||
if getattr(obj, '__file__', None):
|
||||
fakeimport = self._make_fakeimport(obj.__name__)
|
||||
if getattr(obj, '__file__', None) and objname:
|
||||
fakeimport = self._make_fakeimport(objname)
|
||||
scope.add_import(fakeimport)
|
||||
continue
|
||||
|
||||
|
||||
@@ -549,25 +549,28 @@ class TestInterpreterAPI(unittest.TestCase):
|
||||
self.assertEqual(sorted(actual), sorted(completions))
|
||||
|
||||
def test_complete_raw_function(self):
|
||||
from os.path import join
|
||||
self.check_interpreter_complete('join().up',
|
||||
{'join': os.path.join},
|
||||
locals(),
|
||||
['upper'])
|
||||
|
||||
def test_complete_raw_function_different_name(self):
|
||||
from os.path import join as pjoin
|
||||
self.check_interpreter_complete('pjoin().up',
|
||||
{'pjoin': os.path.join},
|
||||
locals(),
|
||||
['upper'])
|
||||
|
||||
def test_complete_raw_module(self):
|
||||
import os
|
||||
self.check_interpreter_complete('os.path.join().up',
|
||||
{'os': os},
|
||||
locals(),
|
||||
['upper'])
|
||||
|
||||
def test_complete_raw_instance(self):
|
||||
import datetime
|
||||
dt = datetime.datetime(2013, 1, 1)
|
||||
self.check_interpreter_complete('(dt - dt).ti',
|
||||
{'dt': dt},
|
||||
locals(),
|
||||
['time', 'timetz', 'timetuple'])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user