Skip to content

Commit

Permalink
Resolves #151
Browse files Browse the repository at this point in the history
  • Loading branch information
k1o0 committed Nov 3, 2024
1 parent 1081afe commit c7dd098
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion one/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def get_cache_dir(client=None) -> Path:
The download cache path
"""
cache_map = iopar.read(f'{_PAR_ID_STR}/{_CLIENT_ID_STR}', {})
client = _key_from_url(client) if client else cache_map.DEFAULT
client = _key_from_url(client) if client else getattr(cache_map, 'DEFAULT', None)
cache_dir = Path(cache_map.CLIENT_MAP[client] if cache_map else CACHE_DIR_DEFAULT)
cache_dir.mkdir(exist_ok=True, parents=True)
return cache_dir
Expand Down
14 changes: 14 additions & 0 deletions one/tests/test_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,20 @@ def test_local_cache_setup_prompt(self):
one_obj = One.setup(cache_dir=self.tempdir.name, silent=True)
assert len(one_obj.list_datasets()) == 2

def test_local_tables_only(self):
"""Test first time instantiation of ONE with only tables_dir arg.
Previously this would have raised and AttributeError as cache_map.DEFAULT
doesn't exist on a new install.
"""
# Expect warning as table_dir empty
with mock.patch('iblutil.io.params.getfile', new=self.get_file), \
self.assertWarns(UserWarning):
# Should instantiate without error
one_obj = One(tables_dir=Path(self.tempdir.name, 'tables'))
self.assertEqual(self.tempdir.name, str(one_obj.cache_dir))
self.assertEqual('tables', one_obj._tables_dir.name)

def test_setup_silent(self):
"""Test setting up parameters with silent flag.
Expand Down

0 comments on commit c7dd098

Please sign in to comment.