diff -r 8f06e4f02733 -r 96da7dc42eb5 test/unittest_spa2rql.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/unittest_spa2rql.py Wed Jul 22 18:35:08 2009 +0200 @@ -0,0 +1,88 @@ +from logilab.common.testlib import TestCase, unittest_main +from cubicweb.devtools import TestServerConfiguration +from cubicweb.xy import xy +from cubicweb.spa2rql import Sparql2rqlTranslator + +xy.add_equivalence('Project', 'doap:Project') +xy.add_equivalence('Project.creation_date', 'doap:Project.doap:created') + + +config = TestServerConfiguration('data') +config.bootstrap_cubes() +schema = config.load_schema() + + +class XYTC(TestCase): + def setUp(self): + self.tr = Sparql2rqlTranslator(schema) + + def _test(self, sparql, rql): + qi = self.tr.translate(sparql) + self.assertEquals(qi.finalize(), rql) + + def XXX_test_base_01(self): + self._test('SELECT * WHERE { }', 'Any X') + + def test_base_is(self): + self._test(''' + PREFIX doap: + SELECT ?project + WHERE { + ?project a doap:Project; + }''', 'Any PROJECT WHERE PROJECT is Project') + + + def test_base_attr_sel(self): + self._test(''' + PREFIX doap: + SELECT ?created + WHERE { + ?project a doap:Project; + doap:created ?created. + }''', 'Any CREATED WHERE PROJECT creation_date CREATED, PROJECT is Project') + + + def test_base_any_attr_sel(self): + self._test(''' + PREFIX dc: + SELECT ?x ?cd + WHERE { + ?x dc:date ?cd; + }''', 'Any X, CD WHERE X creation_date CD') + + def test_base_any_attr_sel_amb(self): + xy.add_equivalence('Version.publication_date', 'doap:Version.dc:date') + try: + self._test(''' + PREFIX dc: + SELECT ?x ?cd + WHERE { + ?x dc:date ?cd; + }''', '(Any X, CD WHERE , X creation_date CD) UNION (Any X, CD WHERE , X publication_date CD, X is Version)') + finally: + xy.remove_equivalence('Version.publication_date', 'doap:Version.dc:date') + +# # Two elements in the group +# PREFIX : +# SELECT * +# { :p :q :r OPTIONAL { :a :b :c } +# :p :q :r OPTIONAL { :a :b :c } +# } + +# PREFIX : +# SELECT * +# { +# { ?s ?p ?o } UNION { ?a ?b ?c } +# } + +# PREFIX dob: +# PREFIX time: +# PREFIX dc: +# SELECT ?desc +# WHERE { +# dob:1D a time:ProperInterval; +# dc:description ?desc. +# } + +if __name__ == '__main__': + unittest_main()