From 1af82733893101fce3df64ed904e35abf6bbd0d9 Mon Sep 17 00:00:00 2001 From: David Halter Date: Sat, 21 Apr 2012 23:08:13 +0200 Subject: [PATCH] added import tests --- evaluate.py | 2 +- functions.py | 5 +++-- parsetest.py | 2 +- parsing.py | 1 + test/completion/imports.py | 29 +++++++++++++++++++++++------ test/run.py | 3 ++- 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/evaluate.py b/evaluate.py index 47a2ac18..acd2673c 100644 --- a/evaluate.py +++ b/evaluate.py @@ -6,6 +6,7 @@ follow_statement -> follow_call -> follow_paths -> follow_path TODO include super classes """ + # python2.5 compatibility try: next @@ -138,7 +139,6 @@ class ArrayElement(object): @property def parent(self): raise NotImplementedError("This shouldn't happen") - return @property def returns(self): diff --git a/functions.py b/functions.py index 26f2a42b..0e007877 100644 --- a/functions.py +++ b/functions.py @@ -58,8 +58,6 @@ class FileWithCursor(modules.File): close_brackets = [')', ']', '}'] gen = tokenize.generate_tokens(fetch_line) - # TODO can happen: raise TokenError, ("EOF in multi-line statement" - # where??? string = '' level = 0 for token_type, tok, start, end, line in gen: @@ -199,6 +197,9 @@ def complete(source, row, column, source_path): for s in scopes: completions += s.get_defined_names() + # remove duplicates + completions = list(set(completions)) + needs_dot = not dot and path completions = [Completion(c, needs_dot, len(like)) for c in completions if c.names[-1].lower().startswith(like.lower())] diff --git a/parsetest.py b/parsetest.py index 7e03e3e1..6908071c 100644 --- a/parsetest.py +++ b/parsetest.py @@ -147,4 +147,4 @@ c = b().c3() 1.0.fromhex(); import flask ; flsk = flask.Flask + flask.Request; abc = [1,2+3]; abc[0]. import pylab; def add(a1,b1): nana = 1; return a1+b1 -abc = datetime; return [abc][0]. ;pylab.; add(1+2,2). +abc = datetime; return [abc][0]. ;pylab.; add(1+2,2).real diff --git a/parsing.py b/parsing.py index 7ecc19df..02ab5caf 100644 --- a/parsing.py +++ b/parsing.py @@ -570,6 +570,7 @@ class Statement(Simple): brackets = {'(': Array.EMPTY, '[': Array.LIST, '{': Array.SET} is_call = lambda: result.__class__ == Call is_call_or_close = lambda: is_call() or close_brackets + if isinstance(tok, Name) or token_type in [tokenize.STRING, tokenize.NUMBER]: # names c_type = Call.NAME diff --git a/test/completion/imports.py b/test/completion/imports.py index 16bfa907..f99e6493 100644 --- a/test/completion/imports.py +++ b/test/completion/imports.py @@ -1,4 +1,22 @@ +# ----------------- +# std lib modules +# ----------------- +import tokenize +#? ['tok_name'] +tokenize.tok_name +from pyclbr import * + +#? ['readmodule_ex'] +readmodule_ex +import os + +#? ['dirname'] +os.path.dirname + +# ----------------- +# builtins +# ----------------- import sys #? ['prefix'] @@ -7,14 +25,13 @@ sys.prefix #? ['append'] sys.path.append - -# --- builtin math --- - from math import * #? ['cos', 'cosh'] cos -import os +def func_with_import(): + import time + return time -#? ['dirname'] -os.path.dirname +#? ['sleep'] +func_with_import().sleep diff --git a/test/run.py b/test/run.py index 9114ca4e..89e7c3ce 100755 --- a/test/run.py +++ b/test/run.py @@ -39,11 +39,12 @@ def completion_test(source): print traceback.format_exc() fails += 1 else: - # TODO remove sorted? completions should be sorted + # 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' % \ (comp_str, correct) + #print [(c.name, c.name.parent) for c in completions] fails += 1 correct = None tests += 1