mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
documentation and clean up, #181
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
"""
|
||||||
|
A helper module for testing, improves compatibility for testing (as
|
||||||
|
``jedi._compatibility``) as well as introducing helper functions.
|
||||||
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
if sys.hexversion < 0x02070000:
|
if sys.hexversion < 0x02070000:
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
"""
|
||||||
|
Test all things related to the ``jedi.api`` module.
|
||||||
|
"""
|
||||||
|
|
||||||
import jedi
|
import jedi
|
||||||
from jedi import common
|
from jedi import common
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
""" Test all things related to the ``jedi.api_classes`` module.
|
||||||
|
"""
|
||||||
|
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@@ -5,6 +8,7 @@ import pytest
|
|||||||
from jedi import api
|
from jedi import api
|
||||||
import jedi
|
import jedi
|
||||||
|
|
||||||
|
|
||||||
def test_is_keyword():
|
def test_is_keyword():
|
||||||
results = jedi.Script('import ', 1, 1, None).goto_definitions()
|
results = jedi.Script('import ', 1, 1, None).goto_definitions()
|
||||||
assert len(results) == 1 and results[0].is_keyword == True
|
assert len(results) == 1 and results[0].is_keyword == True
|
||||||
@@ -57,3 +61,21 @@ def make_definitions():
|
|||||||
def test_basedefinition_type(definition):
|
def test_basedefinition_type(definition):
|
||||||
assert definition.type in ('module', 'class', 'instance', 'function',
|
assert definition.type in ('module', 'class', 'instance', 'function',
|
||||||
'generator', 'statement', 'import', 'param')
|
'generator', 'statement', 'import', 'param')
|
||||||
|
|
||||||
|
|
||||||
|
def test_function_call_signature_in_doc():
|
||||||
|
defs = jedi.Script("""
|
||||||
|
def f(x, y=1, z='a'):
|
||||||
|
pass
|
||||||
|
f""").goto_definitions()
|
||||||
|
doc = defs[0].doc
|
||||||
|
assert "f(x, y = 1, z = 'a')" in doc
|
||||||
|
|
||||||
|
def test_class_call_signature():
|
||||||
|
defs = jedi.Script("""
|
||||||
|
class Foo:
|
||||||
|
def __init__(self, x, y=1, z='a'):
|
||||||
|
pass
|
||||||
|
Foo""").goto_definitions()
|
||||||
|
doc = defs[0].doc
|
||||||
|
assert "Foo(self, x, y = 1, z = 'a')" in doc
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
"""
|
||||||
|
Test all things related to the ``jedi.cache`` module.
|
||||||
|
"""
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
"""
|
||||||
|
Testing of docstring related issues and especially ``jedi.docstrings``.
|
||||||
|
"""
|
||||||
|
|
||||||
import jedi
|
import jedi
|
||||||
from .base import unittest
|
from .base import unittest
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
from .base import cwd_at
|
"""
|
||||||
|
Tests of various import related things that could not be tested with "Black Box
|
||||||
|
Tests".
|
||||||
|
"""
|
||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
from jedi import Script
|
from jedi import Script
|
||||||
|
from .base import cwd_at
|
||||||
|
|
||||||
|
|
||||||
def test_goto_definition_on_import():
|
def test_goto_definition_on_import():
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
"""
|
||||||
|
Test of keywords and ``jedi.keywords``
|
||||||
|
"""
|
||||||
import jedi
|
import jedi
|
||||||
from jedi import Script, common
|
from jedi import Script, common
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
from .base import unittest
|
"""
|
||||||
|
Tests of ``jedi.api.Interpreter``.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .base import TestCase
|
||||||
import jedi
|
import jedi
|
||||||
from jedi._compatibility import is_py33
|
from jedi._compatibility import is_py33
|
||||||
|
|
||||||
|
|
||||||
class TestInterpreterAPI(unittest.TestCase):
|
class TestInterpreterAPI(TestCase):
|
||||||
def check_interpreter_complete(self, source, namespace, completions,
|
def check_interpreter_complete(self, source, namespace, completions,
|
||||||
**kwds):
|
**kwds):
|
||||||
script = jedi.Interpreter(source, [namespace], **kwds)
|
script = jedi.Interpreter(source, [namespace], **kwds)
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
Unit tests to avoid errors of the past. Makes use of Python's ``unittest``
|
Unit tests to avoid errors of the past. These are also all tests that didn't
|
||||||
module.
|
found a good place in any other testing module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
from .base import unittest, cwd_at
|
from .base import TestCase, cwd_at
|
||||||
|
|
||||||
import jedi
|
import jedi
|
||||||
from jedi import Script
|
from jedi import Script
|
||||||
from jedi import api, parsing, common
|
from jedi import api, parsing
|
||||||
|
|
||||||
#jedi.set_debug_function(jedi.debug.print_to_stdout)
|
#jedi.set_debug_function(jedi.debug.print_to_stdout)
|
||||||
|
|
||||||
|
|
||||||
class TestRegression(unittest.TestCase):
|
class TestRegression(TestCase):
|
||||||
def test_goto_definition_cursor(self):
|
def test_goto_definition_cursor(self):
|
||||||
|
|
||||||
s = ("class A():\n"
|
s = ("class A():\n"
|
||||||
@@ -59,23 +59,6 @@ class TestRegression(unittest.TestCase):
|
|||||||
assert len(r) == 1
|
assert len(r) == 1
|
||||||
assert len(r[0].doc) > 100
|
assert len(r[0].doc) > 100
|
||||||
|
|
||||||
def test_function_call_signature(self):
|
|
||||||
defs = Script("""
|
|
||||||
def f(x, y=1, z='a'):
|
|
||||||
pass
|
|
||||||
f""").goto_definitions()
|
|
||||||
doc = defs[0].doc
|
|
||||||
assert "f(x, y = 1, z = 'a')" in doc
|
|
||||||
|
|
||||||
def test_class_call_signature(self):
|
|
||||||
defs = Script("""
|
|
||||||
class Foo:
|
|
||||||
def __init__(self, x, y=1, z='a'):
|
|
||||||
pass
|
|
||||||
Foo""").goto_definitions()
|
|
||||||
doc = defs[0].doc
|
|
||||||
assert "Foo(self, x, y = 1, z = 'a')" in doc
|
|
||||||
|
|
||||||
def test_goto_definition_at_zero(self):
|
def test_goto_definition_at_zero(self):
|
||||||
assert Script("a", 1, 1).goto_definitions() == []
|
assert Script("a", 1, 1).goto_definitions() == []
|
||||||
s = Script("str", 1, 1).goto_definitions()
|
s = Script("str", 1, 1).goto_definitions()
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
|
"""
|
||||||
|
Speed tests of Jedi. To prove that certain things don't take longer than they
|
||||||
|
should.
|
||||||
|
"""
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
from .base import unittest
|
from .base import TestCase
|
||||||
import jedi
|
import jedi
|
||||||
|
|
||||||
class TestSpeed(unittest.TestCase):
|
class TestSpeed(TestCase):
|
||||||
def _check_speed(time_per_run, number=4, run_warm=True):
|
def _check_speed(time_per_run, number=4, run_warm=True):
|
||||||
""" Speed checks should typically be very tolerant. Some machines are
|
""" Speed checks should typically be very tolerant. Some machines are
|
||||||
faster than others, but the tests should still pass. These tests are
|
faster than others, but the tests should still pass. These tests are
|
||||||
|
|||||||
Reference in New Issue
Block a user