From 2dfe2de0fe6d4e3a7579049f5608d722656fc3fb Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 31 Aug 2018 01:26:20 +0200 Subject: [PATCH] Fix some stub tests --- jedi/api/helpers.py | 2 +- test/test_plugin/test_stub.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/jedi/api/helpers.py b/jedi/api/helpers.py index fda8d1c2..9e421dde 100644 --- a/jedi/api/helpers.py +++ b/jedi/api/helpers.py @@ -20,7 +20,7 @@ CompletionParts = namedtuple('CompletionParts', ['path', 'has_dot', 'name']) def sorted_definitions(defs): # Note: `or ''` below is required because `module_path` could be - return sorted(defs, key=lambda x: (x.module_path or '', x.line or 0, x.column or 0)) + return sorted(defs, key=lambda x: (x.module_path or '', x.line or 0, x.column or 0, x.name)) def get_on_completion_name(module_node, lines, position): diff --git a/test/test_plugin/test_stub.py b/test/test_plugin/test_stub.py index 1f70a5e7..25ab3189 100644 --- a/test/test_plugin/test_stub.py +++ b/test/test_plugin/test_stub.py @@ -54,8 +54,8 @@ def test_keywords_variable(Script): code = 'import keyword; keyword.kwlist' def_, = Script(code).goto_definitions() assert def_.name == 'Sequence' - # We want this to show towards the actual definition - assert typeshed._TYPESHED_PATH not in def_.module_path + # This points towards the typeshed implementation + assert typeshed._TYPESHED_PATH in def_.module_path def test_class(Script): @@ -91,9 +91,16 @@ def test_method(Script): def test_sys_exc_info(Script): - code = 'import sys; sys.exc_info()[1]' - def_, = Script(code).goto_definitions() + code = 'import sys; sys.exc_info()' + def_, none = Script(code + '[1]').goto_definitions() + # It's an optional. assert def_.name == 'BaseException' + assert def_.type == 'instance' + assert none.name == 'NoneType' + + def_, none = Script(code + '[0]').goto_definitions() + assert def_.name == 'BaseException' + assert def_.type == 'class' def test_sys_getwindowsversion(Script, environment):