import textwrap

import jedi
from jedi import api_classes
from .base import TestBase


class MixinTestFullName(object):

    def check(self, source, desired):
        definitions = self.get_definitions(textwrap.dedent(source))
        self.assertEqual(definitions[0].full_name, desired)

    def test_os_path_join(self):
        self.check('import os; os.path.join', 'os.path.join')

    def test_builtin(self):
        self.check('type', 'type')

    def test_from_import(self):
        self.check('from os import path', 'os.path')


class TestFullNameWithGotoDefinitions(MixinTestFullName, TestBase):

    get_definitions = TestBase.goto_definitions

    def test_tuple_mapping(self):
        self.check("""
        import re
        any_re = re.compile('.*')
        any_re""", 're.RegexObject')


class TestFullNameWithCompletions(MixinTestFullName, TestBase):
    get_definitions = TestBase.completions


class TestFullDefinedName(TestBase):

    def check(self, source, desired):
        definitions = jedi.defined_names(textwrap.dedent(source))
        full_names = [d.full_name for d in definitions]
        self.assertEqual(full_names, desired)

    def test_local_names(self):
        self.check("""
        def f(): pass
        class C: pass
        """, ['f', 'C'])

    def test_imports(self):
        self.check("""
        import os
        from os import path
        from os.path import join
        from os import path as opath
        """, ['os', 'os.path', 'os.path.join', 'os.path'])


def test_keyword_full_name_should_be_none():
    """issue #94"""
    # Using `from jedi.keywords import Keyword` here does NOT work
    # in Python 3.  This is due to the import hack jedi using.
    Keyword = api_classes.keywords.Keyword
    d = api_classes.Definition(Keyword('(', (0, 0)))
    assert d.full_name is None

@@ -1,123 +1,682 @@
-import textwrap%0A%0Aimport jedi%0Afrom jedi import api_classes%0Afrom .base import TestBase%0A%0A%0Aclass MixinTestFullName(object):
+%22%22%22%0ATests for :attr:%60.BaseDefinition.full_name%60.%0A%0AThere are three kinds of test:%0A%0A#. Test classes derived from :class:%60MixinTestFullName%60.%0A   Child class defines :meth:%60.get_definitions%60 to alter how%0A   the api definition instance is created.%0A%0A#. :class:%60TestFullDefinedName%60 is to test combination of%0A   :attr:%60.full_name%60 and :func:%60.defined_names%60.%0A%0A#. Misc single-function tests.%0A%0A%22%22%22%0A%0Aimport textwrap%0A%0Aimport jedi%0Afrom jedi import api_classes%0Afrom .base import TestBase%0A%0A%0Aclass MixinTestFullName(object):%0A%0A    def get_definitions(self, source):%0A        %22%22%22%0A        Get definition objects of the variable at the end of %60source%60.%0A        %22%22%22%0A        raise NotImplementedError
 %0A%0A  
@@ -1496,24 +1496,112 @@
 TestBase):%0A%0A
+    %22%22%22%0A    Test combination of :attr:%60.full_name%60 and :func:%60.defined_names%60.%0A    %22%22%22%0A%0A
     def chec

Document test_full_name.py