| 1 | #!/usr/bin/env python |
|---|
| 2 | # encoding: utf-8 |
|---|
| 3 | """ |
|---|
| 4 | sparql_test.py |
|---|
| 5 | |
|---|
| 6 | Created by Philip Cooper on 2008-02-27. |
|---|
| 7 | Copyright (c) 2008 Openvest. All rights reserved. |
|---|
| 8 | """ |
|---|
| 9 | |
|---|
| 10 | from rdfalchemy.sparql import SPARQLGraph |
|---|
| 11 | from rdfalchemy.sparql.sesame2 import SesameGraph |
|---|
| 12 | from rdfalchemy import URIRef |
|---|
| 13 | from decimal import Decimal |
|---|
| 14 | import unittest |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | class sparql_test: |
|---|
| 18 | def __init__(self): |
|---|
| 19 | pass |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | class 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 | |
|---|
| 50 | if __name__ == '__main__': |
|---|
| 51 | unittest.main() |
|---|