From 45432c6cb038f1af5672d3d550d4a0762092d0a4 Mon Sep 17 00:00:00 2001 From: David Halter Date: Wed, 7 Aug 2013 18:26:41 +0430 Subject: [PATCH] documentation and clean up, #181 --- test/base.py | 5 +++++ test/test_api.py | 4 ++++ test/test_api_classes.py | 22 ++++++++++++++++++++++ test/test_cache.py | 4 ++++ test/test_docstring.py | 4 ++++ test/test_integration_import.py | 6 +++++- test/test_integration_keyword.py | 3 +++ test/test_interpreter.py | 8 ++++++-- test/test_regression.py | 27 +++++---------------------- test/test_speed.py | 9 +++++++-- 10 files changed, 65 insertions(+), 27 deletions(-) diff --git a/test/base.py b/test/base.py index a162c82b..111b859b 100644 --- a/test/base.py +++ b/test/base.py @@ -1,3 +1,8 @@ +""" +A helper module for testing, improves compatibility for testing (as +``jedi._compatibility``) as well as introducing helper functions. +""" + import sys if sys.hexversion < 0x02070000: import unittest2 as unittest diff --git a/test/test_api.py b/test/test_api.py index f63f90c0..4fd34e9e 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -1,3 +1,7 @@ +""" +Test all things related to the ``jedi.api`` module. +""" + import jedi from jedi import common diff --git a/test/test_api_classes.py b/test/test_api_classes.py index 714a11ef..70d89972 100644 --- a/test/test_api_classes.py +++ b/test/test_api_classes.py @@ -1,3 +1,6 @@ +""" Test all things related to the ``jedi.api_classes`` module. +""" + import textwrap import pytest @@ -5,6 +8,7 @@ import pytest from jedi import api import jedi + def test_is_keyword(): results = jedi.Script('import ', 1, 1, None).goto_definitions() assert len(results) == 1 and results[0].is_keyword == True @@ -57,3 +61,21 @@ def make_definitions(): def test_basedefinition_type(definition): assert definition.type in ('module', 'class', 'instance', 'function', '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 diff --git a/test/test_cache.py b/test/test_cache.py index ef9851bc..463fb8a1 100644 --- a/test/test_cache.py +++ b/test/test_cache.py @@ -1,3 +1,7 @@ +""" +Test all things related to the ``jedi.cache`` module. +""" + import time import pytest diff --git a/test/test_docstring.py b/test/test_docstring.py index dc013d22..7e687fcc 100644 --- a/test/test_docstring.py +++ b/test/test_docstring.py @@ -1,3 +1,7 @@ +""" +Testing of docstring related issues and especially ``jedi.docstrings``. +""" + import jedi from .base import unittest diff --git a/test/test_integration_import.py b/test/test_integration_import.py index 16e044cb..139b870f 100644 --- a/test/test_integration_import.py +++ b/test/test_integration_import.py @@ -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 from jedi import Script +from .base import cwd_at def test_goto_definition_on_import(): diff --git a/test/test_integration_keyword.py b/test/test_integration_keyword.py index 88f086b6..13421baf 100644 --- a/test/test_integration_keyword.py +++ b/test/test_integration_keyword.py @@ -1,3 +1,6 @@ +""" +Test of keywords and ``jedi.keywords`` +""" import jedi from jedi import Script, common diff --git a/test/test_interpreter.py b/test/test_interpreter.py index eb64372c..c7240baa 100644 --- a/test/test_interpreter.py +++ b/test/test_interpreter.py @@ -1,9 +1,13 @@ -from .base import unittest +""" +Tests of ``jedi.api.Interpreter``. +""" + +from .base import TestCase import jedi from jedi._compatibility import is_py33 -class TestInterpreterAPI(unittest.TestCase): +class TestInterpreterAPI(TestCase): def check_interpreter_complete(self, source, namespace, completions, **kwds): script = jedi.Interpreter(source, [namespace], **kwds) diff --git a/test/test_regression.py b/test/test_regression.py index a66d51af..a43019be 100644 --- a/test/test_regression.py +++ b/test/test_regression.py @@ -1,23 +1,23 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- """ -Unit tests to avoid errors of the past. Makes use of Python's ``unittest`` -module. +Unit tests to avoid errors of the past. These are also all tests that didn't +found a good place in any other testing module. """ import os import textwrap -from .base import unittest, cwd_at +from .base import TestCase, cwd_at import jedi from jedi import Script -from jedi import api, parsing, common +from jedi import api, parsing #jedi.set_debug_function(jedi.debug.print_to_stdout) -class TestRegression(unittest.TestCase): +class TestRegression(TestCase): def test_goto_definition_cursor(self): s = ("class A():\n" @@ -59,23 +59,6 @@ class TestRegression(unittest.TestCase): assert len(r) == 1 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): assert Script("a", 1, 1).goto_definitions() == [] s = Script("str", 1, 1).goto_definitions() diff --git a/test/test_speed.py b/test/test_speed.py index e5ec03b3..ce69adfd 100644 --- a/test/test_speed.py +++ b/test/test_speed.py @@ -1,10 +1,15 @@ +""" +Speed tests of Jedi. To prove that certain things don't take longer than they +should. +""" + import time import functools -from .base import unittest +from .base import TestCase import jedi -class TestSpeed(unittest.TestCase): +class TestSpeed(TestCase): def _check_speed(time_per_run, number=4, run_warm=True): """ Speed checks should typically be very tolerant. Some machines are faster than others, but the tests should still pass. These tests are