one.tests.util
Utilities functions for setting up test fixtures.
Functions
Convert str ids to int ids for cache tables. |
|
Touch all the files in the datasets table. |
|
Save REST cache file for docs/ endpoint. |
|
A stub function for iblutil.io.params.getfile. |
|
Stand in for the HTTP transfer so download tests need no data server access. |
|
Load the Alyx REST schema fixture, so that an AlyxClient need not fetch it. |
|
Return a datasets cache DataFrame containing datasets with revision folders. |
|
Create a temporary directory and copy cache fixtures over. |
|
Copy REST cache fixtures to the .one parameter directory. |
|
Copy cache parameter fixture to .one directory. |
- set_up_env() TemporaryDirectory[source]
Create a temporary directory and copy cache fixtures over.
- Returns:
The temporary directory containing the test ONE caches
- Return type:
tempfile.TemporaryDirectory
- setup_rest_cache(cache_dir)[source]
Copy REST cache fixtures to the .one parameter directory.
- Parameters:
cache_dir (str, pathlib.Path) – The location of the ONE cache directory (e.g. ~/Downloads/ONE/alyx.example.com)
- create_file_tree(one)[source]
Touch all the files in the datasets table.
- Parameters:
one (one.api.One) – An instance of One containing cache tables to use.
- setup_test_params(token=False, cache_dir=None)[source]
Copy cache parameter fixture to .one directory.
- Parameters:
token (bool) – If true, save a token file so that client doesn’t hit auth endpoint
cache_dir (str, pathlib.Path) – The cache_dir to save
- revisions_datasets_table(collections=('', 'alf/probe00', 'alf/probe01'), revisions=('', '2020-01-08', '2021-07-06'), object='spikes', attributes=('times', 'waveforems'), touch_path=None)[source]
Return a datasets cache DataFrame containing datasets with revision folders.
As there are no revised datasets on the test databases, this function acts as a fixture for testing the filtering of datasets by a revision.
- Parameters:
collections (tuple) – A list of collections
revisions (tuple) – A list of revisions
object (str) – An ALF object
attributes (tuple) – A list of ALF attributes
touch_path (pathlib.Path, str) – If provided, files are created in this directory.
- Returns:
A datasets cache table containing datasets made from the input names.
- Return type:
pd.DataFrame
- create_schema_cache(param_dir=None)[source]
Save REST cache file for docs/ endpoint.
Ensures the database isn’t hit when the rest_schemas property is accessed.
- Parameters:
param_dir (str, pathlib.Path) – The location of the parameter directory. If None, the default one is used.
- get_file(root: str, str_id: str) str[source]
A stub function for iblutil.io.params.getfile.
Allows the injection of a different param dir.
- Parameters:
root (str, pathlib.Path) – The root directory of the new parameters
str_id (str) – The parameter string identifier
- Returns:
The parameter file path
- Return type:
str
- caches_str2int(caches)[source]
Convert str ids to int ids for cache tables.
- Parameters:
caches (Bunch) – A bunch of cache tables (from One._cache)
- mock_http_download(content=b'mock file contents', tag=True)[source]
Stand in for the HTTP transfer so download tests need no data server access.
The test database’s file records point at the private FlatIron tree. Only the bytes on the wire are simulated; URL validation, the hash check and UUID stripping still run.
The mismatch handler is stubbed out too: a fabricated file never matches the recorded hash, and the handler would flag the file record on Alyx, writing to the shared test database.
- Parameters:
content (bytes) – The contents of each downloaded file.
tag (bool) – If false, _tag_mismatched_file_record is not stubbed out.
- Yields:
unittest.mock.MagicMock, None – The patched _tag_mismatched_file_record, or None if tag is false.