server/test/unittest_rql2sql.py
changeset 10589 7c23b7de2b8d
parent 10553 1d824df4f2bd
child 11033 63d860a14a17
equal deleted inserted replaced
10588:fdaa0e4b7eaf 10589:7c23b7de2b8d
    14 # details.
    14 # details.
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """unit tests for module cubicweb.server.sources.rql2sql"""
    18 """unit tests for module cubicweb.server.sources.rql2sql"""
       
    19 from __future__ import print_function
    19 
    20 
    20 import sys
    21 import sys
    21 import os
    22 import os
    22 from datetime import date
    23 from datetime import date
    23 from logilab.common.testlib import TestCase, unittest_main, mock_object
    24 from logilab.common.testlib import TestCase, unittest_main, mock_object
  1244             args.update(nargs)
  1245             args.update(nargs)
  1245             self.assertMultiLineEqual(strip(r % args), self._norm_sql(sql))
  1246             self.assertMultiLineEqual(strip(r % args), self._norm_sql(sql))
  1246         except Exception as ex:
  1247         except Exception as ex:
  1247             if 'r' in locals():
  1248             if 'r' in locals():
  1248                 try:
  1249                 try:
  1249                     print (r%args).strip()
  1250                     print((r%args).strip())
  1250                 except KeyError:
  1251                 except KeyError:
  1251                     print 'strange, missing substitution'
  1252                     print('strange, missing substitution')
  1252                     print r, nargs
  1253                     print(r, nargs)
  1253                 print '!='
  1254                 print('!=')
  1254                 print sql.strip()
  1255                 print(sql.strip())
  1255             print 'RQL:', rql
  1256             print('RQL:', rql)
  1256             raise
  1257             raise
  1257 
  1258 
  1258     def _parse(self, rqls):
  1259     def _parse(self, rqls):
  1259         for rql, sql in rqls:
  1260         for rql, sql in rqls:
  1260             yield self._check, rql, sql
  1261             yield self._check, rql, sql
  1267         try:
  1268         try:
  1268             rqlst = self._prepare(rql)
  1269             rqlst = self._prepare(rql)
  1269             r, args, cbs = self.o.generate(rqlst, args)
  1270             r, args, cbs = self.o.generate(rqlst, args)
  1270             self.assertEqual((r.strip(), args), sql)
  1271             self.assertEqual((r.strip(), args), sql)
  1271         except Exception as ex:
  1272         except Exception as ex:
  1272             print rql
  1273             print(rql)
  1273             if 'r' in locals():
  1274             if 'r' in locals():
  1274                 print r.strip()
  1275                 print(r.strip())
  1275                 print '!='
  1276                 print('!=')
  1276                 print sql[0].strip()
  1277                 print(sql[0].strip())
  1277             raise
  1278             raise
  1278         return
  1279         return
  1279 
  1280 
  1280     def test1(self):
  1281     def test1(self):
  1281         self._checkall(('Any count(RDEF) WHERE RDEF relation_type X, X eid %(x)s', {'x': None}),
  1282         self._checkall(('Any count(RDEF) WHERE RDEF relation_type X, X eid %(x)s', {'x': None}),