X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2f66d4cc05e9442a9bb69969744d0750a02a1ed4..2693a197ea37490a891c54bbb279937a7b4e897c:/sdk/python/tests/arvados_testutil.py diff --git a/sdk/python/tests/arvados_testutil.py b/sdk/python/tests/arvados_testutil.py index f251ea654b..0035659796 100644 --- a/sdk/python/tests/arvados_testutil.py +++ b/sdk/python/tests/arvados_testutil.py @@ -190,7 +190,13 @@ class MockStreamReader(object): class ApiClientMock(object): def api_client_mock(self): - return mock.MagicMock(name='api_client_mock') + api_mock = mock.MagicMock(name='api_client_mock') + api_mock.config.return_value = { + 'StorageClasses': { + 'default': {'Default': True} + } + } + return api_mock def mock_keep_services(self, api_mock=None, status=200, count=12, service_type='disk', @@ -274,3 +280,30 @@ if sys.version_info < (3, 0): return self.assertNotRegexpMatches(*args, **kwargs) unittest.TestCase.assertRegex = assertRegex unittest.TestCase.assertNotRegex = assertNotRegex + +def binary_compare(a, b): + if len(a) != len(b): + return False + for i in range(0, len(a)): + if a[i] != b[i]: + return False + return True + +def make_block_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)