From d86793039957aa408a98806aecfb5964bda5fb87 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Tue, 13 Jan 2015 13:33:06 +0100 Subject: Add prolog.engine.test Depends on run_tests/3. --- prolog/engine.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/prolog/engine.py b/prolog/engine.py index a25a07d..dff577c 100644 --- a/prolog/engine.py +++ b/prolog/engine.py @@ -114,6 +114,19 @@ class PrologEngine(object): message = re.sub(r'_G[0-9]*', '_', message) return message +def test(name, code): + engine = PrologEngine(code=code) + reply = engine.ask("run_tests({}, '{}', Results)".format(name, engine.id)) + engine.destroy() + + if reply['event'] != 'success': + raise Exception('testing procedure failed') + + results = re.findall(r'(?:success|failure)\([^)]*\)', reply['data'][0]['Results']) + n_total = len(results) + n_passed = len([r for r in results if r.startswith('success')]) + return (n_passed, n_total) + # Basic sanity check. if __name__ == '__main__': engine = PrologEngine(code='dup([],[]). dup([H|T],[H,H|TT]) :- dup(T,TT).') -- cgit v1.2.1