From e7a579ce31fff379058968b7c34aeefc93a2f16a Mon Sep 17 00:00:00 2001 From: David Halter Date: Mon, 25 Jun 2012 21:05:10 +0200 Subject: [PATCH] added thirdparty testing (test/completion/thirdparty/) and fixed an AttributeError --- evaluate.py | 2 +- test/completion/thirdparty/django.py | 9 ++++++++ test/run.py | 32 ++++++++++++++++++---------- 3 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 test/completion/thirdparty/django.py diff --git a/evaluate.py b/evaluate.py index 97a9542e..9e0c9346 100644 --- a/evaluate.py +++ b/evaluate.py @@ -207,7 +207,7 @@ class Instance(Executable): return res def __getattr__(self, name): - if name not in ['line_nr', 'indent', 'name']: + if name not in ['line_nr', 'indent', 'name', 'get_imports']: raise AttributeError("Don't touch this (%s)!" % name) return getattr(self.base, name) diff --git a/test/completion/thirdparty/django.py b/test/completion/thirdparty/django.py new file mode 100644 index 00000000..fc2b351a --- /dev/null +++ b/test/completion/thirdparty/django.py @@ -0,0 +1,9 @@ +import django + +#? ['get_version'] +django.get_version + +from django.conf import settings + +#? ['configured'] +settings.configured diff --git a/test/run.py b/test/run.py index 2fc390ad..89d671d0 100755 --- a/test/run.py +++ b/test/run.py @@ -121,17 +121,27 @@ def run_test(source): completion_test_dir = 'test/completion' summary = [] tests_pass = True -for f_name in os.listdir(completion_test_dir): - if len(sys.argv) == 1 or [a for a in sys.argv[1:] if a in f_name]: - if f_name.endswith(".py"): - path = os.path.join(completion_test_dir, f_name) - f = open(path) - num_tests, fails = run_test(f.read()) - s = 'run %s tests with %s fails (%s)' % (num_tests, fails, f_name) - if fails: - tests_pass = False - print(s) - summary.append(s) +def test_dir(completion_test_dir, third_party=False): + global tests_pass + for f_name in os.listdir(completion_test_dir): + if len(sys.argv) == 1 or [a for a in sys.argv[1:] if a in f_name]: + if f_name.endswith(".py"): + if third_party: + try: + __import__(f_name.replace('.py', '')) + except ImportError: + summary.append('Thirdparty-Library %s not found.' % f_name) + path = os.path.join(completion_test_dir, f_name) + f = open(path) + num_tests, fails = run_test(f.read()) + s = 'run %s tests with %s fails (%s)' % (num_tests, fails, f_name) + if fails: + tests_pass = False + print(s) + summary.append(s) + +test_dir(completion_test_dir) +test_dir(completion_test_dir + '/thirdparty', third_party=True) print('\nSummary:') for s in summary: