root / rdfalchemy / trunk / test / sparql_test.py

Revision 127, 1.6 kB (checked in by phil, 7 months ago)

This update to rdfalchemy moves some functions in to a sub-module and has the beginings of a sparql script
It adds some unit tests (for initBinding)

Breaking your Programs:

This update could break your code if you:


from rdfalchemy.sesame2 import SesameGraph?


you now need to import from rdfalchemy.sparql.sesame2
allows for jython or other sesame graph implimentations not dependent on the http sparql endpoint


you should probably be using create_engine instead

Line 
1#!/usr/bin/env python
2# encoding: utf-8
3"""
4sparql_test.py
5
6Created by Philip Cooper on 2008-02-27.
7Copyright (c) 2008 Openvest. All rights reserved.
8"""
9
10from rdfalchemy.sparql import SPARQLGraph
11from rdfalchemy.sparql.sesame2 import SesameGraph
12from rdfalchemy import URIRef
13from decimal import Decimal
14import unittest
15
16
17class sparql_test:
18    def __init__(self):
19        pass
20
21
22class sparql_testTests(unittest.TestCase):
23    def setUp(self):
24        pass
25       
26    def initBindings_test1(self):
27        query = 'select * where {?s ?P ?oo.?ss ?p \n?oo}'
28        initBindings = dict(oo=URIRef("OHO"),P=Decimal("4.40"))
29        processed = SPARQLGraph._processInitBindings(query,initBindings)
30        assert processed == 'select * where {?s "4.40"^^<http://www.w3.org/2001/XMLSchema#decimal> <OHO>.?ss ?p \n<OHO>}'
31
32    def initBindings_test2(self):
33        query = 'select * where {?s ?P ?oo.?ss ?p \n?oo}'
34        initBindings = dict(oo=URIRef("OHO"),P=Decimal("4.40"))
35        processed = SesameGraph._processInitBindings(query,initBindings)
36        assert processed == 'select * where {?s "4.40"^^<http://www.w3.org/2001/XMLSchema#decimal> <OHO>.?ss ?p \n<OHO>}'
37       
38    def sesame_is_sparql_test(self):
39        url = 'http://www.openvest.com:8080/openrdf-sesame/repositories/Portfolio/'
40        g1 = SesameGraph(url)
41        g2 = SPARQLGraph(url)       
42        q1 = "select ?s ?p ?o where {?s ?p ?o} limit 1000"
43        r1 = set(list(g1.query(q1,resultMethod='xml')))
44        r2 = set(list(g2.query(q1,resultMethod='xml')))       
45        assert r1==r2
46
47
48
49
50if __name__ == '__main__':
51    unittest.main()
Note: See TracBrowser for help on using the browser.