예제 #1
0
    def test_hash_all(self):
        self.digest.update("jake")
        self.digest.update("jones")
        self.digest.hexdigest().AndReturn("42")
        self.mox.ReplayAll()

        self.assertEqual("42", hash_all(["jake", "jones"], digest=self.digest))
예제 #2
0
    def test_hash_all(self):
        self.digest.update('jake')
        self.digest.update('jones')
        self.digest.hexdigest().AndReturn('42')
        self.mox.ReplayAll()

        self.assertEqual('42', hash_all(['jake', 'jones'], digest=self.digest))
예제 #3
0
  def combine_cache_keys(per_target_cache_keys):
    """Returns a cache key for a set of targets that already have cache keys.

    This operation is 'idempotent' in the sense that if per_target_cache_keys contains a single key
    then that key is returned.

    Note that this operation is commutative but not associative.  We use the term 'combine' rather than
    'merge' or 'union' to remind the user of this. Associativity is not a necessary property, in practice.
    """
    if len(per_target_cache_keys) == 1:
      return per_target_cache_keys[0]
    else:
      cache_keys = sorted(per_target_cache_keys)  # For commutativity.
      # Note that combined_id for a list of targets is the same as Target.identify([targets]),
      # for convenience when debugging, but it doesn't have to be for correctness.
      combined_id = hash_all([cache_key.id for cache_key in cache_keys])
      combined_hash = hash_all([cache_key.hash for cache_key in cache_keys])
      combined_num_sources = reduce(lambda x, y: x + y, [cache_key.num_sources for cache_key in cache_keys], 0)
      return CacheKey(combined_id, combined_hash, combined_num_sources)
예제 #4
0
    def combine_cache_keys(per_target_cache_keys):
        """Returns a cache key for a set of targets that already have cache keys.

    This operation is 'idempotent' in the sense that if per_target_cache_keys contains a single key
    then that key is returned.

    Note that this operation is commutative but not associative.  We use the term 'combine' rather than
    'merge' or 'union' to remind the user of this. Associativity is not a necessary property, in practice.
    """
        if len(per_target_cache_keys) == 1:
            return per_target_cache_keys[0]
        else:
            cache_keys = sorted(per_target_cache_keys)  # For commutativity.
            # Note that combined_id for a list of targets is the same as Target.identify([targets]),
            # for convenience when debugging, but it doesn't have to be for correctness.
            combined_id = hash_all([cache_key.id for cache_key in cache_keys])
            combined_hash = hash_all(
                [cache_key.hash for cache_key in cache_keys])
            combined_num_sources = reduce(
                lambda x, y: x + y,
                [cache_key.num_sources for cache_key in cache_keys], 0)
            return CacheKey(combined_id, combined_hash, combined_num_sources)
예제 #5
0
  def combine_cache_keys(cache_keys):
    """Returns a cache key for a list of target sets that already have cache keys.

    This operation is 'idempotent' in the sense that if cache_keys contains a single key
    then that key is returned.

    Note that this operation is commutative but not associative.  We use the term 'combine' rather
    than 'merge' or 'union' to remind the user of this. Associativity is not a necessary property,
    in practice.
    """
    if len(cache_keys) == 1:
      return cache_keys[0]
    else:
      combined_id = Target.maybe_readable_combine_ids(cache_key.id for cache_key in cache_keys)
      combined_hash = hash_all(sorted(cache_key.hash for cache_key in cache_keys))
      combined_num_sources = sum(cache_key.num_sources for cache_key in cache_keys)
      return CacheKey(combined_id, combined_hash, combined_num_sources)
예제 #6
0
  def combine_cache_keys(cache_keys):
    """Returns a cache key for a list of target sets that already have cache keys.

    This operation is 'idempotent' in the sense that if cache_keys contains a single key
    then that key is returned.

    Note that this operation is commutative but not associative.  We use the term 'combine' rather
    than 'merge' or 'union' to remind the user of this. Associativity is not a necessary property,
    in practice.
    """
    if len(cache_keys) == 1:
      return cache_keys[0]
    else:
      combined_id = Target.maybe_readable_combine_ids(cache_key.id for cache_key in cache_keys)
      combined_hash = hash_all(sorted(cache_key.hash for cache_key in cache_keys))
      combined_num_sources = sum(cache_key.num_sources for cache_key in cache_keys)
      combined_sources = \
        sorted(list(itertools.chain(*[cache_key.sources for cache_key in cache_keys])))
      return CacheKey(combined_id, combined_hash, combined_num_sources, combined_sources)
예제 #7
0
파일: target.py 프로젝트: wickman/commons
 def combine_ids(ids):
     """Generates a combined id for a set of ids."""
     return hash_all(
         sorted(ids))  # We sort so that the id isn't sensitive to order.
예제 #8
0
파일: target.py 프로젝트: SeungEun/commons
 def identify(targets):
   """Generates an id for a set of targets."""
   # If you change this implementation, consider changing CacheKeyGenerator.combine_cache_keys to match.
   return hash_all([target.id for target in targets])
예제 #9
0
 def combine_ids(ids):
   """Generates a combined id for a set of ids."""
   return hash_all(sorted(ids))  # We sort so that the id isn't sensitive to order.