X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/67e56f190b9a78e3c45cc7d90510fc631e0d04b6..b2ef730e0f524bc8e08fbc241c80c170d9f27763:/sdk/python/tests/arvados_testutil.py diff --git a/sdk/python/tests/arvados_testutil.py b/sdk/python/tests/arvados_testutil.py index a574508cbd..35e85d1195 100644 --- a/sdk/python/tests/arvados_testutil.py +++ b/sdk/python/tests/arvados_testutil.py @@ -60,10 +60,10 @@ def mock_responses(body, *codes, **headers): return mock.patch('httplib2.Http.request', side_effect=queue_with(( (fake_httplib2_response(code, **headers), body) for code in codes))) -def mock_api_responses(api_client, body, codes, headers={}): +def mock_api_responses(api_client, body, codes, headers={}, method='request'): if not isinstance(body, bytes) and hasattr(body, 'encode'): body = body.encode() - return mock.patch.object(api_client._http, 'request', side_effect=queue_with(( + return mock.patch.object(api_client._http, method, side_effect=queue_with(( (fake_httplib2_response(code, **headers), body) for code in codes))) def str_keep_locator(s): @@ -290,8 +290,20 @@ def binary_compare(a, b): return True def make_block_cache(disk_cache): - block_cache = arvados.keep.KeepBlockCache(disk_cache=disk_cache) if disk_cache: disk_cache_dir = os.path.join(os.path.expanduser("~"), ".cache", "arvados", "keep") shutil.rmtree(disk_cache_dir, ignore_errors=True) + block_cache = arvados.keep.KeepBlockCache(disk_cache=disk_cache) return block_cache + + +class DiskCacheBase: + def make_block_cache(self, disk_cache): + self.disk_cache_dir = tempfile.mkdtemp() if disk_cache else None + block_cache = arvados.keep.KeepBlockCache(disk_cache=disk_cache, + disk_cache_dir=self.disk_cache_dir) + return block_cache + + def tearDown(self): + if self.disk_cache_dir: + shutil.rmtree(self.disk_cache_dir)