예제 #1
0
def test_hashes_exist(object_exists, traverse, dvc):
    remote = Remote(BaseRemoteTree(dvc, {}))

    # remote does not support traverse
    remote.tree.CAN_TRAVERSE = False
    with mock.patch.object(remote.tree,
                           "list_hashes",
                           return_value=list(range(256))):
        hashes = set(range(1000))
        remote.hashes_exist(hashes)
        object_exists.assert_called_with(hashes, None, None)
        traverse.assert_not_called()

    remote.tree.CAN_TRAVERSE = True

    # large remote, small local
    object_exists.reset_mock()
    traverse.reset_mock()
    with mock.patch.object(remote.tree,
                           "list_hashes",
                           return_value=list(range(256))):
        hashes = list(range(1000))
        remote.hashes_exist(hashes)
        # verify that _cache_paths_with_max() short circuits
        # before returning all 256 remote hashes
        max_hashes = math.ceil(
            remote.tree._max_estimation_size(hashes) /
            pow(16, remote.tree.TRAVERSE_PREFIX_LEN))
        assert max_hashes < 256
        object_exists.assert_called_with(frozenset(range(max_hashes, 1000)),
                                         None, None)
        traverse.assert_not_called()

    # large remote, large local
    object_exists.reset_mock()
    traverse.reset_mock()
    remote.tree.JOBS = 16
    with mock.patch.object(remote.tree,
                           "list_hashes",
                           return_value=list(range(256))):
        hashes = list(range(1000000))
        remote.hashes_exist(hashes)
        object_exists.assert_not_called()
        traverse.assert_called_with(
            256 * pow(16, remote.tree.TRAVERSE_PREFIX_LEN),
            set(range(256)),
            None,
            None,
        )
예제 #2
0
 def hashes_exist(self, *args, **kwargs):
     return Remote.hashes_exist(self, *args, **kwargs)