mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
Fix a few tests by either fixing the test cases or adding py__bool__ functions to objects that should have such a method.
This commit is contained in:
@@ -114,8 +114,10 @@ class BaseDefinition(object):
|
|||||||
... def f():
|
... def f():
|
||||||
... pass
|
... pass
|
||||||
...
|
...
|
||||||
... variable = keyword or f or C or x'''
|
... for variable in [keyword, f, C, x]:
|
||||||
>>> script = Script(source, len(source.splitlines()), 3, 'example.py')
|
... variable'''
|
||||||
|
|
||||||
|
>>> script = Script(source)
|
||||||
>>> defs = script.goto_definitions()
|
>>> defs = script.goto_definitions()
|
||||||
|
|
||||||
Before showing what is in ``defs``, let's sort it by :attr:`line`
|
Before showing what is in ``defs``, let's sort it by :attr:`line`
|
||||||
@@ -604,7 +606,7 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)):
|
|||||||
... class C:
|
... class C:
|
||||||
... pass
|
... pass
|
||||||
...
|
...
|
||||||
... variable = f or C'''
|
... variable = f if random.choice([0,1]) else C'''
|
||||||
>>> script = Script(source, column=3) # line is maximum by default
|
>>> script = Script(source, column=3) # line is maximum by default
|
||||||
>>> defs = script.goto_definitions()
|
>>> defs = script.goto_definitions()
|
||||||
>>> defs = sorted(defs, key=lambda d: d.line)
|
>>> defs = sorted(defs, key=lambda d: d.line)
|
||||||
|
|||||||
@@ -484,6 +484,9 @@ class Function(use_metaclass(CachedMetaClass, Wrapper)):
|
|||||||
else:
|
else:
|
||||||
return FunctionExecution(evaluator, self, params).get_return_types()
|
return FunctionExecution(evaluator, self, params).get_return_types()
|
||||||
|
|
||||||
|
def py__bool__(self):
|
||||||
|
return True
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
return getattr(self.base_func, name)
|
return getattr(self.base_func, name)
|
||||||
|
|
||||||
@@ -668,3 +671,6 @@ class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module, Wrapper)):
|
|||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s: %s>" % (type(self).__name__, self._module)
|
return "<%s: %s>" % (type(self).__name__, self._module)
|
||||||
|
|
||||||
|
def py__bool__(self):
|
||||||
|
return True
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ class TestRegression(TestCase):
|
|||||||
class C:
|
class C:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
variable = f or C""")
|
variable = f if random.choice([0, 1]) else C""")
|
||||||
defs = Script(source, column=3).goto_definitions()
|
defs = Script(source, column=3).goto_definitions()
|
||||||
defs = sorted(defs, key=lambda d: d.line)
|
defs = sorted(defs, key=lambda d: d.line)
|
||||||
self.assertEqual([d.description for d in defs],
|
self.assertEqual([d.description for d in defs],
|
||||||
|
|||||||
Reference in New Issue
Block a user