test/unittest_spa2rql.py
author Rémi Cardona <remi.cardona@logilab.fr>
Mon, 21 Sep 2015 18:04:22 +0200
changeset 10722 1d0b5aef7523
parent 10452 f3dec653a27d
permissions -rw-r--r--
[tests] Stop counting pickle bytes in ResultSet tests Between python 2's pickle and cPickle implementations, the various protocol versions added in python 3, the length of the pickled string is completely unpredictable. Instead, do a simple round trip and test a few attributes.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
10452
f3dec653a27d [test] Skip spa2rql tests when fyzz is not available
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 6340
diff changeset
    18
import unittest
f3dec653a27d [test] Skip spa2rql tests when fyzz is not available
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 6340
diff changeset
    19
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
from logilab.common.testlib import TestCase, unittest_main
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
from cubicweb.devtools import TestServerConfiguration
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
from cubicweb.xy import xy
10452
f3dec653a27d [test] Skip spa2rql tests when fyzz is not available
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 6340
diff changeset
    23
f3dec653a27d [test] Skip spa2rql tests when fyzz is not available
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 6340
diff changeset
    24
SKIPCAUSE = None
f3dec653a27d [test] Skip spa2rql tests when fyzz is not available
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 6340
diff changeset
    25
try:
f3dec653a27d [test] Skip spa2rql tests when fyzz is not available
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 6340
diff changeset
    26
    from cubicweb.spa2rql import Sparql2rqlTranslator
f3dec653a27d [test] Skip spa2rql tests when fyzz is not available
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 6340
diff changeset
    27
except ImportError as exc:
f3dec653a27d [test] Skip spa2rql tests when fyzz is not available
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 6340
diff changeset
    28
    SKIPCAUSE = str(exc)
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    29
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    30
xy.add_equivalence('Project', 'doap:Project')
2428
a3e10e6a2461 use space as separator, dot may be found in xml ns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2427
diff changeset
    31
xy.add_equivalence('Project creation_date', 'doap:Project doap:created')
a3e10e6a2461 use space as separator, dot may be found in xml ns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2427
diff changeset
    32
xy.add_equivalence('Project name', 'doap:Project doap:name')
5610
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
    33
xy.add_equivalence('Project name', 'doap:Project dc:title')
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    34
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    35
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    36
config = TestServerConfiguration('data')
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    37
config.bootstrap_cubes()
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    38
schema = config.load_schema()
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    39
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    40
10452
f3dec653a27d [test] Skip spa2rql tests when fyzz is not available
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 6340
diff changeset
    41
@unittest.skipIf(SKIPCAUSE, SKIPCAUSE)
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    42
class XYTC(TestCase):
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    43
    def setUp(self):
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    44
        self.tr = Sparql2rqlTranslator(schema)
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    45
2435
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
    46
    def _test(self, sparql, rql, args={}):
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    47
        qi = self.tr.translate(sparql)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5613
diff changeset
    48
        self.assertEqual(qi.finalize(), (rql, args))
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    49
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    50
    def XXX_test_base_01(self):
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    51
        self._test('SELECT * WHERE { }', 'Any X')
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    52
2431
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
    53
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    54
    def test_base_is(self):
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    55
        self._test('''
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    56
    PREFIX doap: <http://usefulinc.com/ns/doap#>
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    57
    SELECT ?project
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    58
    WHERE  {
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    59
      ?project a doap:Project;
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    60
    }''', 'Any PROJECT WHERE PROJECT is Project')
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    61
5609
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    62
    def test_base_rdftype(self):
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    63
        self._test('''
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    64
    PREFIX doap: <http://usefulinc.com/ns/doap#>
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    65
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    66
    SELECT ?project
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    67
    WHERE  {
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    68
      ?project rdf:type doap:Project.
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    69
    }''', 'Any PROJECT WHERE PROJECT is Project')
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    70
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    71
    def test_base_attr_sel(self):
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    72
        self._test('''
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    73
    PREFIX doap: <http://usefulinc.com/ns/doap#>
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    74
    SELECT ?created
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    75
    WHERE  {
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    76
      ?project a doap:Project;
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    77
              doap:created ?created.
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    78
    }''', 'Any CREATED WHERE PROJECT creation_date CREATED, PROJECT is Project')
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    79
2431
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
    80
