示例#1
0
 def default(self, o):  # pylint:disable=method-hidden
     from _stbt.match import MatchParameters
     if isinstance(o, ImageLogger):
         if o.enabled:
             raise NotCachable()
         return None
     elif isinstance(o, LooseVersion):
         return str(o)
     elif isinstance(o, set):
         return sorted(o)
     elif isinstance(o, MatchParameters):
         return {
             "match_method": o.match_method.value,
             "match_threshold": o.match_threshold,
             "confirm_method": o.confirm_method.value,
             "confirm_threshold": o.confirm_threshold,
             "erode_passes": o.erode_passes
         }
     elif isinstance(o, numpy.ndarray):
         from _stbt.xxhash import Xxhash64
         h = Xxhash64()
         h.update(numpy.ascontiguousarray(o).data)
         return (o.shape, h.hexdigest())
     else:
         json.JSONEncoder.default(self, o)
示例#2
0
def _cache_hash(value):
    from _stbt.xxhash import Xxhash64
    h = Xxhash64()

    class HashWriter(object):
        def write(self, data):
            h.update(data)
            return len(data)

    json.dump(value, HashWriter(), cls=_ArgsEncoder, sort_keys=True)
    return h.digest()
示例#3
0
def _cache_hash(value):
    # type: (...) -> bytes
    h = Xxhash64()

    class HashWriter(object):
        def write(self, data):
            if isinstance(data, str):
                data = data.encode("utf-8")
            h.update(data)
            return len(data)

    json.dump(value, HashWriter(), cls=_ArgsEncoder, sort_keys=True)
    return h.digest()
示例#4
0
 def default(self, value):  # pylint: disable=method-hidden
     import _stbt.core as core
     if isinstance(value, ImageLogger):
         if value.enabled:
             raise NotCachable()
         return None
     elif isinstance(value, set):
         return sorted(value)
     elif isinstance(value, core.MatchParameters):
         return {
             "match_method": value.match_method,
             "match_threshold": value.match_threshold,
             "confirm_method": value.confirm_method,
             "confirm_threshold": value.confirm_threshold,
             "erode_passes": value.erode_passes
         }
     elif isinstance(value, numpy.ndarray):
         from _stbt.xxhash import Xxhash64
         h = Xxhash64()
         h.update(numpy.ascontiguousarray(value).data)
         return (value.shape, h.hexdigest())
     else:
         json.JSONEncoder.default(self, value)