Example #1
0
 def rowp(ds, i):
     if i is None or i < 0:
         return ""
     assert i < len(ds.rows), f"{i} out of range {len(ds.rows)}"
     row = ds.rows[i].values
     printer = DataSetPrinter(rs._decode_type, vid_fn=vid_fn)
     ss = printer.list_to_string(row, delimiter='|')
     return f'{i}: |' + ss + '|'
Example #2
0
 def dsp(ds):
     printer = DataSetPrinter(rs._decode_type, vid_fn=vid_fn)
     return printer.ds_to_string(ds)
Example #3
0
 def compare_value(self, lhs: Value, rhs: Union[Value, Pattern]) -> bool:
     """
     lhs and rhs represent response data and expected data respectively
     """
     if type(rhs) is Pattern:
         dsp = DataSetPrinter(self._decode_type)
         return bool(rhs.match(dsp.to_string(lhs)))
     if lhs.getType() == Value.__EMPTY__:
         return rhs.getType() == Value.__EMPTY__
     if lhs.getType() == Value.NVAL:
         if not rhs.getType() == Value.NVAL:
             return False
         return lhs.get_nVal() == rhs.get_nVal()
     if lhs.getType() == Value.BVAL:
         if not rhs.getType() == Value.BVAL:
             return False
         return lhs.get_bVal() == rhs.get_bVal()
     if lhs.getType() == Value.IVAL:
         if not rhs.getType() == Value.IVAL:
             return False
         return lhs.get_iVal() == rhs.get_iVal()
     if lhs.getType() == Value.FVAL:
         if not rhs.getType() == Value.FVAL:
             return False
         return math.fabs(lhs.get_fVal() - rhs.get_fVal()) < 1.0E-8
     if lhs.getType() == Value.SVAL:
         if not rhs.getType() == Value.SVAL:
             return False
         return lhs.get_sVal() == self.bstr(rhs.get_sVal())
     if lhs.getType() == Value.DVAL:
         if rhs.getType() == Value.DVAL:
             return lhs.get_dVal() == rhs.get_dVal()
         if rhs.getType() == Value.SVAL:
             ld = lhs.get_dVal()
             lds = "%d-%02d-%02d" % (ld.year, ld.month, ld.day)
             rv = rhs.get_sVal()
             return lds == rv if type(rv) == str else self.b(lds) == rv
         return False
     if lhs.getType() == Value.TVAL:
         if rhs.getType() == Value.TVAL:
             return lhs.get_tVal() == rhs.get_tVal()
         if rhs.getType() == Value.SVAL:
             lt = lhs.get_tVal()
             lts = "%02d:%02d:%02d.%06d" % (lt.hour, lt.minute, lt.sec,
                                            lt.microsec)
             rv = rhs.get_sVal()
             return lts == rv if type(rv) == str else self.b(lts) == rv
         return False
     if lhs.getType() == Value.DTVAL:
         if rhs.getType() == Value.DTVAL:
             return lhs.get_dtVal() == rhs.get_dtVal()
         if rhs.getType() == Value.SVAL:
             ldt = lhs.get_dtVal()
             ldts = "%d-%02d-%02dT%02d:%02d:%02d.%06d" % (
                 ldt.year, ldt.month, ldt.day, ldt.hour, ldt.minute,
                 ldt.sec, ldt.microsec)
             rv = rhs.get_sVal()
             return ldts == rv if type(rv) == str else self.b(ldts) == rv
         return False
     if lhs.getType() == Value.LVAL:
         if not rhs.getType() == Value.LVAL:
             return False
         lvals = lhs.get_lVal().values
         rvals = rhs.get_lVal().values
         return self.compare_list(lvals, rvals)
     if lhs.getType() == Value.UVAL:
         if not rhs.getType() == Value.UVAL:
             return False
         lvals = lhs.get_uVal().values
         rvals = rhs.get_uVal().values
         res, _ = self._compare_list(lvals, rvals, self.compare_value)
         return res
     if lhs.getType() == Value.MVAL:
         if not rhs.getType() == Value.MVAL:
             return False
         lkvs = lhs.get_mVal().kvs
         rkvs = rhs.get_mVal().kvs
         return self.compare_map(lkvs, rkvs)
     if lhs.getType() == Value.VVAL:
         if not rhs.getType() == Value.VVAL:
             return False
         return self.compare_node(lhs.get_vVal(), rhs.get_vVal())
     if lhs.getType() == Value.EVAL:
         if not rhs.getType() == Value.EVAL:
             return False
         return self.compare_edge(lhs.get_eVal(), rhs.get_eVal())
     if lhs.getType() == Value.PVAL:
         if not rhs.getType() == Value.PVAL:
             return False
         return self.compare_path(lhs.get_pVal(), rhs.get_pVal())
     return False