mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 07:14:48 +08:00
added tests
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
class TestClass(object):
|
||||||
|
var_class = TestClass()
|
||||||
|
|
||||||
|
def __init__(self2, a):
|
||||||
|
self2.var_inst = a
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
inst = TestClass(1)
|
||||||
|
|
||||||
|
#? ['var_class', 'var_inst']
|
||||||
|
inst.var
|
||||||
|
|
||||||
|
#? ['var_class']
|
||||||
|
TestClass.var_class
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
def array():
|
def array():
|
||||||
return []
|
return list()
|
||||||
#? ['append']
|
#? ['append']
|
||||||
array().app
|
array().app
|
||||||
|
|
||||||
|
|||||||
48
test/completion/types.py
Normal file
48
test/completion/types.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
# -----------------
|
||||||
|
# lists
|
||||||
|
# -----------------
|
||||||
|
arr = []
|
||||||
|
#? ['append']
|
||||||
|
arr().app
|
||||||
|
|
||||||
|
#? ['append']
|
||||||
|
list().app
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# dicts
|
||||||
|
# -----------------
|
||||||
|
dic = {}
|
||||||
|
|
||||||
|
#? ['clear', 'copy']
|
||||||
|
dic.c
|
||||||
|
|
||||||
|
dic2 = dict(a=1, b=2)
|
||||||
|
#? ['pop', 'popitem']
|
||||||
|
dic2.p
|
||||||
|
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# set
|
||||||
|
# -----------------
|
||||||
|
set_t = {1,2}
|
||||||
|
|
||||||
|
#? ['clear', 'copy']
|
||||||
|
set_t.c
|
||||||
|
|
||||||
|
set_t2 = set()
|
||||||
|
|
||||||
|
#? ['clear', 'copy']
|
||||||
|
set_t2.c
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# tuples
|
||||||
|
# -----------------
|
||||||
|
tup = ('',2)
|
||||||
|
|
||||||
|
#? ['count']
|
||||||
|
tup.c
|
||||||
|
|
||||||
|
tup2 = tuple()
|
||||||
|
#? ['index']
|
||||||
|
tup2.i
|
||||||
29
test/run.py
29
test/run.py
@@ -3,6 +3,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import StringIO
|
import StringIO
|
||||||
|
import traceback
|
||||||
|
|
||||||
sys.path.append('../')
|
sys.path.append('../')
|
||||||
import functions
|
import functions
|
||||||
@@ -29,13 +30,20 @@ def completion_test(source):
|
|||||||
if correct:
|
if correct:
|
||||||
# lines start with 1 and column is just the last (makes no
|
# lines start with 1 and column is just the last (makes no
|
||||||
# difference for testing)
|
# difference for testing)
|
||||||
completions = functions.complete(source, line_nr, 999,
|
try:
|
||||||
completion_test_dir)
|
completions = functions.complete(source, line_nr, 999,
|
||||||
comp_str = str([str(c) for c in completions])
|
completion_test_dir)
|
||||||
if comp_str != correct:
|
except:
|
||||||
print 'Solution not correct, received %s, wanted %s' % \
|
print 'test: %s' % line
|
||||||
(correct, comp_str)
|
print traceback.format_exc()
|
||||||
fails += 1
|
fails += 1
|
||||||
|
else:
|
||||||
|
# TODO remove sorted? completions should be sorted
|
||||||
|
comp_str = str(sorted([str(c) for c in completions]))
|
||||||
|
if comp_str != correct:
|
||||||
|
print 'Solution not correct, received %s, wanted %s' % \
|
||||||
|
(correct, comp_str)
|
||||||
|
fails += 1
|
||||||
correct = None
|
correct = None
|
||||||
tests += 1
|
tests += 1
|
||||||
else:
|
else:
|
||||||
@@ -47,9 +55,16 @@ def completion_test(source):
|
|||||||
|
|
||||||
# completion tests:
|
# completion tests:
|
||||||
completion_test_dir = 'completion'
|
completion_test_dir = 'completion'
|
||||||
|
summary = []
|
||||||
for f_name in os.listdir(completion_test_dir ):
|
for f_name in os.listdir(completion_test_dir ):
|
||||||
if f_name.endswith(".py"):
|
if f_name.endswith(".py"):
|
||||||
path = os.path.join(completion_test_dir, f_name)
|
path = os.path.join(completion_test_dir, f_name)
|
||||||
f = open(path)
|
f = open(path)
|
||||||
num_tests, fails = completion_test(f.read())
|
num_tests, fails = completion_test(f.read())
|
||||||
print '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)
|
||||||
|
print s
|
||||||
|
summary.append(s)
|
||||||
|
|
||||||
|
print '\nSummary:'
|
||||||
|
for s in summary:
|
||||||
|
print s
|
||||||
|
|||||||
Reference in New Issue
Block a user