[spade2] r2242 committed - Added new unit tests for the pyxf module.

4 views
Skip to first unread message

spa...@googlecode.com

unread,
Jul 11, 2012, 8:27:11 AM7/11/12
to spade-...@googlegroups.com
Revision: 2242
Author: jpalanca
Date: Wed Jul 11 05:26:53 2012
Log: Added new unit tests for the pyxf module.
http://code.google.com/p/spade2/source/detail?r=2242

Added:
/trunk/test/logic
/trunk/test/logic/test_eclipse.ecl
/trunk/test/logic/test_flora.flr
/trunk/test/logic/test_swi.pl
/trunk/test/logic/test_xsb.P
/trunk/test/xfTestCase.py
Modified:
/trunk/spade/pyxf.py
/trunk/test.py

=======================================
--- /dev/null
+++ /trunk/test/logic/test_eclipse.ecl Wed Jul 11 05:26:53 2012
@@ -0,0 +1,5 @@
+
+likes( john, curry ).
+likes( sandy, mushrooms ).
+
+dislikes( X, Y ) :- not( likes( X, Y ) ).
=======================================
--- /dev/null
+++ /trunk/test/logic/test_flora.flr Wed Jul 11 05:26:53 2012
@@ -0,0 +1,6 @@
+
+john[ likes->curry ].
+sandy[ likes->mushrooms ].
+
+?x[ dislikes->?y ] :-
+ ?x[ not( likes->?y ) ].
=======================================
--- /dev/null
+++ /trunk/test/logic/test_swi.pl Wed Jul 11 05:26:53 2012
@@ -0,0 +1,5 @@
+
+likes( john, curry ).
+likes( sandy, mushrooms ).
+
+dislikes( X, Y ) :- not( likes( X, Y ) ).
=======================================
--- /dev/null
+++ /trunk/test/logic/test_xsb.P Wed Jul 11 05:26:53 2012
@@ -0,0 +1,5 @@
+
+likes( john, curry ).
+likes( sandy, mushrooms ).
+
+dislikes( X, Y ) :- not( likes( X, Y ) ).
=======================================
--- /dev/null
+++ /trunk/test/xfTestCase.py Wed Jul 11 05:26:53 2012
@@ -0,0 +1,65 @@
+import os
+import sys
+import unittest
+
+from spade.pyxf import *
+class xfTestCase(unittest.TestCase):
+
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def testEclipse(self):
+ try:
+ e = eclipse()
+ except ECLiPSeExecutableNotFound:
+ self.fail('ECLiPSe Prolog executable not found on the specified
path.')
+
+ e.load( 'test/logic/test_eclipse' )
+ assert e.query( 'dislikes( john, mushrooms )' ) == True
+ for result in e.query( 'likes( Person, Food )' ):
+ assert result in [{'Food': 'curry', 'Person': 'john'},
{'Food': 'mushrooms', 'Person': 'sandy'}]
+ del e
+
+ def testFlora2(self):
+ try:
+ f = flora2()
+ except Flora2ExecutableNotFound:
+ self.fail('Flora-2 executable not found on the specified path. Try
installing flora2')
+
+ f.load( 'test/logic/test_flora' )
+ assert f.query( 'john[ dislikes->mushrooms ]' ) == True
+ for result in f.query( '?person[ likes->?food ]' ):
+ assert result in [{'food': 'curry', 'person': 'john'},
{'food': 'mushrooms', 'person': 'sandy'}]
+ del f
+
+ def testSWI(self):
+ try:
+ s = swipl()
+ except SWIExecutableNotFound:
+ self.fail('SWI-Prolog executable not found on the specified path.
Try installing swi-prolog.')
+
+ s.load( 'test/logic/test_swi' )
+ assert s.query( 'dislikes( john, mushrooms )' ) == True
+ for result in s.query( 'likes( Person, Food )' ):
+ assert result in [{'Food': 'curry', 'Person': 'john'},
{'Food': 'mushrooms', 'Person': 'sandy'}]
+ del s
+
+
+ def testXSB(self):
+ try:
+ x = xsb()
+ except XSBExecutableNotFound:
+ self.fail('XSB executable not found on the specified path. Try
installing xsb')
+
+ x.load( 'test/logic/test_xsb' )
+ assert x.query( 'dislikes( john, mushrooms )' ) == True
+ for result in x.query( 'likes( Person, Food )' ):
+ assert result in [{'Food': 'curry', 'Person': 'john'},
{'Food': 'mushrooms', 'Person': 'sandy'}]
+ del x
+
+
+if __name__ == "__main__":
+ unittest.main()
=======================================
--- /trunk/spade/pyxf.py Wed Jul 11 04:18:54 2012
+++ /trunk/spade/pyxf.py Wed Jul 11 05:26:53 2012
@@ -440,25 +440,27 @@

if __name__ == '__main__':
x = xsb()
- x.load( 'test_xsb' )
+ x.load( '../test/logic/test_xsb' )
print x.query( 'dislikes( john, mushrooms )' )
print x.query( 'likes( Person, Food )' )
del x
+
+ print "======="

s = swipl()
- s.load( 'test_swi' )
+ s.load( '../test/logic/test_swi' )
print s.query( 'dislikes( john, mushrooms )' )
print s.query( 'likes( Person, Food )' )
del s

e = eclipse()
- e.load( 'test_eclipse' )
+ e.load( '../test/logic/test_eclipse' )
print e.query( 'dislikes( john, mushrooms )' )
print e.query( 'likes( Person, Food )' )
del e

f = flora2()
- f.load( 'test_flora' )
+ f.load( '../test/logic/test_flora' )
print f.query( 'john[ dislikes->mushrooms ]' )
print f.query( '?person[ likes->?food ]' )
del f
=======================================
--- /trunk/test.py Tue Jul 10 16:56:02 2012
+++ /trunk/test.py Wed Jul 11 05:26:53 2012
@@ -9,6 +9,7 @@
from test.eventbehavTestCase import *
from test.pubsubTestCase import *
from test.kbTestCase import *
+from test.xfTestCase import *

from spade import spade_backend
from xmppd.xmppd import Server
Reply all
Reply to author
Forward
0 new messages