[pypy-svn] r42094 - pypy/dist/pypy/lib/pyontology/test
tismer at codespeak.net
tismer at codespeak.net
Mon Apr 16 15:24:49 CEST 2007
Author: tismer
Date: Mon Apr 16 15:24:48 2007
New Revision: 42094
Modified:
pypy/dist/pypy/lib/pyontology/test/test_ontology.py
pypy/dist/pypy/lib/pyontology/test/test_sparql.py
Log:
some modification to the tests to make them path independent. Without changing the implementation,
I had to turn the file names into an opened URL. Note that there is a wrong assumption of having a seekable file, which is not true for URLs. The seek can be avoided by passing the 'xml' type to add_file
Modified: pypy/dist/pypy/lib/pyontology/test/test_ontology.py
==============================================================================
--- pypy/dist/pypy/lib/pyontology/test/test_ontology.py (original)
+++ pypy/dist/pypy/lib/pyontology/test/test_ontology.py Mon Apr 16 15:24:48 2007
@@ -13,6 +13,24 @@
#from pypy.lib.pyontology.pyontology import * # Ontology, ClassDomain, SubClassConstraint
from rdflib import Graph, URIRef, BNode
+import os
+import pypy.lib.pyontology
+DATAPATH = os.path.join(os.path.split(pypy.lib.pyontology.__file__)[0], 'test')
+
+def datapath(name):
+ """
+ Making the tests location independent:
+ We need to turn the file name into an URL, or the drive letter
+ would be misinterpreted as protocol on windows.
+ Instead of a plain file name, we pass an open URL.
+ But careful, URLs don't have a seek method, so we need to avoid
+ inspection of the beginning of the file by passing the file type
+ 'xml' explicitly.
+ """
+ from urllib import urlopen, pathname2url
+ url = pathname2url(os.path.join(DATAPATH, name))
+ return urlopen(url)
+
UR = URIRef
class TestAppOntology:
@@ -40,7 +58,7 @@
def test_equivalentProperty_inconst(self):
from pypy.lib.pyontology.pyontology import *
O = Ontology()
- O.add_file("testinconst.rdf")
+ O.add_file(datapath("testinconst.rdf"), 'xml')
O.attach_fd()
raises(ConsistencyFailure, O.consistency)
@@ -683,12 +701,12 @@
def test_add_file(self):
from pypy.lib.pyontology.pyontology import *
O = Ontology()
- O.add_file('premises001.rdf')
+ O.add_file(datapath('premises001.rdf'), 'xml')
trip = list(O.graph.triples((None,)*3))
# O.attach_fd()
ll = len(O.variables)
l = len(trip)
- O.add_file('conclusions001.rdf')
+ O.add_file(datapath('conclusions001.rdf'), 'xml')
O.attach_fd()
lll = len(O.variables)
assert len(list(O.graph.triples((None,)*3))) > l
@@ -696,12 +714,12 @@
def test_more_cardinality(self):
from pypy.lib.pyontology.pyontology import *
O = Ontology()
- O.add_file('premises003.rdf')
+ O.add_file(datapath('premises003.rdf'), 'xml')
trip = list(O.graph.triples((None,)*3))
# O.attach_fd()
ll = len(O.variables)
l = len(trip)
- O.add_file('conclusions003.rdf')
+ O.add_file(datapath('conclusions003.rdf'), 'xml')
O.attach_fd()
O.consistency()
lll = len(O.variables)
Modified: pypy/dist/pypy/lib/pyontology/test/test_sparql.py
==============================================================================
--- pypy/dist/pypy/lib/pyontology/test/test_sparql.py (original)
+++ pypy/dist/pypy/lib/pyontology/test/test_sparql.py Mon Apr 16 15:24:48 2007
@@ -9,6 +9,25 @@
from pypy.lib.pyontology.sparql_grammar import SPARQLGrammar as SP
from pypy.lib.pyontology.pyontology import Ontology, ConsistencyFailure
+import os
+import pypy.lib.pyontology
+DATAPATH = os.path.join(os.path.split(pypy.lib.pyontology.__file__)[0], 'test')
+
+def datapath(name):
+ """
+ Making the tests location independent:
+ We need to turn the file name into an URL, or the drive letter
+ would be misinterpreted as protocol on windows.
+ Instead of a plain file name, we pass an open URL.
+ But careful, URLs don't have a seek method, so we need to avoid
+ inspection of the beginning of the file by passing the file type
+ 'xml' explicitly.
+ """
+ from urllib import urlopen, pathname2url
+ url = pathname2url(os.path.join(DATAPATH, name))
+ return urlopen(url)
+
+
qt = """
PREFIX ns: <http://example.org/ns#>
@@ -80,7 +99,7 @@
query = qt_proto % ('?x', 'ns:sub ns:p "a123" .')
O = Ontology()
- O.add_file("testont.rdf")
+ O.add_file(datapath("testont.rdf"), 'xml')
O.attach_fd()
raises(ConsistencyFailure, O.sparql, query)
@@ -89,7 +108,7 @@
query = qt_proto % ('?x', '?x ns:p 123 .')
O = Ontology()
- O.add_file("testont.rdf")
+ O.add_file(datapath("testont.rdf"), 'xml')
O.attach_fd()
O.finish()
res = O.sparql(query)
@@ -100,7 +119,7 @@
query = qt_proto % ('?x', 'ns:sub ?x 123 .')
O = Ontology()
- O.add_file("testont.rdf")
+ O.add_file(datapath("testont.rdf"), 'xml')
O.attach_fd()
O.finish()
@@ -113,7 +132,7 @@
query = qt_proto % ('?x', 'ns:sub ns:p ?x .')
O = Ontology()
- O.add_file("testont.rdf")
+ O.add_file(datapath("testont.rdf"), 'xml')
O.attach_fd()
O.finish()
@@ -125,7 +144,7 @@
query = qt_proto % ('?x ?y', '?x ?y 123 .')
O = Ontology()
- O.add_file("testont.rdf")
+ O.add_file(datapath("testont.rdf"), 'xml')
O.attach_fd()
O.finish()
@@ -139,7 +158,7 @@
query = qt_proto % ('?x ?y', '?x ns:p ?y .')
O = Ontology()
- O.add_file("testont.rdf")
+ O.add_file(datapath("testont.rdf"), 'xml')
O.attach_fd()
O.finish()
@@ -154,7 +173,7 @@
query = qt_proto % ('?x ?y', 'ns:sub ?x ?y .')
O = Ontology()
- O.add_file("testont.rdf")
+ O.add_file(datapath("testont.rdf"), 'xml')
O.attach_fd()
O.finish()
@@ -167,7 +186,7 @@
query = qt_proto % ('?x ?y ?z', '?x ?y ?z .')
O = Ontology()
- O.add_file("testont.rdf")
+ O.add_file(datapath("testont.rdf"), 'xml')
O.attach_fd()
O.finish()
res = O.sparql(query)
@@ -177,7 +196,7 @@
def test_filter():
query = qt_proto % ('?x ?y', '?x ns:p ?y .\n FILTER(?y < 124) .')
O = Ontology()
- O.add_file("testont.rdf")
+ O.add_file(datapath("testont.rdf"), 'xml')
O.attach_fd()
O.finish()
res = O.sparql(query)
@@ -218,7 +237,7 @@
def test_query1():
O = Ontology()
- O.add_file("testont2.rdf")
+ O.add_file(datapath("testont2.rdf"), 'xml')
O.attach_fd()
res = O.sparql(query1)
@@ -229,7 +248,7 @@
def test_query2():
# py.test.skip("Doesn't work yet")
O = Ontology()
- O.add_file("testont2.rdf")
+ O.add_file(datapath("testont2.rdf"), 'xml')
O.attach_fd()
res = O.sparql(query2)
@@ -240,7 +259,7 @@
def test_query3():
#py.test.skip("Doesn't work yet")
O = Ontology()
- O.add_file("testont2.rdf")
+ O.add_file(datapath("testont2.rdf"), 'xml')
O.attach_fd()
res = O.sparql(query3)
@@ -258,6 +277,8 @@
import sys
exe = sys.executable
print exe
+ self.oldcwd = os.getcwd()
+ os.chdir(DATAPATH)
self.shell = Popen("%s ../pyontology.py testont.rdf" % exe, shell=True)
server = xmlrpclib.ServerProxy("http://localhost:9000")
print "setup"
@@ -271,7 +292,11 @@
break
def teardown_class(self):
print " teardown", self.shell.pid
- os.kill(self.shell.pid, signal.SIGTERM)
+ os.chdir(self.oldcwd)
+ try:
+ os.kill(self.shell.pid, signal.SIGTERM)
+ except AttributeError:
+ print "SORRY can't kill process in this OS"
def test_xmlrpc(self):
print "test_xmlrpc"
More information about the pypy-svn
mailing list