forked from VimPlug/jedi
Fix a few more tests
This commit is contained in:
@@ -205,7 +205,12 @@ class CompiledObject(Context):
|
||||
)
|
||||
|
||||
def get_safe_value(self, default=_sentinel):
|
||||
return self.access.get_safe_value(default=default)
|
||||
try:
|
||||
return self.access.get_safe_value()
|
||||
except ValueError:
|
||||
if default == _sentinel:
|
||||
raise
|
||||
return default
|
||||
|
||||
def execute_operation(self, other, operator):
|
||||
return _create_from_access(
|
||||
@@ -565,8 +570,6 @@ def _create(evaluator, access, parent_context=None, faked=None):
|
||||
parent_context = create(evaluator, _builtins)
|
||||
return create(evaluator, access, parent_context)
|
||||
|
||||
if access._obj == str:
|
||||
print('OOOOOOOOOO', id(access), id(parent_context), id(faked))
|
||||
return CompiledObject(evaluator, access, parent_context, faked)
|
||||
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ def compiled_objects_cache(attribute_name):
|
||||
Caching the id has the advantage that an object doesn't need to be
|
||||
hashable.
|
||||
"""
|
||||
def wrapper(evaluator, obj):
|
||||
def wrapper(evaluator, obj, parent_context=None):
|
||||
cache = getattr(evaluator, attribute_name)
|
||||
# Do a very cheap form of caching here.
|
||||
key = id(obj)
|
||||
@@ -91,9 +91,13 @@ def compiled_objects_cache(attribute_name):
|
||||
cache[key]
|
||||
return cache[key][0]
|
||||
except KeyError:
|
||||
result = func(evaluator, obj)
|
||||
# TODO wuaaaarrghhhhhhhh
|
||||
if attribute_name == 'mixed_cache':
|
||||
result = func(evaluator, obj, parent_context)
|
||||
else:
|
||||
result = func(evaluator, obj)
|
||||
# Need to cache all of them, otherwise the id could be overwritten.
|
||||
cache[key] = result, obj
|
||||
cache[key] = result, obj, parent_context
|
||||
return result
|
||||
return wrapper
|
||||
|
||||
@@ -214,11 +218,10 @@ class DirectObjectAccess(object):
|
||||
raise
|
||||
return None
|
||||
|
||||
def get_safe_value(self, default=_sentinel):
|
||||
def get_safe_value(self):
|
||||
if type(self._obj) in (float, int, str, unicode, slice, type(Ellipsis)):
|
||||
return self._obj
|
||||
if default == _sentinel:
|
||||
raise ValueError
|
||||
raise ValueError
|
||||
|
||||
def get_api_type(self):
|
||||
obj = self._obj
|
||||
|
||||
@@ -109,7 +109,8 @@ def _load_module(evaluator, path, python_object):
|
||||
).get_root_node()
|
||||
python_module = inspect.getmodule(python_object)
|
||||
|
||||
evaluator.modules[python_module.__name__] = module
|
||||
# TODO we should actually make something like this possible.
|
||||
#evaluator.modules[python_module.__name__] = module
|
||||
return module
|
||||
|
||||
|
||||
|
||||
@@ -250,7 +250,7 @@ class DictComprehension(ArrayMixin, Comprehension):
|
||||
for keys, values in self._iterate():
|
||||
for k in keys:
|
||||
if isinstance(k, compiled.CompiledObject):
|
||||
if k.obj == index:
|
||||
if k.get_safe_value(default=object()) == index:
|
||||
return values
|
||||
return self.dict_values()
|
||||
|
||||
|
||||
@@ -229,7 +229,6 @@ def builtins_isinstance(evaluator, objects, types, arguments):
|
||||
|
||||
for cls_or_tup in types:
|
||||
if cls_or_tup.is_class():
|
||||
print(id(mro[0]), mro[0], id(cls_or_tup), cls_or_tup)
|
||||
bool_results.add(cls_or_tup in mro)
|
||||
elif cls_or_tup.name.string_name == 'tuple' \
|
||||
and cls_or_tup.get_root_context() == evaluator.BUILTINS:
|
||||
|
||||
@@ -12,32 +12,25 @@ from jedi.parser_utils import clean_scope_docstring
|
||||
from jedi import Script
|
||||
|
||||
|
||||
def _evaluator():
|
||||
return Evaluator(parso.load_grammar(), Project())
|
||||
|
||||
|
||||
def test_simple():
|
||||
e = _evaluator()
|
||||
bltn = compiled.CompiledObject(e, builtins)
|
||||
obj = compiled.CompiledObject(e, '_str_', bltn)
|
||||
def test_simple(evaluator):
|
||||
obj = compiled.create(evaluator, '_str_')
|
||||
upper, = obj.py__getattribute__('upper')
|
||||
objs = list(upper.execute_evaluated())
|
||||
assert len(objs) == 1
|
||||
assert isinstance(objs[0], instance.CompiledInstance)
|
||||
|
||||
|
||||
def test_fake_loading():
|
||||
e = _evaluator()
|
||||
assert isinstance(compiled.create(e, next), FunctionContext)
|
||||
def test_fake_loading(evaluator):
|
||||
assert isinstance(compiled.create(evaluator, next), FunctionContext)
|
||||
|
||||
builtin = compiled.get_special_object(e, 'BUILTINS')
|
||||
builtin = compiled.get_special_object(evaluator, 'BUILTINS')
|
||||
string, = builtin.py__getattribute__('str')
|
||||
from_name = compiled._create_from_name(e, builtin, string, '__init__')
|
||||
from_name = compiled._create_from_name(evaluator, builtin, string, '__init__')
|
||||
assert isinstance(from_name, FunctionContext)
|
||||
|
||||
|
||||
def test_fake_docstr():
|
||||
node = compiled.create(_evaluator(), next).tree_node
|
||||
def test_fake_docstr(evaluator):
|
||||
node = compiled.create(evaluator, next).tree_node
|
||||
assert clean_scope_docstring(node) == next.__doc__
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user