2427
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    81
    def test_base_attr_sel_distinct(self):
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    82
        self._test('''
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    83
    PREFIX doap: <http://usefulinc.com/ns/doap#>
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    84
    SELECT DISTINCT ?name
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    85
    WHERE  {
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    86
      ?project a doap:Project;
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    87
              doap:name ?name.
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    88
    }''', 'DISTINCT Any NAME WHERE PROJECT name NAME, PROJECT is Project')
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    89
2431
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
    90
2427
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    91
    def test_base_attr_sel_reduced(self):
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    92
        self._test('''
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    93
    PREFIX doap: <http://usefulinc.com/ns/doap#>
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    94
    SELECT REDUCED ?name
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    95
    WHERE  {
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    96
      ?project a doap:Project;
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    97
              doap:name ?name.
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    98
    }''', 'Any NAME WHERE PROJECT name NAME, PROJECT is Project')
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    99
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   100
2431
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   101
    def test_base_attr_sel_limit_offset(self):
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   102
        self._test('''
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   103
    PREFIX doap: <http://usefulinc.com/ns/doap#>
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   104
    SELECT ?name
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   105
    WHERE  {
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   106
      ?project a doap:Project;
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   107
              doap:name ?name.
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   108
    }
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   109
    LIMIT 20''', 'Any NAME LIMIT 20 WHERE PROJECT name NAME, PROJECT is Project')
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   110
        self._test('''
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   111
    PREFIX doap: <http://usefulinc.com/ns/doap#>
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   112
    SELECT ?name
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   113
    WHERE  {
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   114
      ?project a doap:Project;
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   115
              doap:name ?name.
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   116
    }
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   117
    LIMIT 20 OFFSET 10''', 'Any NAME LIMIT 20 OFFSET 10 WHERE PROJECT name NAME, PROJECT is Project')
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   118
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   119
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   120
    def test_base_attr_sel_orderby(self):
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   121
        self._test('''
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   122
    PREFIX doap: <http://usefulinc.com/ns/doap#>
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   123
    SELECT ?name
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   124
    WHERE  {
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   125
      ?project a doap:Project;
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   126
              doap:name ?name;
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   127
              doap:created ?created.
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   128
    }
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   129
    ORDER BY ?name DESC(?created)''', 'Any NAME ORDERBY NAME ASC, CREATED DESC WHERE PROJECT name NAME, PROJECT creation_date CREATED, PROJECT is Project')
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   130
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   131
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   132
    def test_base_any_attr_sel(self):
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   133
        self._test('''
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   134
    PREFIX dc: <http://purl.org/dc/elements/1.1/>
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   135
    SELECT ?x ?cd
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   136
    WHERE  {
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   137
      ?x dc:date ?cd;
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   138
    }''', 'Any X, CD WHERE X creation_date CD')
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   139
2431
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   140
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   141
    def test_base_any_attr_sel_amb(self):
2428
a3e10e6a2461 use space as separator, dot may be found in xml ns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2427
diff changeset
   142
        xy.add_equivalence('Version publication_date', 'doap:Version dc:date')
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   143
        try:
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   144
            self._test('''
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   145
    PREFIX dc: <http://purl.org/dc/elements/1.1/>
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   146
    SELECT ?x ?cd
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   147
    WHERE  {
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   148
      ?x dc:date ?cd;
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   149
    }''', '(Any X, CD WHERE , X creation_date CD) UNION (Any X, CD WHERE , X publication_date CD, X is Version)')
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   150
        finally:
