pyketest.py :  » Language-Interface » Python-Knowledge-Engine » pyke-1.1.1 » Test » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Language Interface » Python Knowledge Engine 
Python Knowledge Engine » pyke 1.1.1 » Test » pyketest.py
# pyketest.py

from __future__ import with_statement
import types
import unittest
from pyke import knowledge_engine
from pyke import krb_traceback

def mk_engine(*paths):
    if isinstance(self.paths, types.StringTypes):
        self.paths = (self.paths,)
    return knowledge_engine.engine(*paths)

class pyketest(unittest.TestCase):
    # Need to set: engine
    tmp_facts = ()      # sequence of (fb_name, fact_name, fact_arg...)
    rb_names_to_activate = ('test',)
    def activate(self):
        for tmp_fact in self.tmp_facts:
            fb = tmp_fact[0]
            name = tmp_fact[1]
            args = tmp_fact[2:]
            self.tmp_fact(fb, name, *args)
        if hasattr(self, 'add_tmp_facts'): self.add_tmp_facts()
        self.engine.activate(*self.rb_names_to_activate)
    def add_fact(fb, name, *args):
        self.engine.add_universal_fact(fb, name, args)
    def tmp_fact(fb, name, *args):
        self.engine.add_case_specific_fact(fb, name, args)
    def tearDown(self):
        self.engine.reset()

class fc_tests(pyketest):
    def runTest(self):
        self.activate()

class bc_tests(pyketest):
    rb_name = None      # defaults to self.rb_names_to_activate[0]
    # Need to set: goal, num_return
    plan_args = None
    plan_kws = None
    def __init__(self, methodName = 'runTest'):
        super(bc_tests, self).__init__(methodName)
        if self.rb_name is None: self.rb_name = self.rb_names_to_activate[0]
    def setUp(self):
        try:
            self.activate()
        except:
            krb_traceback.print_exc()
            raise
    def bc_test(self, *args):
        ans = []
        with self.engine.prove_n(self.rb_name, self.goal, args,
                                 self.num_return) as gen:
            for ret_args, plan in gen:
                if plan_args is None and plan_kws is None:
                    self.assert_(plan is None, "unexpected plan")
                    ans.append(ret_args)
                else:
                    self.assert_(plan is not None, "expected plan")
                    if plan_args is None: plan_ans = plan(**plan_kws)
                    elif plan_kws is None: plan_ans = plan(*plan_args)
                    else: plan_ans = plan(*plan_args, **plan_vars)
                    ans.append((ret_args, plan_ans))
        return ans

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.