From 99b1ad18b411645bd8c5db37fc138b9d728311a7 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 18 Apr 2014 15:10:57 +0200 Subject: [PATCH] test for davidhalter/jedi-vim#268, Definition objects should be unique per position. This was fixed a few commits ago by the whole usage fixes. --- test/test_api/test_api.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/test_api/test_api.py b/test/test_api/test_api.py index 3b0c3363..a32edd98 100644 --- a/test/test_api/test_api.py +++ b/test/test_api/test_api.py @@ -2,6 +2,8 @@ Test all things related to the ``jedi.api`` module. """ +from textwrap import dedent + from jedi import api from pytest import raises @@ -102,3 +104,26 @@ def test_goto_assignments_on_non_statement(): with raises(api.NotFoundError): api.Script('assert').goto_assignments() + + +def test_goto_definition_not_multiple(): + """ + There should be only one Definition result if it leads back to the same + origin (e.g. instance method) + """ + + s = dedent('''\ + import random + class A(): + def __init__(self, a): + self.a = 3 + + def foo(self): + pass + + if random.randint(0, 1): + a = A(2) + else: + a = A(1) + a''') + assert len(api.Script(s).goto_definitions()) == 1