2428
a3e10e6a2461 use space as separator, dot may be found in xml ns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2427
diff changeset
   151
            xy.remove_equivalence('Version publication_date', 'doap:Version dc:date')
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   152
2431
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   153
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   154
    def test_base_any_attr_sel_amb_limit_offset(self):
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   155
        xy.add_equivalence('Version publication_date', 'doap:Version dc:date')
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   156
        try:
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   157
            self._test('''
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   158
    PREFIX dc: <http://purl.org/dc/elements/1.1/>
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   159
    SELECT ?x ?cd
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   160
    WHERE  {
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   161
      ?x dc:date ?cd;
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   162
    }
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   163
    LIMIT 20 OFFSET 10''', 'Any X, CD LIMIT 20 OFFSET 10 WITH X, CD BEING ((Any X, CD WHERE , X creation_date CD) UNION (Any X, CD WHERE , X publication_date CD, X is Version))')
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   164
        finally:
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   165
            xy.remove_equivalence('Version publication_date', 'doap:Version dc:date')
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   166
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   167
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   168
    def test_base_any_attr_sel_amb_orderby(self):
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   169
        xy.add_equivalence('Version publication_date', 'doap:Version dc:date')
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   170
        try:
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   171
            self._test('''
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   172
    PREFIX dc: <http://purl.org/dc/elements/1.1/>
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   173
    SELECT ?x ?cd
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   174
    WHERE  {
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   175
      ?x dc:date ?cd;
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   176
    }
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   177
    ORDER BY DESC(?cd)''', 'Any X, CD ORDERBY CD DESC WITH X, CD BEING ((Any X, CD WHERE , X creation_date CD) UNION (Any X, CD WHERE , X publication_date CD, X is Version))')
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   178
        finally:
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   179
            xy.remove_equivalence('Version publication_date', 'doap:Version dc:date')
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   180
2435
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   181
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   182
    def test_restr_attr(self):
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   183
        self._test('''
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   184
    PREFIX doap: <http://usefulinc.com/ns/doap#>
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   185
    SELECT ?project
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   186
    WHERE  {
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   187
      ?project a doap:Project;
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   188
              doap:name "cubicweb".
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   189
    }''', 'Any PROJECT WHERE PROJECT name %(a)s, PROJECT is Project', {'a': 'cubicweb'})
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   190
5610
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
   191
    def test_dctitle_both_project_cwuser(self):
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
   192
        self._test('''
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
   193
    PREFIX doap: <http://usefulinc.com/ns/doap#>
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
   194
    PREFIX dc: <http://purl.org/dc/elements/1.1/>
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
   195
    SELECT ?project ?title
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
   196
    WHERE  {
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
   197
      ?project a doap:Project;
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
   198
              dc:title ?title.
5613
bc0ebfbf5c5d [sparql] fix type inference (test_dctitle_both_project_cwuser) and support for <http://www.w3.org/1999/02/22-rdf-syntax-ns#type tag (test_base_rdftype)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5610
diff changeset
   199
    }''', 'Any PROJECT, TITLE WHERE PROJECT name TITLE, PROJECT is Project')
5610
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
   200
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   201
# # Two elements in the group
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   202
# PREFIX :  <http://example.org/ns#>
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   203
# SELECT *
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   204
# { :p :q :r  OPTIONAL { :a :b :c }
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   205
#   :p :q :r  OPTIONAL { :a :b :c }
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   206
# }
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   207
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   208
# PREFIX : <http://example.org/ns#>
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   209
# SELECT *
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   210
# {
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   211
#   { ?s ?p ?o } UNION { ?a ?b ?c }
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   212
# }
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   213
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   214
# PREFIX dob: <http://placetime.com/interval/gregorian/1977-01-18T04:00:00Z/P>
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   215
# PREFIX time: <http://www.ai.sri.com/daml/ontologies/time/Time.daml#>
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   216
# PREFIX dc: <http://purl.org/dc/elements/1.1/>
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   217
# SELECT ?desc
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   218
# WHERE  {
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   219
#   dob:1D a time:ProperInterval;
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   220
#          dc:description ?desc.
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   221
# }
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   222
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   223
if __name__ == '__main__':
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   224
    unittest_main()