From 5f21f563303a63fe448cc58bd54621ea95e11bee Mon Sep 17 00:00:00 2001 From: David Halter Date: Thu, 12 Apr 2012 15:47:33 +0200 Subject: [PATCH] test suite for completion added --- ftest.py | 6 ++-- test/__init__.py | 0 test/completion/classes.py | 0 test/completion/functions.py | 9 ++++++ test/run.py | 55 ++++++++++++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 test/__init__.py create mode 100644 test/completion/classes.py create mode 100644 test/completion/functions.py create mode 100755 test/run.py diff --git a/ftest.py b/ftest.py index ac390dd7..0434a10f 100755 --- a/ftest.py +++ b/ftest.py @@ -3,11 +3,11 @@ import functions functions.debug.debug_function = functions.debug.print_to_stdout -#functions.debug.ignored_modules += ['parsing', 'builtin'] -functions.debug.ignored_modules += ['parsing', 'builtin', 'evaluate', 'modules'] +functions.debug.ignored_modules = ['parsing', 'builtin'] +#functions.debug.ignored_modules = ['parsing', 'builtin', 'evaluate', 'modules'] functions.modules.module_find_path.insert(0, '.') -f_name = 'test.py' +f_name = 'parsetest.py' import os path = os.getcwd() + '/' + f_name diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test/completion/classes.py b/test/completion/classes.py new file mode 100644 index 00000000..e69de29b diff --git a/test/completion/functions.py b/test/completion/functions.py new file mode 100644 index 00000000..ac1c200b --- /dev/null +++ b/test/completion/functions.py @@ -0,0 +1,9 @@ +import os + +def array(): + return [] +#? ['append'] +array().app + +#? ['array'] +arr diff --git a/test/run.py b/test/run.py new file mode 100755 index 00000000..a7ec73d1 --- /dev/null +++ b/test/run.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +import os +import sys +import re +import StringIO + +sys.path.append('../') +import functions + +#functions.set_debug_function(functions.debug.print_to_stdout) + +def completion_test(source): + """ + This is the completion test for some cases. The tests are not unit test + like, they are rather integration tests. + It uses comments to specify a test in the next line. The comment also says, + which results are expected. The comment always begins with `#?`. The last + row symbolizes the cursor. + + For example: + #? ['ab'] + ab = 3; a + """ + fails = 0 + tests = 0 + correct = None + for line_nr, line in enumerate(StringIO.StringIO(source)): + line_nr += 1 + if correct: + # lines start with 1 and column is just the last (makes no + # difference for testing) + completions = functions.complete(source, line_nr, 999, + completion_test_dir) + comp_str = str([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 + tests += 1 + else: + try: + correct = re.search(r'#\?\s*([^\n]+)', line).group(1) + except: + correct = None + return tests, fails + +# completion tests: +completion_test_dir = 'completion' +for f_name in os.listdir(completion_test_dir ): + if f_name.endswith(".py"): + path = os.path.join(completion_test_dir, f_name) + f = open(path) + num_tests, fails = completion_test(f.read()) + print 'run %s tests with %s fails (%s)' % (num_tests, fails, f_name)