Commits

Olemis Lang committed 233753f

GViz QL : Test for FORMAT clause ... [ok]

gvizql.py Total tests : 62 , Failures : 0 , Errors : 6

Comments (0)

Files changed (3)

trac-dev/gviz/tracgviz/gvizql.py

   def __init__(self, seq):
     r"""Initialize this clause with a sequence of formatting expressions
     """
-    self.patterns = dict(seq)
+    if not isinstance(seq, Sequence):
+      seq = Sequence([seq])
+    self.fmt = seq
 
   def transform(self, schema, data):
     r"""Annotate result set with formatted values.
   def handle_bfunc(self, funcnm, _, colnm, __):
     funcnm = funcnm[1]
     colnm = colnm[1]
+    col_schema = colnm['schema'](lambda colnm: (colnm, None) )
     try:
       f = self.agg_funcs[funcnm]
     except KeyError:
       raise LookupError('Unknown aggregation function %s' % (funcnm,))
     return_type = getattr(f, 'return_type', None)
-    func_label = '%s(%s)' % \
-        (funcnm, colnm['schema'](lambda colnm: (colnm, None) )[0])
+    func_label = '%s(%s)' % (funcnm, col_schema[0])
     return dict(
         eval=self._unsupported, 
         schema=(func_label, return_type) if return_type else 
-            lambda get_col_schema: (func_label, get_col_schema(colnm)),
+            lambda get_col_schema: (func_label, get_col_schema(col_schema[0])[1]),
         is_eval_callable=True,
         is_schema_callable=not bool(return_type)
       )
   def _handle_explicit_order(self, expr, direction):
     return (expr[1], direction[1] == 'asc')
 
-  handle_orderasc = handle_order_dsc = _handle_explicit_order
+  handle_orderasc = handle_orderdsc = _handle_explicit_order
 
   def handle_orderseq(self, orderdef, _, neworder):
     orderdef = orderdef[1]

trac-dev/gviz/tracgviz/testing/test_gvizql.py

       *****
       * Parsing
       *****
-      NotSupported  :(
+      [(u'salary', '#,##0.00')]
+      *****
+      * Result
+      *****
+      GVizUnsupportedQueryOp  :  Unable to evaluate FORMAT clause. Either the whole clause or an specific feature is not supported yet.
+
 
       >>> parse("  format  salary   '#,##0.00' ," \
       ...       "hireDate 'dd-MMM-yyyy',      " \
       *****
       * Parsing
       *****
-      NotSupported  :(
+      [(u'salary', '#,##0.00'), (u'hireDate', 'dd-MMM-yyyy'), (u'isSenior', 'not yet:of course!')]
+      *****
+      * Result
+      *****
+      GVizUnsupportedQueryOp  :  Unable to evaluate FORMAT clause. Either the whole clause or an specific feature is not supported yet.
+
 
       >>> parse("format salary '#,##0.00', hireDate 'dd-MMM-yyyy', "
       ...       "isSenior 'Yes!:Not yet'", 'fmt')
       *****
       * Parsing
       *****
-      NotSupported  :(
+      [(u'salary', '#,##0.00'), (u'hireDate', 'dd-MMM-yyyy'), (u'isSenior', 'Yes!:Not yet')]
+      *****
+      * Result
+      *****
+      GVizUnsupportedQueryOp  :  Unable to evaluate FORMAT clause. Either the whole clause or an specific feature is not supported yet.
+
 
       >>> parse("select salary, hireDate, isSenior   , lunchTime "
       ...       "format salary '#,##0.00', hireDate 'dd-MMM-yyyy', "
       *****
       * Parsing
       *****
-      NotSupported  :(
+      [(u'salary', '#,##0.00'), (u'hireDate', 'dd-MMM-yyyy'), (u'isSenior', 'Yes!:Not yet')]
+      [u'salary', u'hireDate', u'isSenior', u'lunchTime']
+      *****
+      * Result
+      *****
+      GVizUnsupportedQueryOp  :  Unable to evaluate FORMAT clause. Either the whole clause or an specific feature is not supported yet.
+
       """,
   'Parsing OPTIONS' : r"""
       >>> parse("  select *  options    no_format   ", 'opts', 'cols')
       *****
       * Parsing
       *****
-      Unexpected token <EOL>.
+      Unexpected token after select.
 
       >>> parse("  select 7group ", 'cols', fail=True)
       *****

trac-dev/gviz/tracgviz/util/parsing.py

         try:
           prod_id, args = self._match_production(pushdown_list)
         except LookupError:
-          raise SyntaxError('Unexpected token %s.%s' % 
+          raise SyntaxError('Unexpected token after %s.%s' % 
               (last_val, ("\n\n" + pushdown_list if self.verbose else "") ) )
         pushdown_list.append((NonTerminal, on_reduce(prod_id, *args)))
         last_tkn, last_val = pushdown_list[-1]