mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
move more testing functionality out of run.py
This commit is contained in:
29
test/base.py
29
test/base.py
@@ -1,5 +1,6 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
import time
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from os.path import abspath, dirname
|
from os.path import abspath, dirname
|
||||||
@@ -8,7 +9,28 @@ sys.path.insert(0, abspath(dirname(abspath(__file__)) + '/../jedi'))
|
|||||||
os.chdir(os.path.dirname(os.path.abspath(__file__)) + '/../jedi')
|
os.chdir(os.path.dirname(os.path.abspath(__file__)) + '/../jedi')
|
||||||
|
|
||||||
import api
|
import api
|
||||||
|
import debug
|
||||||
|
|
||||||
|
test_sum = 0
|
||||||
|
t_start = time.time()
|
||||||
|
# Sorry I didn't use argparse here. It's because argparse is not in the
|
||||||
|
# stdlib in 2.5.
|
||||||
|
args = sys.argv[1:]
|
||||||
|
|
||||||
|
print_debug = False
|
||||||
|
try:
|
||||||
|
i = args.index('--debug')
|
||||||
|
args = args[:i] + args[i + 1:]
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
print_debug = True
|
||||||
|
api.set_debug_function(debug.print_to_stdout)
|
||||||
|
|
||||||
|
sys.argv = sys.argv[:1] + args
|
||||||
|
|
||||||
|
summary = []
|
||||||
|
tests_fail = 0
|
||||||
|
|
||||||
class TestBase(unittest.TestCase):
|
class TestBase(unittest.TestCase):
|
||||||
def get_script(self, src, pos, path=None):
|
def get_script(self, src, pos, path=None):
|
||||||
@@ -32,3 +54,10 @@ class TestBase(unittest.TestCase):
|
|||||||
def get_in_function_call(self, src, pos=None):
|
def get_in_function_call(self, src, pos=None):
|
||||||
script = self.get_script(src, pos)
|
script = self.get_script(src, pos)
|
||||||
return script.get_in_function_call()
|
return script.get_in_function_call()
|
||||||
|
|
||||||
|
def print_summary():
|
||||||
|
print('\nSummary: (%s fails of %s tests) in %.3fs' % \
|
||||||
|
(tests_fail, test_sum, time.time() - t_start))
|
||||||
|
for s in summary:
|
||||||
|
print(s)
|
||||||
|
|
||||||
|
|||||||
@@ -152,11 +152,11 @@ from .......import_tree import mod1
|
|||||||
#?
|
#?
|
||||||
mod1.a
|
mod1.a
|
||||||
|
|
||||||
from .. import run
|
from .. import base
|
||||||
#? int()
|
#? int()
|
||||||
run.tests_fail
|
base.tests_fail
|
||||||
|
|
||||||
from ..run import tests_fail as f
|
from ..base import tests_fail as f
|
||||||
#? int()
|
#? int()
|
||||||
f
|
f
|
||||||
|
|
||||||
|
|||||||
55
test/run.py
55
test/run.py
@@ -3,13 +3,16 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import traceback
|
import traceback
|
||||||
import time
|
|
||||||
|
|
||||||
from base import api
|
import base
|
||||||
|
|
||||||
from _compatibility import unicode, StringIO, reduce, literal_eval, is_py25
|
from _compatibility import unicode, StringIO, reduce, literal_eval, is_py25
|
||||||
|
|
||||||
|
import api
|
||||||
import debug
|
import debug
|
||||||
|
|
||||||
#sys.path.pop(0) # pop again, because it might affect the completion
|
|
||||||
|
sys.path.pop(0) # pop again, because it might affect the completion
|
||||||
|
|
||||||
|
|
||||||
def run_completion_test(script, correct, line_nr):
|
def run_completion_test(script, correct, line_nr):
|
||||||
@@ -129,7 +132,7 @@ def run_test(source, f_name, lines_to_execute):
|
|||||||
continue
|
continue
|
||||||
# -1 for the comment, +3 because of the comment start `#? `
|
# -1 for the comment, +3 because of the comment start `#? `
|
||||||
start = index.start()
|
start = index.start()
|
||||||
if print_debug:
|
if base.print_debug:
|
||||||
api.set_debug_function(None)
|
api.set_debug_function(None)
|
||||||
number += 1
|
number += 1
|
||||||
try:
|
try:
|
||||||
@@ -137,7 +140,7 @@ def run_test(source, f_name, lines_to_execute):
|
|||||||
except Exception:
|
except Exception:
|
||||||
print('could not resolve %s indent %s' % (line_nr - 1, start))
|
print('could not resolve %s indent %s' % (line_nr - 1, start))
|
||||||
raise
|
raise
|
||||||
if print_debug:
|
if base.print_debug:
|
||||||
api.set_debug_function(debug.print_to_stdout)
|
api.set_debug_function(debug.print_to_stdout)
|
||||||
# because the objects have different ids, `repr` it, then compare it.
|
# because the objects have different ids, `repr` it, then compare it.
|
||||||
should_str = set(r.desc_with_module for r in should_be)
|
should_str = set(r.desc_with_module for r in should_be)
|
||||||
@@ -199,7 +202,6 @@ def run_test(source, f_name, lines_to_execute):
|
|||||||
|
|
||||||
|
|
||||||
def test_dir(completion_test_dir, thirdparty=False):
|
def test_dir(completion_test_dir, thirdparty=False):
|
||||||
global tests_fail
|
|
||||||
for f_name in os.listdir(completion_test_dir):
|
for f_name in os.listdir(completion_test_dir):
|
||||||
files_to_execute = [a for a in test_files.items() if a[0] in f_name]
|
files_to_execute = [a for a in test_files.items() if a[0] in f_name]
|
||||||
lines_to_execute = reduce(lambda x, y: x + y[1], files_to_execute, [])
|
lines_to_execute = reduce(lambda x, y: x + y[1], files_to_execute, [])
|
||||||
@@ -216,7 +218,7 @@ def test_dir(completion_test_dir, thirdparty=False):
|
|||||||
# It looks like: completion/thirdparty/pylab_.py
|
# It looks like: completion/thirdparty/pylab_.py
|
||||||
__import__(lib)
|
__import__(lib)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
summary.append('Thirdparty-Library %s not found.' %
|
base.summary.append('Thirdparty-Library %s not found.' %
|
||||||
f_name)
|
f_name)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -224,40 +226,24 @@ def test_dir(completion_test_dir, thirdparty=False):
|
|||||||
f = open(path)
|
f = open(path)
|
||||||
num_tests, fails = run_test(f.read(), f_name, lines_to_execute)
|
num_tests, fails = run_test(f.read(), f_name, lines_to_execute)
|
||||||
global test_sum
|
global test_sum
|
||||||
test_sum += num_tests
|
base.test_sum += num_tests
|
||||||
|
|
||||||
s = 'run %s tests with %s fails (%s)' % (num_tests, fails, f_name)
|
s = 'run %s tests with %s fails (%s)' % (num_tests, fails, f_name)
|
||||||
tests_fail += fails
|
base.tests_fail += fails
|
||||||
print(s)
|
print(s)
|
||||||
summary.append(s)
|
base.summary.append(s)
|
||||||
|
|
||||||
|
|
||||||
test_sum = 0
|
|
||||||
t_start = time.time()
|
|
||||||
# Sorry I didn't use argparse here. It's because argparse is not in the
|
|
||||||
# stdlib in 2.5.
|
|
||||||
args = sys.argv[1:]
|
|
||||||
try:
|
try:
|
||||||
i = args.index('--thirdparty')
|
i = sys.argv.index('--thirdparty')
|
||||||
thirdparty = True
|
thirdparty = True
|
||||||
args = args[:i] + args[i + 1:]
|
sys.argv = sys.argv[:i] + sys.argv[i + 1:]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
thirdparty = False
|
thirdparty = False
|
||||||
|
|
||||||
print_debug = False
|
|
||||||
try:
|
|
||||||
i = args.index('--debug')
|
|
||||||
args = args[:i] + args[i + 1:]
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
print_debug = True
|
|
||||||
api.set_debug_function(debug.print_to_stdout)
|
|
||||||
|
|
||||||
# get test list, that should be executed
|
# get test list, that should be executed
|
||||||
test_files = {}
|
test_files = {}
|
||||||
last = None
|
last = None
|
||||||
for arg in args:
|
for arg in sys.argv[1:]:
|
||||||
if arg.isdigit():
|
if arg.isdigit():
|
||||||
if last is None:
|
if last is None:
|
||||||
continue
|
continue
|
||||||
@@ -268,8 +254,6 @@ for arg in args:
|
|||||||
|
|
||||||
# completion tests:
|
# completion tests:
|
||||||
completion_test_dir = '../test/completion'
|
completion_test_dir = '../test/completion'
|
||||||
summary = []
|
|
||||||
tests_fail = 0
|
|
||||||
|
|
||||||
# execute tests
|
# execute tests
|
||||||
test_dir(completion_test_dir)
|
test_dir(completion_test_dir)
|
||||||
@@ -277,13 +261,10 @@ if test_files or thirdparty:
|
|||||||
completion_test_dir += '/thirdparty'
|
completion_test_dir += '/thirdparty'
|
||||||
test_dir(completion_test_dir, thirdparty=True)
|
test_dir(completion_test_dir, thirdparty=True)
|
||||||
|
|
||||||
print('\nSummary: (%s fails of %s tests) in %.3fs' % (tests_fail, test_sum,
|
base.print_summary()
|
||||||
time.time() - t_start))
|
|
||||||
for s in summary:
|
|
||||||
print(s)
|
|
||||||
|
|
||||||
exit_code = 1 if tests_fail else 0
|
exit_code = 1 if base.tests_fail else 0
|
||||||
if sys.hexversion < 0x02060000 and tests_fail <= 9:
|
if sys.hexversion < 0x02060000 and base.tests_fail <= 9:
|
||||||
# Python 2.5 has major incompabillities (e.g. no property.setter),
|
# Python 2.5 has major incompabillities (e.g. no property.setter),
|
||||||
# therefore it is not possible to pass all tests.
|
# therefore it is not possible to pass all tests.
|
||||||
exit_code = 0
|
exit_code = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user